@@ -2070,7 +2070,14 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
20702070
20712071 // Don't print the tuple of capture types
20722072 if !is_upvar_tys_infer_tuple {
2073- err. note ( & format ! ( "required because it appears within the type `{}`" , ty) ) ;
2073+ let msg = format ! ( "required because it appears within the type `{}`" , ty) ;
2074+ match ty. kind ( ) {
2075+ ty:: Adt ( def, _) => match self . tcx . item_name_from_hir ( def. did ) {
2076+ Some ( ident) => err. span_note ( ident. span , & msg) ,
2077+ None => err. note ( & msg) ,
2078+ } ,
2079+ _ => err. note ( & msg) ,
2080+ } ;
20742081 }
20752082
20762083 obligated_types. push ( ty) ;
@@ -2092,11 +2099,36 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
20922099 ObligationCauseCode :: ImplDerivedObligation ( ref data) => {
20932100 let mut parent_trait_ref = self . resolve_vars_if_possible ( data. parent_trait_ref ) ;
20942101 let parent_def_id = parent_trait_ref. def_id ( ) ;
2095- err . note ( & format ! (
2102+ let msg = format ! (
20962103 "required because of the requirements on the impl of `{}` for `{}`" ,
20972104 parent_trait_ref. print_only_trait_path( ) ,
20982105 parent_trait_ref. skip_binder( ) . self_ty( )
2099- ) ) ;
2106+ ) ;
2107+ let mut candidates = vec ! [ ] ;
2108+ self . tcx . for_each_relevant_impl (
2109+ parent_def_id,
2110+ parent_trait_ref. self_ty ( ) . skip_binder ( ) ,
2111+ |impl_def_id| {
2112+ candidates. push ( impl_def_id) ;
2113+ } ,
2114+ ) ;
2115+ match & candidates[ ..] {
2116+ [ def_id] => match self . tcx . hir ( ) . get_if_local ( * def_id) {
2117+ Some ( Node :: Item ( hir:: Item {
2118+ kind : hir:: ItemKind :: Impl ( hir:: Impl { of_trait, self_ty, .. } ) ,
2119+ ..
2120+ } ) ) => {
2121+ let mut spans = Vec :: with_capacity ( 2 ) ;
2122+ if let Some ( trait_ref) = of_trait {
2123+ spans. push ( trait_ref. path . span ) ;
2124+ }
2125+ spans. push ( self_ty. span ) ;
2126+ err. span_note ( spans, & msg)
2127+ }
2128+ _ => err. note ( & msg) ,
2129+ } ,
2130+ _ => err. note ( & msg) ,
2131+ } ;
21002132
21012133 let mut parent_predicate = parent_trait_ref. without_const ( ) . to_predicate ( tcx) ;
21022134 let mut data = data;
0 commit comments