1 //! Test that `$var:expr` captures function correctly.
3 use expect_test::expect;
5 use crate::macro_expansion_tests::check;
8 fn unary_minus_is_a_literal() {
11 macro_rules! m { ($x:literal) => (literal!();); ($x:tt) => (not_a_literal!();); }
18 macro_rules! m { ($x:literal) => (literal!();); ($x:tt) => (not_a_literal!();); }
22 /* error: leftover tokens */not_a_literal!();
28 fn test_expand_bad_literal() {
31 macro_rules! m { ($i:literal) => {}; }
35 macro_rules! m { ($i:literal) => {}; }
36 /* error: Failed to lower macro args to token tree */"#]],
41 fn test_empty_comments() {
44 macro_rules! m{ ($fmt:expr) => (); }
48 macro_rules! m{ ($fmt:expr) => (); }
49 /* error: expected Expr */
56 // Thanks, Christopher!
58 // https://internals.rust-lang.org/t/understanding-decisions-behind-semicolons/15181/29
61 macro_rules! asi { ($($stmt:stmt)*) => ($($stmt)*); }
73 macro_rules! asi { ($($stmt:stmt)*) => ($($stmt)*); }
76 let a = 2let b = 5drop(b-a)println!("{}", a+b)
83 fn stmt_boundaries() {
84 // FIXME: this actually works OK under rustc.
88 ($($s:stmt)*) => (stringify!($($s |)*);)
90 m!(;;92;let x = 92; loop {};);
94 ($($s:stmt)*) => (stringify!($($s |)*);)
108 fn range_patterns() {
109 // FIXME: rustc thinks there are three patterns here, not one.
113 ($($p:pat)*) => (stringify!($($p |)*);)
119 ($($p:pat)*) => (stringify!($($p |)*);)
121 stringify!(.. .. ..|);
130 macro_rules! m { ($($i:ident)? $vis:vis) => () }
134 macro_rules! m { ($($i:ident)? $vis:vis) => () }