Skip to content

Commit f71e804

Browse files
committed
fix: no suggest ref match when expected generic ref
Example --- ```rust fn foo<T>(s: &T) {} fn main() { let ssss = &mut 2i32; foo($0); } ``` **Before this PR** ```text lc ssss &mut i32 [type_could_unify+local] lc &ssss [type+local] md core:: [] fn foo(…) fn(&T) [] fn &foo(…) [type] fn main() fn() [] fn &main() [type] ``` **After this PR** ```text lc ssss &mut i32 [type_could_unify+local] md core:: [] fn foo(…) fn(&T) [] fn &foo(…) [type] fn main() fn() [] fn &main() [type] ```
1 parent ce81cf6 commit f71e804

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

crates/ide-completion/src/render.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,12 +717,13 @@ fn compute_ref_match(
717717
ctx: &CompletionContext<'_, '_>,
718718
completion_ty: &hir::Type<'_>,
719719
) -> Option<CompletionItemRefMode> {
720+
if compute_type_match(ctx, completion_ty).is_some() {
721+
return None;
722+
}
720723
let expected_type = ctx.expected_type.as_ref()?;
721724
let expected_without_ref = expected_type.remove_ref();
722725
let completion_without_ref = completion_ty.remove_ref();
723-
if expected_type.could_unify_with(ctx.db, completion_ty) {
724-
return None;
725-
}
726+
726727
if let Some(expected_without_ref) = &expected_without_ref
727728
&& (completion_without_ref.is_none()
728729
|| completion_ty.could_unify_with(ctx.db, expected_without_ref))
@@ -2976,6 +2977,24 @@ fn main() {
29762977
fn main() fn() []
29772978
"#]],
29782979
);
2980+
check_relevance(
2981+
r#"
2982+
//- minicore: deref
2983+
fn foo<T>(s: &T) {}
2984+
fn main() {
2985+
let ssss = &mut 2i32;
2986+
foo($0);
2987+
}
2988+
"#,
2989+
expect![[r#"
2990+
lc ssss &mut i32 [type_could_unify+local]
2991+
md core:: []
2992+
fn foo(…) fn(&T) []
2993+
fn &foo(…) [type]
2994+
fn main() fn() []
2995+
fn &main() [type]
2996+
"#]],
2997+
);
29792998
}
29802999

29813000
#[test]

0 commit comments

Comments
 (0)