@@ -65,22 +65,19 @@ impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> {
6565 // borrows are safe.
6666 let blanket_impls = trait_def. blanket_impls . borrow ( ) ;
6767 let nonblanket_impls = trait_def. nonblanket_impls . borrow ( ) ;
68- let trait_def_id = trait_def. trait_ref . def_id ;
6968
7069 // Conflicts can only occur between a blanket impl and another impl,
7170 // or between 2 non-blanket impls of the same kind.
7271
7372 for ( i, & impl1_def_id) in blanket_impls. iter ( ) . enumerate ( ) {
7473 for & impl2_def_id in & blanket_impls[ ( i+1 ) ..] {
75- self . check_if_impls_overlap ( trait_def_id,
76- impl1_def_id,
74+ self . check_if_impls_overlap ( impl1_def_id,
7775 impl2_def_id) ;
7876 }
7977
8078 for v in nonblanket_impls. values ( ) {
8179 for & impl2_def_id in v {
82- self . check_if_impls_overlap ( trait_def_id,
83- impl1_def_id,
80+ self . check_if_impls_overlap ( impl1_def_id,
8481 impl2_def_id) ;
8582 }
8683 }
@@ -89,8 +86,7 @@ impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> {
8986 for impl_group in nonblanket_impls. values ( ) {
9087 for ( i, & impl1_def_id) in impl_group. iter ( ) . enumerate ( ) {
9188 for & impl2_def_id in & impl_group[ ( i+1 ) ..] {
92- self . check_if_impls_overlap ( trait_def_id,
93- impl1_def_id,
89+ self . check_if_impls_overlap ( impl1_def_id,
9490 impl2_def_id) ;
9591 }
9692 }
@@ -121,40 +117,47 @@ impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> {
121117
122118
123119 fn check_if_impls_overlap ( & self ,
124- trait_def_id : DefId ,
125120 impl1_def_id : DefId ,
126121 impl2_def_id : DefId )
127122 {
128123 if let Some ( ( impl1_def_id, impl2_def_id) ) = self . order_impls (
129124 impl1_def_id, impl2_def_id)
130125 {
131- debug ! ( "check_if_impls_overlap({:?}, {:?}, {:?})" ,
132- trait_def_id,
126+ debug ! ( "check_if_impls_overlap({:?}, {:?})" ,
133127 impl1_def_id,
134128 impl2_def_id) ;
135129
136130 let infcx = infer:: new_infer_ctxt ( self . tcx , & self . tcx . tables , None , false ) ;
137- if traits:: overlapping_impls ( & infcx, impl1_def_id, impl2_def_id) {
138- self . report_overlap_error ( trait_def_id , impl1_def_id, impl2_def_id) ;
131+ if let Some ( trait_ref ) = traits:: overlapping_impls ( & infcx, impl1_def_id, impl2_def_id) {
132+ self . report_overlap_error ( impl1_def_id, impl2_def_id, trait_ref ) ;
139133 }
140134 }
141135 }
142136
143- fn report_overlap_error ( & self , trait_def_id : DefId ,
144- impl1 : DefId , impl2 : DefId ) {
137+ fn report_overlap_error ( & self ,
138+ impl1 : DefId ,
139+ impl2 : DefId ,
140+ trait_ref : ty:: TraitRef )
141+ {
142+ // only print the Self type if it's concrete; otherwise, it's not adding much information.
143+ let self_type = {
144+ trait_ref. substs . self_ty ( ) . and_then ( |ty| {
145+ if let ty:: TyInfer ( _) = ty. sty {
146+ None
147+ } else {
148+ Some ( format ! ( " for type `{}`" , ty) )
149+ }
150+ } ) . unwrap_or ( String :: new ( ) )
151+ } ;
145152
146153 span_err ! ( self . tcx. sess, self . span_of_impl( impl1) , E0119 ,
147- "conflicting implementations for trait `{}`" ,
148- self . tcx. item_path_str( trait_def_id) ) ;
149-
150- self . report_overlap_note ( impl2) ;
151- }
152-
153- fn report_overlap_note ( & self , impl2 : DefId ) {
154+ "conflicting implementations of trait `{}`{}:" ,
155+ trait_ref,
156+ self_type) ;
154157
155158 if impl2. is_local ( ) {
156159 span_note ! ( self . tcx. sess, self . span_of_impl( impl2) ,
157- "note conflicting implementation here" ) ;
160+ "conflicting implementation is here: " ) ;
158161 } else {
159162 let cname = self . tcx . sess . cstore . crate_name ( impl2. krate ) ;
160163 self . tcx . sess . note ( & format ! ( "conflicting implementation in crate `{}`" , cname) ) ;
@@ -180,9 +183,9 @@ impl<'cx, 'tcx,'v> intravisit::Visitor<'v> for OverlapChecker<'cx, 'tcx> {
180183 let prev_default_impl = self . default_impls . insert ( trait_ref. def_id , item. id ) ;
181184 match prev_default_impl {
182185 Some ( prev_id) => {
183- self . report_overlap_error ( trait_ref . def_id ,
184- impl_def_id ,
185- self . tcx . map . local_def_id ( prev_id ) ) ;
186+ self . report_overlap_error ( impl_def_id ,
187+ self . tcx . map . local_def_id ( prev_id ) ,
188+ trait_ref ) ;
186189 }
187190 None => { }
188191 }
0 commit comments