Skip to content

Commit 6cd11bb

Browse files
bors[bot]Veykril
andauthored
Merge #8775
8775: Add `=` to pattern recovery r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 parents 4e33cbc + 174f043 commit 6cd11bb

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

crates/ide_completion/src/context.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ impl<'a> CompletionContext<'a> {
313313
cov_mark::hit!(expected_type_let_with_leading_char);
314314
cov_mark::hit!(expected_type_let_without_leading_char);
315315
let ty = it.pat()
316-
.and_then(|pat| self.sema.type_of_pat(&pat));
316+
.and_then(|pat| self.sema.type_of_pat(&pat))
317+
.or_else(|| it.initializer().and_then(|it| self.sema.type_of_expr(&it)));
317318
let name = if let Some(ast::Pat::IdentPat(ident)) = it.pat() {
318319
ident.name().map(NameOrNameRef::Name)
319320
} else {
@@ -719,6 +720,26 @@ fn foo() {
719720
);
720721
}
721722

723+
#[test]
724+
fn expected_type_let_pat() {
725+
check_expected_type_and_name(
726+
r#"
727+
fn foo() {
728+
let x$0 = 0u32;
729+
}
730+
"#,
731+
expect![[r#"ty: u32, name: ?"#]],
732+
);
733+
check_expected_type_and_name(
734+
r#"
735+
fn foo() {
736+
let $0 = 0u32;
737+
}
738+
"#,
739+
expect![[r#"ty: u32, name: ?"#]],
740+
);
741+
}
742+
722743
#[test]
723744
fn expected_type_fn_param_without_leading_char() {
724745
cov_mark::check!(expected_type_fn_param_without_leading_char);

crates/parser/src/grammar/patterns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn pattern_single_r(p: &mut Parser, recovery_set: TokenSet) {
8383
}
8484

8585
const PAT_RECOVERY_SET: TokenSet =
86-
TokenSet::new(&[T![let], T![if], T![while], T![loop], T![match], T![')'], T![,]]);
86+
TokenSet::new(&[T![let], T![if], T![while], T![loop], T![match], T![')'], T![,], T![=]]);
8787

8888
fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
8989
let m = match p.nth(0) {

0 commit comments

Comments
 (0)