@@ -105,9 +105,12 @@ fn complete_fields(
105
105
mut named_field : impl FnMut ( & mut Completions , hir:: Field , hir:: Type ) ,
106
106
mut tuple_index : impl FnMut ( & mut Completions , usize , hir:: Type ) ,
107
107
) {
108
+ let mut seen_names = FxHashSet :: default ( ) ;
108
109
for receiver in receiver. autoderef ( ctx. db ) {
109
110
for ( field, ty) in receiver. fields ( ctx. db ) {
110
- named_field ( acc, field, ty) ;
111
+ if seen_names. insert ( field. name ( ctx. db ) ) {
112
+ named_field ( acc, field, ty) ;
113
+ }
111
114
}
112
115
for ( i, ty) in receiver. tuple_fields ( ctx. db ) . into_iter ( ) . enumerate ( ) {
113
116
// Tuple fields are always public (tuple struct fields are handled above).
@@ -671,6 +674,52 @@ impl T {
671
674
) ;
672
675
}
673
676
677
+ #[ test]
678
+ fn test_field_no_same_name ( ) {
679
+ check (
680
+ r#"
681
+ //- minicore: deref
682
+ struct A { field: u8 }
683
+ struct B { field: u16, another: u32 }
684
+ impl core::ops::Deref for A {
685
+ type Target = B;
686
+ fn deref(&self) -> &Self::Target { loop {} }
687
+ }
688
+ fn test(a: A) {
689
+ a.$0
690
+ }
691
+ "# ,
692
+ expect ! [ [ r#"
693
+ fd another u32
694
+ fd field u8
695
+ me deref() (use core::ops::Deref) fn(&self) -> &<Self as Deref>::Target
696
+ "# ] ] ,
697
+ ) ;
698
+ }
699
+
700
+ #[ test]
701
+ fn test_tuple_field_no_same_index ( ) {
702
+ check (
703
+ r#"
704
+ //- minicore: deref
705
+ struct A(u8);
706
+ struct B(u16, u32);
707
+ impl core::ops::Deref for A {
708
+ type Target = B;
709
+ fn deref(&self) -> &Self::Target { loop {} }
710
+ }
711
+ fn test(a: A) {
712
+ a.$0
713
+ }
714
+ "# ,
715
+ expect ! [ [ r#"
716
+ fd 0 u8
717
+ fd 1 u32
718
+ me deref() (use core::ops::Deref) fn(&self) -> &<Self as Deref>::Target
719
+ "# ] ] ,
720
+ ) ;
721
+ }
722
+
674
723
#[ test]
675
724
fn test_completion_works_in_consts ( ) {
676
725
check (
@@ -1000,7 +1049,6 @@ fn test(a: A) {
1000
1049
}
1001
1050
"# ,
1002
1051
expect ! [ [ r#"
1003
- fd 0 u16
1004
1052
fd 0 u8
1005
1053
me deref() (use core::ops::Deref) fn(&self) -> &<Self as Deref>::Target
1006
1054
"# ] ] ,
0 commit comments