Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/render.rs')
-rw-r--r--crates/ide-completion/src/render.rs45
1 files changed, 33 insertions, 12 deletions
diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs
index 9c1cf61622..e2bfb7909e 100644
--- a/crates/ide-completion/src/render.rs
+++ b/crates/ide-completion/src/render.rs
@@ -494,7 +494,13 @@ fn render_resolution_path(
..CompletionRelevance::default()
});
- path_ref_match(completion, path_ctx, &ty, &mut item);
+ match resolution {
+ ScopeDef::Local(_)
+ | ScopeDef::ModuleDef(ModuleDef::Const(_) | ModuleDef::Static(_)) => {
+ path_ref_match(completion, path_ctx, &ty, &mut item)
+ }
+ _ => (),
+ }
};
match resolution {
@@ -722,7 +728,7 @@ fn compute_ref_match(
|| completion_ty.could_unify_with(ctx.db, expected_without_ref))
&& completion_ty
.autoderef(ctx.db)
- .any(|ty| ty.could_unify_with(ctx.db, expected_without_ref))
+ .any(|ty| !ty.is_unknown() && ty.could_unify_with(ctx.db, expected_without_ref))
{
cov_mark::hit!(suggest_ref);
let mutability = if expected_type.is_mutable_reference() {
@@ -2641,7 +2647,6 @@ fn go(world: &WorldSnapshot) { go(w$0) }
st WorldSnapshot {…} WorldSnapshot { _f: () } []
st &WorldSnapshot {…} [type]
st WorldSnapshot WorldSnapshot []
- st &WorldSnapshot [type]
fn go(…) fn(&WorldSnapshot) []
"#]],
);
@@ -2867,7 +2872,6 @@ fn main() {
st S S []
st &mut S [type]
st S S []
- st &mut S [type]
fn foo(…) fn(&mut S) []
fn main() fn() []
"#]],
@@ -2881,6 +2885,7 @@ fn main() {
foo(&mut $0);
}
"#,
+ // FIXME: There are many `S` here
expect![[r#"
lc s S [type+name+local]
st S S [type]
@@ -2943,11 +2948,34 @@ fn main() {
lc ssss S<u32> [local]
lc &mut ssss [type+local]
st S S<{unknown}> []
- st &mut S [type]
fn foo(…) fn(&mut S<T>) []
fn main() fn() []
"#]],
);
+ // Regression test https://github.com/rust-lang/rust-analyzer/issues/22324
+ check_relevance(
+ r#"
+//- minicore: deref
+struct S<T>(T);
+impl<T> core::ops::Deref for S<T> {
+ type Target = T;
+}
+fn foo<T>(s: &u32) {}
+fn main() {
+ let ssss = S();
+ foo($0);
+}
+ "#,
+ // FIXME: term_search exclude ssss.0 (field.ty().is_unknown())
+ expect![[r#"
+ ex ssss.0 [type_could_unify]
+ lc ssss S<{unknown}> [local]
+ st S S<{unknown}> []
+ md core:: []
+ fn foo(…) fn(&u32) []
+ fn main() fn() []
+ "#]],
+ );
}
#[test]
@@ -3018,9 +3046,7 @@ fn main() {
lc t T [local]
lc &t [type+local]
st S S []
- st &S [type]
st T T []
- st &T [type]
md core:: []
fn foo(…) fn(&S) []
fn main() fn() []
@@ -3067,9 +3093,7 @@ fn main() {
lc t T [local]
lc &mut t [type+local]
st S S []
- st &mut S [type]
st T T []
- st &mut T [type]
md core:: []
fn foo(…) fn(&mut S) []
fn main() fn() []
@@ -3133,7 +3157,6 @@ fn bar(t: &Foo) {}
ev Foo::B Foo::B []
ev &Foo::B [type]
en Foo Foo []
- en &Foo [type]
fn bar(…) fn(&Foo) []
fn foo() fn() []
"#]],
@@ -3168,9 +3191,7 @@ fn main() {
st &S [type]
ex core::ops::Deref::deref(&bar()) [type_could_unify]
st S S []
- st &S [type]
st T T []
- st &T [type]
fn bar() fn() -> T []
fn &bar() [type]
md core:: []