@@ -457,11 +457,28 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
457
457
err
458
458
}
459
459
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
+
460
476
pub fn report_selection_error ( & self ,
461
477
obligation : & PredicateObligation < ' tcx > ,
462
478
error : & SelectionError < ' tcx > )
463
479
{
464
480
let span = obligation. cause . span ;
481
+
465
482
let mut err = match * error {
466
483
SelectionError :: Unimplemented => {
467
484
if let ObligationCauseCode :: CompareImplMethodObligation {
@@ -486,16 +503,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
486
503
return ;
487
504
} else {
488
505
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 ( ) ) ,
499
513
} ;
500
514
let mut err = struct_span_err ! (
501
515
self . tcx. sess,
0 commit comments