1 //! Unlike rustc, rust-analyzer's syntax tree are not "made of" token trees.
2 //! Rather, token trees are an explicit bridge between the parser and
3 //! (procedural or declarative) macros.
5 //! This module tests tt <-> syntax tree conversion specifically. In particular,
6 //! it, among other things, check that we convert `tt` to the right kind of
7 //! syntax node depending on the macro call-site.
8 use expect_test::expect;
10 use crate::macro_expansion_tests::check;
13 fn round_trips_compound_tokens() {
17 () => { type qual: ::T = qual::T; }
23 () => { type qual: ::T = qual::T; }
25 type qual: ::T = qual::T;
31 fn round_trips_literals() {
69 fn roundtrip_lifetime() {
73 ($($t:tt)*) => { $($t)*}
75 m!(static bar: &'static str = "hello";);
79 ($($t:tt)*) => { $($t)*}
81 static bar: & 'static str = "hello";
87 fn broken_parenthesis_sequence() {
90 macro_rules! m1 { ($x:ident) => { ($x } }
91 macro_rules! m2 { ($x:ident) => {} }
97 macro_rules! m1 { ($x:ident) => { ($x } }
98 macro_rules! m2 { ($x:ident) => {} }
100 /* error: invalid macro definition: expected subtree */
101 /* error: Failed to lower macro args to token tree */
107 fn expansion_does_not_parse_as_expression() {
114 fn f() { let _ = stmts!/*+errors*/(); }
121 fn f() { let _ = /* parse error: expected expression */
131 macro_rules! m1 { () => (Some(x) left overs) }
132 macro_rules! m2 { () => ($) }
136 let m2!/*+errors*/() = ();
140 macro_rules! m1 { () => (Some(x) left overs) }
141 macro_rules! m2 { () => ($) }
144 let Some(x)left overs = ();
145 let /* parse error: expected pattern */