@@ -457,11 +457,28 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
457457 err
458458 }
459459
460+
461+ /// Get the parent trait chain start
462+ fn get_parent_trait_ref ( & self , code : & ObligationCauseCode < ' tcx > ) -> Option < String > {
463+ match code {
464+ & ObligationCauseCode :: BuiltinDerivedObligation ( ref data) => {
465+ let parent_trait_ref = self . resolve_type_vars_if_possible (
466+ & data. parent_trait_ref ) ;
467+ match self . get_parent_trait_ref ( & data. parent_code ) {
468+ Some ( t) => Some ( t) ,
469+ None => Some ( format ! ( "{}" , parent_trait_ref. 0 . self_ty( ) ) ) ,
470+ }
471+ }
472+ _ => None ,
473+ }
474+ }
475+
460476 pub fn report_selection_error ( & self ,
461477 obligation : & PredicateObligation < ' tcx > ,
462478 error : & SelectionError < ' tcx > )
463479 {
464480 let span = obligation. cause . span ;
481+
465482 let mut err = match * error {
466483 SelectionError :: Unimplemented => {
467484 if let ObligationCauseCode :: CompareImplMethodObligation {
@@ -486,16 +503,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
486503 return ;
487504 } else {
488505 let trait_ref = trait_predicate. to_poly_trait_ref ( ) ;
489-
490- let ( post_message, pre_message) =
491- if let ObligationCauseCode :: BuiltinDerivedObligation ( ref data)
492- = obligation. cause . code {
493- let parent_trait_ref = self . resolve_type_vars_if_possible (
494- & data. parent_trait_ref ) ;
495- ( format ! ( " in `{}`" , parent_trait_ref. 0 . self_ty( ) ) ,
496- format ! ( "within `{}`, " , parent_trait_ref. 0 . self_ty( ) ) )
497- } else {
498- ( String :: new ( ) , String :: new ( ) )
506+ let ( post_message, pre_message) = match self . get_parent_trait_ref (
507+ & obligation. cause . code )
508+ {
509+ Some ( t) => {
510+ ( format ! ( " in `{}`" , t) , format ! ( "within `{}`, " , t) )
511+ }
512+ None => ( String :: new ( ) , String :: new ( ) ) ,
499513 } ;
500514 let mut err = struct_span_err ! (
501515 self . tcx. sess,
0 commit comments