Skip to content

Commit facaa68

Browse files
committed
fix: ref match uses unified type
Example --- ```rust struct S<T>(T); fn foo<T>(s: &mut S<T>) {} fn main() { let mut ssss = S(2u32); foo($0); } ``` **Before this PR** ```text st S(…) S(T) [] st &mut S(…) [type] lc ssss S<u32> [local] ``` **After this PR** ```text st S(…) S(T) [] st &mut S(…) [type] lc ssss S<u32> [local] lc &mut ssss [type+local] ```
1 parent f04c372 commit facaa68

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

crates/ide-completion/src/render.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,9 @@ fn compute_ref_match(
713713
if let Some(expected_without_ref) = &expected_without_ref
714714
&& (completion_without_ref.is_none()
715715
|| completion_ty.could_unify_with(ctx.db, expected_without_ref))
716-
&& completion_ty.autoderef(ctx.db).any(|ty| ty == *expected_without_ref)
716+
&& completion_ty
717+
.autoderef(ctx.db)
718+
.any(|ty| ty.could_unify_with(ctx.db, expected_without_ref))
717719
{
718720
cov_mark::hit!(suggest_ref);
719721
let mutability = if expected_type.is_mutable_reference() {
@@ -2917,6 +2919,26 @@ fn main() {
29172919
fn main() fn() []
29182920
"#]],
29192921
);
2922+
check_relevance(
2923+
r#"
2924+
struct S<T>(T);
2925+
fn foo<T>(s: &mut S<T>) {}
2926+
fn main() {
2927+
let mut ssss = S(2u32);
2928+
foo($0);
2929+
}
2930+
"#,
2931+
expect![[r#"
2932+
st S(…) S(T) []
2933+
st &mut S(…) [type]
2934+
lc ssss S<u32> [local]
2935+
lc &mut ssss [type+local]
2936+
st S S<{unknown}> []
2937+
st &mut S [type]
2938+
fn foo(…) fn(&mut S<T>) []
2939+
fn main() fn() []
2940+
"#]],
2941+
);
29202942
}
29212943

29222944
#[test]

0 commit comments

Comments
 (0)