From 174f043c8d9186d2bec7c9a45b7a6ca68b232c80 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sat, 8 May 2021 23:14:08 +0200 Subject: Add `=` to pattern recovery --- crates/ide_completion/src/context.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'crates/ide_completion') 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> { cov_mark::hit!(expected_type_let_with_leading_char); cov_mark::hit!(expected_type_let_without_leading_char); let ty = it.pat() - .and_then(|pat| self.sema.type_of_pat(&pat)); + .and_then(|pat| self.sema.type_of_pat(&pat)) + .or_else(|| it.initializer().and_then(|it| self.sema.type_of_expr(&it))); let name = if let Some(ast::Pat::IdentPat(ident)) = it.pat() { ident.name().map(NameOrNameRef::Name) } else { @@ -719,6 +720,26 @@ fn foo() { ); } + #[test] + fn expected_type_let_pat() { + check_expected_type_and_name( + r#" +fn foo() { + let x$0 = 0u32; +} +"#, + expect![[r#"ty: u32, name: ?"#]], + ); + check_expected_type_and_name( + r#" +fn foo() { + let $0 = 0u32; +} +"#, + expect![[r#"ty: u32, name: ?"#]], + ); + } + #[test] fn expected_type_fn_param_without_leading_char() { cov_mark::check!(expected_type_fn_param_without_leading_char); -- cgit v1.2.3