File tree 4 files changed +45
-4
lines changed
hir-def/src/macro_expansion_tests
test_data/parser/inline/ok
4 files changed +45
-4
lines changed Original file line number Diff line number Diff line change @@ -92,3 +92,40 @@ fn foo() {
92
92
}"## ] ] ,
93
93
) ;
94
94
}
95
+
96
+ #[ test]
97
+ fn float_parsing_panic ( ) {
98
+ // Regression test for https://github.com/rust-lang/rust-analyzer/issues/12211
99
+ check (
100
+ r#"
101
+ //- proc_macros: identity
102
+ macro_rules! id {
103
+ ($($t:tt)*) => {
104
+ $($t)*
105
+ };
106
+ }
107
+
108
+ id! {
109
+ #[proc_macros::identity]
110
+ impl Foo for WrapBj {
111
+ async fn foo(&self) {
112
+ self.0. id().await;
113
+ }
114
+ }
115
+ }
116
+ "# ,
117
+ expect ! [ [ r##"
118
+ macro_rules! id {
119
+ ($($t:tt)*) => {
120
+ $($t)*
121
+ };
122
+ }
123
+
124
+ #[proc_macros::identity] impl Foo for WrapBj {
125
+ async fn foo(&self ) {
126
+ self .0.id().await ;
127
+ }
128
+ }
129
+ "## ] ] ,
130
+ ) ;
131
+ }
Original file line number Diff line number Diff line change @@ -243,6 +243,8 @@ fn convert_tokens<C: TokenConvertor>(conv: &mut C) -> tt::Subtree {
243
243
let char = match token. to_char ( conv) {
244
244
Some ( c) => c,
245
245
None => {
246
+ // FIXME: this isn't really correct, `to_char` yields the *first* char of the token,
247
+ // and this is relevant when eg. creating 2 `tt::Punct` from a single `::` token
246
248
panic ! ( "Token from lexer must be single char: token = {:#?}" , token) ;
247
249
}
248
250
} ;
Original file line number Diff line number Diff line change @@ -324,7 +324,9 @@ fn name_ref_or_index(p: &mut Parser) {
324
324
) ;
325
325
let m = p. start ( ) ;
326
326
if p. at ( FLOAT_NUMBER_PART ) || p. at_ts ( FLOAT_LITERAL_FIRST ) {
327
- p. bump_remap ( INT_NUMBER ) ;
327
+ // Ideally we'd remap this to `INT_NUMBER` instead, but that causes the MBE conversion to
328
+ // lose track of what's a float and what isn't, causing panics.
329
+ p. bump_remap ( FLOAT_NUMBER_PART ) ;
328
330
} else {
329
331
p. bump_any ( ) ;
330
332
}
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ SOURCE_FILE
50
50
IDENT "x"
51
51
DOT "."
52
52
NAME_REF
53
- INT_NUMBER "0"
53
+ FLOAT_NUMBER_PART "0"
54
54
DOT "."
55
55
WHITESPACE " "
56
56
NAME_REF
@@ -67,10 +67,10 @@ SOURCE_FILE
67
67
IDENT "x"
68
68
DOT "."
69
69
NAME_REF
70
- INT_NUMBER "0"
70
+ FLOAT_NUMBER_PART "0"
71
71
DOT "."
72
72
NAME_REF
73
- INT_NUMBER "1"
73
+ FLOAT_NUMBER_PART "1"
74
74
SEMICOLON ";"
75
75
WHITESPACE "\n "
76
76
EXPR_STMT
You can’t perform that action at this time.
0 commit comments