diff options
| author | bors <bors@rust-lang.org> | 2023-03-15 09:47:20 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-03-15 09:47:20 +0000 |
| commit | e611fbe6ab345f7bc0a679154fda967e21dfe9c8 (patch) | |
| tree | 40a31061fbb7a48dae97c3ead2d5bcbdc970f6ed | |
| parent | 1a318965fe3f9afa153a620d4a261e68c9589c87 (diff) | |
| parent | 82ed68c95edbc145b9318b147ec5bcb70869a513 (diff) | |
| download | rust-e611fbe6ab345f7bc0a679154fda967e21dfe9c8.tar.gz rust-e611fbe6ab345f7bc0a679154fda967e21dfe9c8.zip | |
Auto merge of #14355 - Veykril:completion-ref-strip, r=Veykril
fix: Fix reference completions being emitted in places other than argument lists Fixes https://github.com/rust-lang/rust-analyzer/issues/14331
| -rw-r--r-- | crates/ide-completion/src/context/analysis.rs | 9 | ||||
| -rw-r--r-- | crates/ide-completion/src/context/tests.rs | 12 |
2 files changed, 16 insertions, 5 deletions
diff --git a/crates/ide-completion/src/context/analysis.rs b/crates/ide-completion/src/context/analysis.rs index db0045aef6e..fff9678e5e9 100644 --- a/crates/ide-completion/src/context/analysis.rs +++ b/crates/ide-completion/src/context/analysis.rs @@ -353,7 +353,7 @@ fn expected_type_and_name( _ => ty, }; - loop { + let (ty, name) = loop { break match_ast! { match node { ast::LetStmt(it) => { @@ -385,9 +385,7 @@ fn expected_type_and_name( token.clone(), ).map(|ap| { let name = ap.ident().map(NameOrNameRef::Name); - - let ty = strip_refs(ap.ty); - (Some(ty), name) + (Some(ap.ty), name) }) .unwrap_or((None, None)) }, @@ -489,7 +487,8 @@ fn expected_type_and_name( }, } }; - } + }; + (ty.map(strip_refs), name) } fn classify_lifetime( diff --git a/crates/ide-completion/src/context/tests.rs b/crates/ide-completion/src/context/tests.rs index a654a5db574..82a1c10c531 100644 --- a/crates/ide-completion/src/context/tests.rs +++ b/crates/ide-completion/src/context/tests.rs @@ -411,3 +411,15 @@ fn main() { expect!["ty: i32, name: ?"], ); } + +#[test] +fn expected_type_ref_return_pos() { + check_expected_type_and_name( + r#" +fn f(thing: u32) -> &u32 { + &thin$0 +} +"#, + expect!["ty: u32, name: ?"], + ); +} |
