@@ -706,36 +706,29 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
706
706
}
707
707
708
708
let param_env = obligation. param_env ;
709
- let trait_ref = poly_trait_ref. skip_binder ( ) ;
710
-
711
- let found_ty = trait_ref. self_ty ( ) ;
712
- let found_ty_str = found_ty. to_string ( ) ;
713
- let imm_borrowed_found_ty = self . tcx . mk_imm_ref ( self . tcx . lifetimes . re_static , found_ty) ;
714
- let imm_substs = self . tcx . mk_substs_trait ( imm_borrowed_found_ty, & [ ] ) ;
715
- let mut_borrowed_found_ty = self . tcx . mk_mut_ref ( self . tcx . lifetimes . re_static , found_ty) ;
716
- let mut_substs = self . tcx . mk_substs_trait ( mut_borrowed_found_ty, & [ ] ) ;
717
709
718
710
// Try to apply the original trait binding obligation by borrowing.
719
- let mut try_borrowing = |new_imm_trait_ref : ty:: Binder < ' tcx , ty:: TraitRef < ' tcx > > ,
720
- new_mut_trait_ref : ty:: Binder < ' tcx , ty:: TraitRef < ' tcx > > ,
721
- expected_trait_ref : ty:: Binder < ' tcx , ty:: TraitRef < ' tcx > > ,
711
+ let mut try_borrowing = |old_ref : ty:: Binder < ' tcx , ty:: TraitRef < ' tcx > > ,
722
712
blacklist : & [ DefId ] |
723
713
-> bool {
724
- if blacklist. contains ( & expected_trait_ref . def_id ( ) ) {
714
+ if blacklist. contains ( & old_ref . def_id ( ) ) {
725
715
return false ;
726
716
}
727
717
728
- let imm_result = self . predicate_must_hold_modulo_regions ( & Obligation :: new (
729
- ObligationCause :: dummy ( ) ,
730
- param_env,
731
- new_imm_trait_ref. without_const ( ) . to_predicate ( self . tcx ) ,
732
- ) ) ;
733
-
734
- let mut_result = self . predicate_must_hold_modulo_regions ( & Obligation :: new (
735
- ObligationCause :: dummy ( ) ,
736
- param_env,
737
- new_mut_trait_ref. without_const ( ) . to_predicate ( self . tcx ) ,
738
- ) ) ;
718
+ let orig_ty = old_ref. self_ty ( ) . skip_binder ( ) ;
719
+ let mk_result = |new_ty| {
720
+ let new_ref = old_ref. rebind ( ty:: TraitRef :: new (
721
+ old_ref. def_id ( ) ,
722
+ self . tcx . mk_substs_trait ( new_ty, & old_ref. skip_binder ( ) . substs [ 1 ..] ) ,
723
+ ) ) ;
724
+ self . predicate_must_hold_modulo_regions ( & Obligation :: new (
725
+ ObligationCause :: dummy ( ) ,
726
+ param_env,
727
+ new_ref. without_const ( ) . to_predicate ( self . tcx ) ,
728
+ ) )
729
+ } ;
730
+ let imm_result = mk_result ( self . tcx . mk_imm_ref ( self . tcx . lifetimes . re_static , orig_ty) ) ;
731
+ let mut_result = mk_result ( self . tcx . mk_mut_ref ( self . tcx . lifetimes . re_static , orig_ty) ) ;
739
732
740
733
if imm_result || mut_result {
741
734
if let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( span) {
@@ -747,8 +740,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
747
740
748
741
let msg = format ! (
749
742
"the trait bound `{}: {}` is not satisfied" ,
750
- found_ty_str ,
751
- expected_trait_ref . print_only_trait_path( ) ,
743
+ orig_ty . to_string ( ) ,
744
+ old_ref . print_only_trait_path( ) ,
752
745
) ;
753
746
if has_custom_message {
754
747
err. note ( & msg) ;
@@ -764,7 +757,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
764
757
span,
765
758
& format ! (
766
759
"expected an implementor of trait `{}`" ,
767
- expected_trait_ref . print_only_trait_path( ) ,
760
+ old_ref . print_only_trait_path( ) ,
768
761
) ,
769
762
) ;
770
763
@@ -807,21 +800,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
807
800
} ;
808
801
809
802
if let ObligationCauseCode :: ImplDerivedObligation ( obligation) = & * code {
810
- let expected_trait_ref = obligation. parent_trait_ref ;
811
- let new_imm_trait_ref = poly_trait_ref
812
- . rebind ( ty:: TraitRef :: new ( obligation. parent_trait_ref . def_id ( ) , imm_substs) ) ;
813
- let new_mut_trait_ref = poly_trait_ref
814
- . rebind ( ty:: TraitRef :: new ( obligation. parent_trait_ref . def_id ( ) , mut_substs) ) ;
815
- return try_borrowing ( new_imm_trait_ref, new_mut_trait_ref, expected_trait_ref, & [ ] ) ;
803
+ try_borrowing ( obligation. parent_trait_ref , & [ ] )
816
804
} else if let ObligationCauseCode :: BindingObligation ( _, _)
817
805
| ObligationCauseCode :: ItemObligation ( _) = & * code
818
806
{
819
- return try_borrowing (
820
- poly_trait_ref. rebind ( ty:: TraitRef :: new ( trait_ref. def_id , imm_substs) ) ,
821
- poly_trait_ref. rebind ( ty:: TraitRef :: new ( trait_ref. def_id , mut_substs) ) ,
822
- * poly_trait_ref,
823
- & never_suggest_borrow[ ..] ,
824
- ) ;
807
+ try_borrowing ( * poly_trait_ref, & never_suggest_borrow[ ..] )
825
808
} else {
826
809
false
827
810
}
0 commit comments