about summary refs log tree commit diff
diff options
context:
space:
mode:
authorfprasx <felix725@gmail.com>2022-08-04 09:28:25 -0400
committerfprasx <felix725@gmail.com>2022-08-04 09:28:25 -0400
commitd6d8a1c18f29ad6402f9594e3908cbb6d80aa31c (patch)
treeecb2ccc7292b237d4e49ca5e0ad50533f9d1b880
parentef2eabbfa84fb11deda705df724b28ef3431256c (diff)
downloadrust-d6d8a1c18f29ad6402f9594e3908cbb6d80aa31c.tar.gz
rust-d6d8a1c18f29ad6402f9594e3908cbb6d80aa31c.zip
Shortened fixup for match, added cases for for
Previously added a blank _ => {} for match statements
-rw-r--r--crates/hir-expand/src/fixup.rs53
1 files changed, 18 insertions, 35 deletions
diff --git a/crates/hir-expand/src/fixup.rs b/crates/hir-expand/src/fixup.rs
index cd02c802e50..58d73f2d6c0 100644
--- a/crates/hir-expand/src/fixup.rs
+++ b/crates/hir-expand/src/fixup.rs
@@ -218,36 +218,6 @@ pub(crate) fn fixup_syntax(node: &SyntaxNode) -> SyntaxFixups {
                                 id: EMPTY_ID,
                             },
                             SyntheticToken {
-                                kind: SyntaxKind::UNDERSCORE,
-                                text: "_".into(),
-                                range: end_range,
-                                id: EMPTY_ID
-                            },
-                            SyntheticToken {
-                                kind: SyntaxKind::EQ,
-                                text: "=".into(),
-                                range: end_range,
-                                id: EMPTY_ID
-                            },
-                            SyntheticToken {
-                                kind: SyntaxKind::R_ANGLE,
-                                text: ">".into(),
-                                range: end_range,
-                                id: EMPTY_ID
-                            },
-                            SyntheticToken {
-                                kind: SyntaxKind::L_CURLY,
-                                text: "{".into(),
-                                range: end_range,
-                                id: EMPTY_ID,
-                            },
-                            SyntheticToken {
-                                kind: SyntaxKind::R_CURLY,
-                                text: "}".into(),
-                                range: end_range,
-                                id: EMPTY_ID,
-                            },
-                            SyntheticToken {
                                 kind: SyntaxKind::R_CURLY,
                                 text: "}".into(),
                                 range: end_range,
@@ -270,11 +240,12 @@ pub(crate) fn fixup_syntax(node: &SyntaxNode) -> SyntaxFixups {
 
                     if it.pat().is_none() && it.in_token().is_none() && it.iterable().is_none() {
                         append.insert(for_token.into(), vec![pat, in_token, iter]);
+                    } else if it.pat().is_none() {
+                        append.insert(for_token.into(), vec![pat]);
+                    } else if it.pat().is_none() && it.in_token().is_none() {
+                        append.insert(for_token.into(), vec![pat, in_token]);
                     }
 
-                    // Tricky: add logic to add in just a pattern or iterable if not all
-                    // the pieces are missing
-
                     if it.loop_body().is_none() {
                         append.insert(node.clone().into(), vec![
                             SyntheticToken {
@@ -398,6 +369,18 @@ fn foo () {for _ in __ra_fixup {}}
         )
     }
 
+    fn for_no_iter_no_in() {
+        check(
+            r#"
+fn foo() {
+    for _ {}
+}
+"#,
+            expect![[r#"
+fn foo () {for _ in __ra_fixup {}}
+"#]],
+        )
+    }
     #[test]
     fn for_no_iter() {
         check(
@@ -435,7 +418,7 @@ fn foo() {
 }
 "#,
             expect![[r#"
-fn foo () {match __ra_fixup {_ => {}}}
+fn foo () {match __ra_fixup {}}
 "#]],
         )
     }
@@ -467,7 +450,7 @@ fn foo() {
 }
 "#,
             expect![[r#"
-fn foo () {match __ra_fixup {_ => {}}}
+fn foo () {match __ra_fixup {}}
 "#]],
         )
     }