@@ -2067,7 +2067,14 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
20672067
20682068 // Don't print the tuple of capture types
20692069 if !is_upvar_tys_infer_tuple {
2070- err. note ( & format ! ( "required because it appears within the type `{}`" , ty) ) ;
2070+ let msg = format ! ( "required because it appears within the type `{}`" , ty) ;
2071+ match ty. kind ( ) {
2072+ ty:: Adt ( def, _) => match self . tcx . item_name_from_hir ( def. did ) {
2073+ Some ( ident) => err. span_note ( ident. span , & msg) ,
2074+ None => err. note ( & msg) ,
2075+ } ,
2076+ _ => err. note ( & msg) ,
2077+ } ;
20712078 }
20722079
20732080 obligated_types. push ( ty) ;
@@ -2089,11 +2096,36 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
20892096 ObligationCauseCode :: ImplDerivedObligation ( ref data) => {
20902097 let mut parent_trait_ref = self . resolve_vars_if_possible ( data. parent_trait_ref ) ;
20912098 let parent_def_id = parent_trait_ref. def_id ( ) ;
2092- err . note ( & format ! (
2099+ let msg = format ! (
20932100 "required because of the requirements on the impl of `{}` for `{}`" ,
20942101 parent_trait_ref. print_only_trait_path( ) ,
20952102 parent_trait_ref. skip_binder( ) . self_ty( )
2096- ) ) ;
2103+ ) ;
2104+ let mut candidates = vec ! [ ] ;
2105+ self . tcx . for_each_relevant_impl (
2106+ parent_def_id,
2107+ parent_trait_ref. self_ty ( ) . skip_binder ( ) ,
2108+ |impl_def_id| {
2109+ candidates. push ( impl_def_id) ;
2110+ } ,
2111+ ) ;
2112+ match & candidates[ ..] {
2113+ [ def_id] => match self . tcx . hir ( ) . get_if_local ( * def_id) {
2114+ Some ( Node :: Item ( hir:: Item {
2115+ kind : hir:: ItemKind :: Impl ( hir:: Impl { of_trait, self_ty, .. } ) ,
2116+ ..
2117+ } ) ) => {
2118+ let mut spans = Vec :: with_capacity ( 2 ) ;
2119+ if let Some ( trait_ref) = of_trait {
2120+ spans. push ( trait_ref. path . span ) ;
2121+ }
2122+ spans. push ( self_ty. span ) ;
2123+ err. span_note ( spans, & msg)
2124+ }
2125+ _ => err. note ( & msg) ,
2126+ } ,
2127+ _ => err. note ( & msg) ,
2128+ } ;
20972129
20982130 let mut parent_predicate = parent_trait_ref. without_const ( ) . to_predicate ( tcx) ;
20992131 let mut data = data;
0 commit comments