Shortened fixup for match, added cases for for

Previously added a blank _ => {} for match statements
This commit is contained in:
fprasx 2022-08-04 09:28:25 -04:00
parent ef2eabbfa8
commit d6d8a1c18f

View file

@ -217,36 +217,6 @@ pub(crate) fn fixup_syntax(node: &SyntaxNode) -> SyntaxFixups {
range: end_range,
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(),
@ -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 {}}
"#]],
)
}