Skip to content

Commit d01283b

Browse files
committed
Deduplicate tuple indices for completion
1 parent 42eab5e commit d01283b

File tree

1 file changed

+28
-2
lines changed
  • crates/ide-completion/src/completions

1 file changed

+28
-2
lines changed

crates/ide-completion/src/completions/dot.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,12 @@ fn complete_fields(
113113
}
114114
}
115115
for (i, ty) in receiver.tuple_fields(ctx.db).into_iter().enumerate() {
116-
// Tuple fields are always public (tuple struct fields are handled above).
117-
tuple_index(acc, i, ty);
116+
// Tuples are always the last type in a deref chain, so just check if the name is
117+
// already seen without inserting into the hashset.
118+
if !seen_names.contains(&hir::Name::new_tuple_field(i)) {
119+
// Tuple fields are always public (tuple struct fields are handled above).
120+
tuple_index(acc, i, ty);
121+
}
118122
}
119123
}
120124
}
@@ -720,6 +724,28 @@ fn test(a: A) {
720724
);
721725
}
722726

727+
#[test]
728+
fn test_tuple_struct_deref_to_tuple_no_same_index() {
729+
check(
730+
r#"
731+
//- minicore: deref
732+
struct A(u8);
733+
impl core::ops::Deref for A {
734+
type Target = (u16, u32);
735+
fn deref(&self) -> &Self::Target { loop {} }
736+
}
737+
fn test(a: A) {
738+
a.$0
739+
}
740+
"#,
741+
expect![[r#"
742+
fd 0 u8
743+
fd 1 u32
744+
me deref() (use core::ops::Deref) fn(&self) -> &<Self as Deref>::Target
745+
"#]],
746+
);
747+
}
748+
723749
#[test]
724750
fn test_completion_works_in_consts() {
725751
check(

0 commit comments

Comments
 (0)