@@ -1260,40 +1260,47 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
12601260 "type mismatch resolving `{}`" ,
12611261 predicate
12621262 ) ;
1263- self . note_type_err ( & mut diag, & obligation. cause , None , values, err) ;
1263+ let secondary_span = match predicate. kind ( ) . skip_binder ( ) {
1264+ ty:: PredicateKind :: Projection ( proj) => self
1265+ . tcx
1266+ . opt_associated_item ( proj. projection_ty . item_def_id )
1267+ . and_then ( |trait_assoc_item| {
1268+ self . tcx
1269+ . trait_of_item ( proj. projection_ty . item_def_id )
1270+ . map ( |id| ( trait_assoc_item, id) )
1271+ } )
1272+ . and_then ( |( trait_assoc_item, id) | {
1273+ self . tcx . find_map_relevant_impl (
1274+ id,
1275+ proj. projection_ty . self_ty ( ) ,
1276+ |did| {
1277+ self . tcx
1278+ . associated_items ( did)
1279+ . in_definition_order ( )
1280+ . filter ( |assoc| assoc. ident == trait_assoc_item. ident )
1281+ . next ( )
1282+ } ,
1283+ )
1284+ } )
1285+ . and_then ( |item| match self . tcx . hir ( ) . get_if_local ( item. def_id ) {
1286+ Some (
1287+ hir:: Node :: TraitItem ( hir:: TraitItem {
1288+ kind : hir:: TraitItemKind :: Type ( _, Some ( ty) ) ,
1289+ ..
1290+ } )
1291+ | hir:: Node :: ImplItem ( hir:: ImplItem {
1292+ kind : hir:: ImplItemKind :: TyAlias ( ty) ,
1293+ ..
1294+ } ) ,
1295+ ) => {
1296+ Some ( ( ty. span , format ! ( "type mismatch resolving `{}`" , predicate) ) )
1297+ }
1298+ _ => None ,
1299+ } ) ,
1300+ _ => None ,
1301+ } ;
1302+ self . note_type_err ( & mut diag, & obligation. cause , secondary_span, values, err, true ) ;
12641303 self . note_obligation_cause ( & mut diag, obligation) ;
1265- match predicate. kind ( ) . skip_binder ( ) {
1266- ty:: PredicateKind :: Projection ( proj) => {
1267- let item = self
1268- . tcx
1269- . opt_associated_item ( proj. projection_ty . item_def_id )
1270- . and_then ( |trait_assoc_item| {
1271- self . tcx
1272- . trait_of_item ( proj. projection_ty . item_def_id )
1273- . map ( |id| ( trait_assoc_item, id) )
1274- } )
1275- . and_then ( |( trait_assoc_item, id) | {
1276- self . tcx . find_map_relevant_impl (
1277- id,
1278- proj. projection_ty . self_ty ( ) ,
1279- |did| {
1280- self . tcx
1281- . associated_items ( did)
1282- . in_definition_order ( )
1283- . filter ( |assoc| assoc. ident == trait_assoc_item. ident )
1284- . next ( )
1285- } ,
1286- )
1287- } ) ;
1288- if let Some ( item) = item {
1289- diag. span_label (
1290- item. ident . span ,
1291- & format ! ( "type mismatch with `{}` here" , proj. ty) ,
1292- ) ;
1293- }
1294- }
1295- _ => { }
1296- }
12971304 diag. emit ( ) ;
12981305 }
12991306 } ) ;
0 commit comments