Skip to content

Commit e2ba9d1

Browse files
committed
Add test for using $:literal to index a tuple
Currently fails to build: error: unexpected token: `0` --> src/test/ui/macros/macro-interpolation.rs:19:16 | LL | $var . $field | ^^^^^^ ... LL | let _ = field!(tuple.0); | --------------- in this macro invocation | = note: this error originates in the macro `field` (in Nightly builds, run with -Z macro-backtrace for more info) error: macro expansion ignores token `0` and any following --> src/test/ui/macros/macro-interpolation.rs:19:16 | LL | $var . $field | ^^^^^^ ... LL | let _ = field!(tuple.0); | --------------- caused by the macro expansion here | = note: the usage of `field!` is likely invalid in expression context error: aborting due to 2 previous errors
1 parent e5e2b0b commit e2ba9d1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/test/ui/macros/macro-interpolation.rs

+9
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,19 @@ macro_rules! qpath {
2424
};
2525
}
2626

27+
macro_rules! field {
28+
($var:ident . $field:literal) => {
29+
$var . $field
30+
};
31+
}
32+
2733
pub fn main() {
2834
let _: qpath!(path, <str as ToOwned>::Owned);
2935
let _: qpath!(ty, <str as ToOwned>::Owned);
3036

37+
let tuple = ('x',);
38+
let _ = field!(tuple.0);
39+
3140
assert!(overly_complicated!(f, x, Option<usize>, { return Some(x); },
3241
Some(8), Some(y), y) == 8)
3342
}

0 commit comments

Comments
 (0)