Skip to content

Commit c6a7251

Browse files
Merge pull request rust-lang#19226 from Shourya742/2025-02-25-fix-completion-ref-matching
completion-ref-matching
2 parents a43a5f9 + 2071cc2 commit c6a7251

File tree

1 file changed

+25
-3
lines changed
  • src/tools/rust-analyzer/crates/ide-completion/src

1 file changed

+25
-3
lines changed

src/tools/rust-analyzer/crates/ide-completion/src/render.rs

+25-3
Original file line numberDiff line numberDiff line change
@@ -628,11 +628,9 @@ fn compute_ref_match(
628628
let expected_type = ctx.expected_type.as_ref()?;
629629
let expected_without_ref = expected_type.remove_ref();
630630
let completion_without_ref = completion_ty.remove_ref();
631-
632-
if completion_ty == expected_type {
631+
if expected_type.could_unify_with(ctx.db, completion_ty) {
633632
return None;
634633
}
635-
636634
if let Some(expected_without_ref) = &expected_without_ref {
637635
if completion_ty.autoderef(ctx.db).any(|ty| ty == *expected_without_ref) {
638636
cov_mark::hit!(suggest_ref);
@@ -2007,6 +2005,30 @@ fn f() {
20072005
);
20082006
}
20092007

2008+
#[test]
2009+
fn test_avoid_redundant_suggestion() {
2010+
check_relevance(
2011+
r#"
2012+
struct aa([u8]);
2013+
2014+
impl aa {
2015+
fn from_bytes(bytes: &[u8]) -> &Self {
2016+
unsafe { &*(bytes as *const [u8] as *const aa) }
2017+
}
2018+
}
2019+
2020+
fn bb()-> &'static aa {
2021+
let bytes = b"hello";
2022+
aa::$0
2023+
}
2024+
"#,
2025+
expect![[r#"
2026+
ex bb() [type]
2027+
fn from_bytes(…) fn(&[u8]) -> &aa [type_could_unify]
2028+
"#]],
2029+
);
2030+
}
2031+
20102032
#[test]
20112033
fn suggest_ref_mut() {
20122034
cov_mark::check!(suggest_ref);

0 commit comments

Comments
 (0)