8
8
use hir:: LangItem ;
9
9
use rustc_errors:: DelayDm ;
10
10
use rustc_hir as hir;
11
- use rustc_hir:: def_id:: DefId ;
12
11
use rustc_infer:: traits:: ObligationCause ;
13
12
use rustc_infer:: traits:: { Obligation , SelectionError , TraitObligation } ;
14
13
use rustc_lint_defs:: builtin:: DEREF_INTO_DYN_SUPERTRAIT ;
@@ -707,7 +706,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
707
706
ty : Ty < ' tcx > ,
708
707
param_env : ty:: ParamEnv < ' tcx > ,
709
708
cause : & ObligationCause < ' tcx > ,
710
- ) -> Option < ( Ty < ' tcx > , DefId ) > {
709
+ ) -> Option < ty :: PolyExistentialTraitRef < ' tcx > > {
711
710
let tcx = self . tcx ( ) ;
712
711
if tcx. features ( ) . trait_upcasting {
713
712
return None ;
@@ -729,27 +728,25 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
729
728
return None ;
730
729
}
731
730
732
- let ty = traits:: normalize_projection_type (
733
- self ,
734
- param_env,
735
- ty:: ProjectionTy {
736
- item_def_id : tcx. lang_items ( ) . deref_target ( ) ?,
737
- substs : trait_ref. substs ,
738
- } ,
739
- cause. clone ( ) ,
740
- 0 ,
741
- // We're *intentionally* throwing these away,
742
- // since we don't actually use them.
743
- & mut vec ! [ ] ,
744
- )
745
- . ty ( )
746
- . unwrap ( ) ;
747
-
748
- if let ty:: Dynamic ( data, ..) = ty. kind ( ) {
749
- Some ( ( ty, data. principal_def_id ( ) ?) )
750
- } else {
751
- None
752
- }
731
+ self . infcx . probe ( |_| {
732
+ let ty = traits:: normalize_projection_type (
733
+ self ,
734
+ param_env,
735
+ ty:: ProjectionTy {
736
+ item_def_id : tcx. lang_items ( ) . deref_target ( ) ?,
737
+ substs : trait_ref. substs ,
738
+ } ,
739
+ cause. clone ( ) ,
740
+ 0 ,
741
+ // We're *intentionally* throwing these away,
742
+ // since we don't actually use them.
743
+ & mut vec ! [ ] ,
744
+ )
745
+ . ty ( )
746
+ . unwrap ( ) ;
747
+
748
+ if let ty:: Dynamic ( data, ..) = ty. kind ( ) { data. principal ( ) } else { None }
749
+ } )
753
750
}
754
751
755
752
/// Searches for unsizing that might apply to `obligation`.
@@ -811,21 +808,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
811
808
let principal_a = data_a. principal ( ) . unwrap ( ) ;
812
809
let target_trait_did = principal_def_id_b. unwrap ( ) ;
813
810
let source_trait_ref = principal_a. with_self_ty ( self . tcx ( ) , source) ;
814
- if let Some ( ( deref_output_ty, deref_output_trait_did) ) = self
815
- . need_migrate_deref_output_trait_object (
816
- source,
817
- obligation. param_env ,
818
- & obligation. cause ,
819
- )
820
- {
821
- if deref_output_trait_did == target_trait_did {
811
+ if let Some ( deref_trait_ref) = self . need_migrate_deref_output_trait_object (
812
+ source,
813
+ obligation. param_env ,
814
+ & obligation. cause ,
815
+ ) {
816
+ if deref_trait_ref. def_id ( ) == target_trait_did {
822
817
self . tcx ( ) . struct_span_lint_hir (
823
818
DEREF_INTO_DYN_SUPERTRAIT ,
824
819
obligation. cause . body_id ,
825
820
obligation. cause . span ,
826
821
DelayDm ( || format ! (
827
822
"`{}` implements `Deref` with supertrait `{}` as output" ,
828
- source, deref_output_ty
823
+ source, deref_trait_ref
829
824
) ) ,
830
825
|lint| lint,
831
826
) ;
0 commit comments