aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-05-08 22:14:47 +0100
committerGitHub <[email protected]>2021-05-08 22:14:47 +0100
commit6cd11bbbc235bcc3891f20c6d4097834cf1990e5 (patch)
tree8f246de36dcc04d33285ab2f2f9558f7e975626a /crates
parent4e33cbc6ad40b993d2c0e67a93bbf4a48a54a8eb (diff)
parent174f043c8d9186d2bec7c9a45b7a6ca68b232c80 (diff)
Merge #8775
8775: Add `=` to pattern recovery r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ide_completion/src/context.rs23
-rw-r--r--crates/parser/src/grammar/patterns.rs2
2 files changed, 23 insertions, 2 deletions
diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs
index 62ef40818..787eb2fd3 100644
--- a/crates/ide_completion/src/context.rs
+++ b/crates/ide_completion/src/context.rs
@@ -313,7 +313,8 @@ impl<'a> CompletionContext<'a> {
313 cov_mark::hit!(expected_type_let_with_leading_char); 313 cov_mark::hit!(expected_type_let_with_leading_char);
314 cov_mark::hit!(expected_type_let_without_leading_char); 314 cov_mark::hit!(expected_type_let_without_leading_char);
315 let ty = it.pat() 315 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)));
317 let name = if let Some(ast::Pat::IdentPat(ident)) = it.pat() { 318 let name = if let Some(ast::Pat::IdentPat(ident)) = it.pat() {
318 ident.name().map(NameOrNameRef::Name) 319 ident.name().map(NameOrNameRef::Name)
319 } else { 320 } else {
@@ -720,6 +721,26 @@ fn foo() {
720 } 721 }
721 722
722 #[test] 723 #[test]
724 fn expected_type_let_pat() {
725 check_expected_type_and_name(
726 r#"
727fn foo() {
728 let x$0 = 0u32;
729}
730"#,
731 expect![[r#"ty: u32, name: ?"#]],
732 );
733 check_expected_type_and_name(
734 r#"
735fn foo() {
736 let $0 = 0u32;
737}
738"#,
739 expect![[r#"ty: u32, name: ?"#]],
740 );
741 }
742
743 #[test]
723 fn expected_type_fn_param_without_leading_char() { 744 fn expected_type_fn_param_without_leading_char() {
724 cov_mark::check!(expected_type_fn_param_without_leading_char); 745 cov_mark::check!(expected_type_fn_param_without_leading_char);
725 check_expected_type_and_name( 746 check_expected_type_and_name(
diff --git a/crates/parser/src/grammar/patterns.rs b/crates/parser/src/grammar/patterns.rs
index 3ab347834..f1d1f9eaa 100644
--- a/crates/parser/src/grammar/patterns.rs
+++ b/crates/parser/src/grammar/patterns.rs
@@ -83,7 +83,7 @@ fn pattern_single_r(p: &mut Parser, recovery_set: TokenSet) {
83} 83}
84 84
85const PAT_RECOVERY_SET: TokenSet = 85const 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![=]]);
87 87
88fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> { 88fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
89 let m = match p.nth(0) { 89 let m = match p.nth(0) {