@@ -5,7 +5,7 @@ use std::mem;
5
5
use mbe:: { SyntheticToken , SyntheticTokenId , TokenMap } ;
6
6
use rustc_hash:: FxHashMap ;
7
7
use syntax:: {
8
- ast:: { self , AstNode } ,
8
+ ast:: { self , AstNode , HasLoopBody } ,
9
9
match_ast, SyntaxElement , SyntaxKind , SyntaxNode , TextRange ,
10
10
} ;
11
11
use tt:: Subtree ;
@@ -142,6 +142,39 @@ pub(crate) fn fixup_syntax(node: &SyntaxNode) -> SyntaxFixups {
142
142
] ) ;
143
143
}
144
144
} ,
145
+ ast:: WhileExpr ( it) => {
146
+ if it. condition( ) . is_none( ) {
147
+ // insert placeholder token after the while token
148
+ let while_token = match it. while_token( ) {
149
+ Some ( t) => t,
150
+ None => continue ,
151
+ } ;
152
+ append. insert( while_token. into( ) , vec![
153
+ SyntheticToken {
154
+ kind: SyntaxKind :: IDENT ,
155
+ text: "__ra_fixup" . into( ) ,
156
+ range: end_range,
157
+ id: EMPTY_ID ,
158
+ } ,
159
+ ] ) ;
160
+ }
161
+ if it. loop_body( ) . is_none( ) {
162
+ append. insert( node. clone( ) . into( ) , vec![
163
+ SyntheticToken {
164
+ kind: SyntaxKind :: L_CURLY ,
165
+ text: "{" . into( ) ,
166
+ range: end_range,
167
+ id: EMPTY_ID ,
168
+ } ,
169
+ SyntheticToken {
170
+ kind: SyntaxKind :: R_CURLY ,
171
+ text: "}" . into( ) ,
172
+ range: end_range,
173
+ id: EMPTY_ID ,
174
+ } ,
175
+ ] ) ;
176
+ }
177
+ } ,
145
178
// FIXME: foo::
146
179
// FIXME: for, loop, match etc.
147
180
_ => ( ) ,
@@ -376,6 +409,47 @@ fn foo() {
376
409
// the {} gets parsed as the condition, I think?
377
410
expect ! [ [ r#"
378
411
fn foo () {if {} {}}
412
+ "# ] ] ,
413
+ )
414
+ }
415
+
416
+ #[ test]
417
+ fn fixup_while_1 ( ) {
418
+ check (
419
+ r#"
420
+ fn foo() {
421
+ while
422
+ }
423
+ "# ,
424
+ expect ! [ [ r#"
425
+ fn foo () {while __ra_fixup {}}
426
+ "# ] ] ,
427
+ )
428
+ }
429
+
430
+ #[ test]
431
+ fn fixup_while_2 ( ) {
432
+ check (
433
+ r#"
434
+ fn foo() {
435
+ while foo
436
+ }
437
+ "# ,
438
+ expect ! [ [ r#"
439
+ fn foo () {while foo {}}
440
+ "# ] ] ,
441
+ )
442
+ }
443
+ #[ test]
444
+ fn fixup_while_3 ( ) {
445
+ check (
446
+ r#"
447
+ fn foo() {
448
+ while {}
449
+ }
450
+ "# ,
451
+ expect ! [ [ r#"
452
+ fn foo () {while __ra_fixup {}}
379
453
"# ] ] ,
380
454
)
381
455
}
0 commit comments