@@ -2619,8 +2619,9 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
26192619 this. with_current_self_type ( self_type, |this| {
26202620 this. with_self_rib_ns ( ValueNS , Res :: SelfCtor ( item_def_id) , |this| {
26212621 debug ! ( "resolve_implementation with_self_rib_ns(ValueNS, ...)" ) ;
2622+ let mut seen_trait_items = Default :: default ( ) ;
26222623 for item in impl_items {
2623- this. resolve_impl_item ( & * * item) ;
2624+ this. resolve_impl_item ( & * * item, & mut seen_trait_items ) ;
26242625 }
26252626 } ) ;
26262627 } ) ;
@@ -2634,7 +2635,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
26342635 ) ;
26352636 }
26362637
2637- fn resolve_impl_item ( & mut self , item : & ' ast AssocItem ) {
2638+ fn resolve_impl_item (
2639+ & mut self ,
2640+ item : & ' ast AssocItem ,
2641+ seen_trait_items : & mut FxHashMap < DefId , Span > ,
2642+ ) {
26382643 use crate :: ResolutionError :: * ;
26392644 match & item. kind {
26402645 AssocItemKind :: Const ( _, ty, default) => {
@@ -2647,6 +2652,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
26472652 & item. kind ,
26482653 ValueNS ,
26492654 item. span ,
2655+ seen_trait_items,
26502656 |i, s, c| ConstNotMemberOfTrait ( i, s, c) ,
26512657 ) ;
26522658
@@ -2687,6 +2693,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
26872693 & item. kind ,
26882694 ValueNS ,
26892695 item. span ,
2696+ seen_trait_items,
26902697 |i, s, c| MethodNotMemberOfTrait ( i, s, c) ,
26912698 ) ;
26922699
@@ -2715,6 +2722,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
27152722 & item. kind ,
27162723 TypeNS ,
27172724 item. span ,
2725+ seen_trait_items,
27182726 |i, s, c| TypeNotMemberOfTrait ( i, s, c) ,
27192727 ) ;
27202728
@@ -2736,6 +2744,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
27362744 kind : & AssocItemKind ,
27372745 ns : Namespace ,
27382746 span : Span ,
2747+ seen_trait_items : & mut FxHashMap < DefId , Span > ,
27392748 err : F ,
27402749 ) where
27412750 F : FnOnce ( Ident , String , Option < Symbol > ) -> ResolutionError < ' a > ,
@@ -2768,7 +2777,25 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
27682777 } ;
27692778
27702779 let res = binding. res ( ) ;
2771- let Res :: Def ( def_kind, _) = res else { bug ! ( ) } ;
2780+ let Res :: Def ( def_kind, id_in_trait) = res else { bug ! ( ) } ;
2781+
2782+ match seen_trait_items. entry ( id_in_trait) {
2783+ Entry :: Occupied ( entry) => {
2784+ self . report_error (
2785+ span,
2786+ ResolutionError :: TraitImplDuplicate {
2787+ name : ident. name ,
2788+ old_span : * entry. get ( ) ,
2789+ trait_item_span : binding. span ,
2790+ } ,
2791+ ) ;
2792+ return ;
2793+ }
2794+ Entry :: Vacant ( entry) => {
2795+ entry. insert ( span) ;
2796+ }
2797+ } ;
2798+
27722799 match ( def_kind, kind) {
27732800 ( DefKind :: AssocTy , AssocItemKind :: TyAlias ( ..) )
27742801 | ( DefKind :: AssocFn , AssocItemKind :: Fn ( ..) )
0 commit comments