File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed 
compiler/rustc_trait_selection/src/traits/error_reporting Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -426,17 +426,25 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
426426                        let  ( main_trait_predicate,  o)  = if  let  ty:: PredicateKind :: Clause ( 
427427                            ty:: ClauseKind :: Trait ( root_pred) 
428428                        )  = root_obligation. predicate . kind ( ) . skip_binder ( ) 
429+                             && !trait_predicate. self_ty ( ) . skip_binder ( ) . has_escaping_bound_vars ( ) 
430+                             && !root_pred. self_ty ( ) . has_escaping_bound_vars ( ) 
429431                            // The type of the leaf predicate is (roughly) the same as the type 
430432                            // from the root predicate, as a proxy for "we care about the root" 
431433                            // FIXME: this doesn't account for trivial derefs, but works as a first 
432434                            // approximation. 
433435                            && ( 
434436                                // `T: Trait` && `&&T: OtherTrait`, we want `OtherTrait` 
435-                                 trait_predicate. self_ty ( ) . skip_binder ( ) 
436-                                     == root_pred. self_ty ( ) . peel_refs ( ) 
437+                                 self . can_eq ( 
438+                                     obligation. param_env , 
439+                                     trait_predicate. self_ty ( ) . skip_binder ( ) , 
440+                                     root_pred. self_ty ( ) . peel_refs ( ) , 
441+                                 ) 
437442                                // `&str: Iterator` && `&str: IntoIterator`, we want `IntoIterator` 
438-                                 || trait_predicate. self_ty ( ) . skip_binder ( ) 
439-                                     == root_pred. self_ty ( ) 
443+                                 || self . can_eq ( 
444+                                     obligation. param_env , 
445+                                     trait_predicate. self_ty ( ) . skip_binder ( ) , 
446+                                     root_pred. self_ty ( ) , 
447+                                 ) 
440448                            ) 
441449                            // The leaf trait and the root trait are different, so as to avoid 
442450                            // talking about `&mut T: Trait` and instead remain talking about 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments