@@ -58,6 +58,37 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
58
58
== item2. ident ( self . tcx ) . normalize_to_macros_2_0 ( )
59
59
}
60
60
61
+ fn check_for_duplicate_items_in_impl ( & self , impl_ : DefId ) {
62
+ let impl_items = self . tcx . associated_items ( impl_) ;
63
+
64
+ let mut seen_items = FxHashMap :: default ( ) ;
65
+ for impl_item in impl_items. in_definition_order ( ) {
66
+ let span = self . tcx . def_span ( impl_item. def_id ) ;
67
+ let ident = impl_item. ident ( self . tcx ) ;
68
+
69
+ let norm_ident = ident. normalize_to_macros_2_0 ( ) ;
70
+ match seen_items. entry ( norm_ident) {
71
+ Entry :: Occupied ( entry) => {
72
+ let former = entry. get ( ) ;
73
+ let mut err = struct_span_err ! (
74
+ self . tcx. sess,
75
+ span,
76
+ E0592 ,
77
+ "duplicate definitions with name `{}`" ,
78
+ ident,
79
+ ) ;
80
+ err. span_label ( span, format ! ( "duplicate definitions for `{}`" , ident) ) ;
81
+ err. span_label ( * former, format ! ( "other definition for `{}`" , ident) ) ;
82
+
83
+ err. emit ( ) ;
84
+ }
85
+ Entry :: Vacant ( entry) => {
86
+ entry. insert ( span) ;
87
+ }
88
+ }
89
+ }
90
+ }
91
+
61
92
fn check_for_common_items_in_impls (
62
93
& self ,
63
94
impl1 : DefId ,
@@ -133,12 +164,6 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
133
164
134
165
let impls = self . tcx . inherent_impls ( id. def_id ) ;
135
166
136
- // If there is only one inherent impl block,
137
- // there is nothing to overlap check it with
138
- if impls. len ( ) <= 1 {
139
- return ;
140
- }
141
-
142
167
let overlap_mode = OverlapMode :: get ( self . tcx , id. def_id . to_def_id ( ) ) ;
143
168
144
169
let impls_items = impls
@@ -152,6 +177,8 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
152
177
const ALLOCATING_ALGO_THRESHOLD : usize = 500 ;
153
178
if impls. len ( ) < ALLOCATING_ALGO_THRESHOLD {
154
179
for ( i, & ( & impl1_def_id, impl_items1) ) in impls_items. iter ( ) . enumerate ( ) {
180
+ self . check_for_duplicate_items_in_impl ( impl1_def_id) ;
181
+
155
182
for & ( & impl2_def_id, impl_items2) in & impls_items[ ( i + 1 ) ..] {
156
183
if self . impls_have_common_items ( impl_items1, impl_items2) {
157
184
self . check_for_overlapping_inherent_impls (
@@ -290,6 +317,8 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
290
317
impl_blocks. sort_unstable ( ) ;
291
318
for ( i, & impl1_items_idx) in impl_blocks. iter ( ) . enumerate ( ) {
292
319
let & ( & impl1_def_id, impl_items1) = & impls_items[ impl1_items_idx] ;
320
+ self . check_for_duplicate_items_in_impl ( impl1_def_id) ;
321
+
293
322
for & impl2_items_idx in impl_blocks[ ( i + 1 ) ..] . iter ( ) {
294
323
let & ( & impl2_def_id, impl_items2) = & impls_items[ impl2_items_idx] ;
295
324
if self . impls_have_common_items ( impl_items1, impl_items2) {
0 commit comments