@@ -5,7 +5,6 @@ use super::{
5
5
PredicateObligation ,
6
6
} ;
7
7
8
- use crate :: autoderef:: Autoderef ;
9
8
use crate :: infer:: InferCtxt ;
10
9
use crate :: traits:: { NormalizeExt , ObligationCtxt } ;
11
10
@@ -750,26 +749,30 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
750
749
}
751
750
752
751
if let ty:: Ref ( region, base_ty, mutbl) = * real_ty. skip_binder ( ) . kind ( ) {
753
- let mut autoderef = Autoderef :: new (
754
- self ,
755
- obligation. param_env ,
756
- obligation. cause . body_id ,
757
- span,
758
- base_ty,
759
- ) ;
760
- if let Some ( steps) = autoderef. find_map ( |( ty, steps) | {
761
- // Re-add the `&`
762
- let ty = self . tcx . mk_ref ( region, TypeAndMut { ty, mutbl } ) ;
763
-
764
- // Remapping bound vars here
765
- let real_trait_pred_and_ty =
766
- real_trait_pred. map_bound ( |inner_trait_pred| ( inner_trait_pred, ty) ) ;
767
- let obligation = self . mk_trait_obligation_with_new_self_ty (
768
- obligation. param_env ,
769
- real_trait_pred_and_ty,
770
- ) ;
771
- Some ( steps) . filter ( |_| self . predicate_may_hold ( & obligation) )
772
- } ) {
752
+ let autoderef = ( self . autoderef_steps ) ( base_ty) ;
753
+ if let Some ( steps) =
754
+ autoderef. into_iter ( ) . enumerate ( ) . find_map ( |( steps, ( ty, obligations) ) | {
755
+ // Re-add the `&`
756
+ let ty = self . tcx . mk_ref ( region, TypeAndMut { ty, mutbl } ) ;
757
+
758
+ // Remapping bound vars here
759
+ let real_trait_pred_and_ty =
760
+ real_trait_pred. map_bound ( |inner_trait_pred| ( inner_trait_pred, ty) ) ;
761
+ let obligation = self . mk_trait_obligation_with_new_self_ty (
762
+ obligation. param_env ,
763
+ real_trait_pred_and_ty,
764
+ ) ;
765
+ if obligations
766
+ . iter ( )
767
+ . chain ( [ & obligation] )
768
+ . all ( |obligation| self . predicate_may_hold ( obligation) )
769
+ {
770
+ Some ( steps)
771
+ } else {
772
+ None
773
+ }
774
+ } )
775
+ {
773
776
if steps > 0 {
774
777
// Don't care about `&mut` because `DerefMut` is used less
775
778
// often and user will not expect autoderef happens.
0 commit comments