Skip to content

Commit ab44a81

Browse files
committed
Fixed up for loops, added fixme with problem
#12937 (comment)
1 parent d6d8a1c commit ab44a81

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

crates/hir-expand/src/fixup.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,9 @@ pub(crate) fn fixup_syntax(node: &SyntaxNode) -> SyntaxFixups {
240240

241241
if it.pat().is_none() && it.in_token().is_none() && it.iterable().is_none() {
242242
append.insert(for_token.into(), vec![pat, in_token, iter]);
243+
// does something funky -- see test case for_no_pat
243244
} else if it.pat().is_none() {
244245
append.insert(for_token.into(), vec![pat]);
245-
} else if it.pat().is_none() && it.in_token().is_none() {
246-
append.insert(for_token.into(), vec![pat, in_token]);
247246
}
248247

249248
if it.loop_body().is_none() {
@@ -356,7 +355,7 @@ mod tests {
356355
}
357356

358357
#[test]
359-
fn for_no_iter_no_body() {
358+
fn just_for_token() {
360359
check(
361360
r#"
362361
fn foo() {
@@ -369,42 +368,47 @@ fn foo () {for _ in __ra_fixup {}}
369368
)
370369
}
371370

372-
fn for_no_iter_no_in() {
371+
#[test]
372+
fn for_no_iter_pattern() {
373373
check(
374374
r#"
375375
fn foo() {
376-
for _ {}
376+
for {}
377377
}
378378
"#,
379379
expect![[r#"
380380
fn foo () {for _ in __ra_fixup {}}
381381
"#]],
382382
)
383383
}
384+
384385
#[test]
385-
fn for_no_iter() {
386+
fn for_no_body() {
386387
check(
387388
r#"
388389
fn foo() {
389-
for {}
390+
for bar in qux
390391
}
391392
"#,
392393
expect![[r#"
393-
fn foo () {for _ in __ra_fixup {}}
394+
fn foo () {for bar in qux {}}
394395
"#]],
395396
)
396397
}
397398

399+
// FIXME: https://github.com/rust-lang/rust-analyzer/pull/12937#discussion_r937633695
398400
#[test]
399-
fn for_no_body() {
401+
fn for_no_pat() {
400402
check(
401403
r#"
402404
fn foo() {
403-
for bar in qux
405+
for in qux {
406+
407+
}
404408
}
405409
"#,
406410
expect![[r#"
407-
fn foo () {for bar in qux {}}
411+
fn foo () {__ra_fixup}
408412
"#]],
409413
)
410414
}

0 commit comments

Comments
 (0)