@@ -11,7 +11,7 @@ use rustc_index::Idx;
1111use rustc_middle:: mir:: * ;
1212use rustc_middle:: ty:: adjustment:: PointerCoercion ;
1313use rustc_middle:: ty:: util:: IntTypeExt ;
14- use rustc_middle:: ty:: { self , GenericArg , GenericArgsRef , Ty , TyCtxt , Unnormalized } ;
14+ use rustc_middle:: ty:: { self , GenericArg , GenericArgsRef , Ty , TyCtxt } ;
1515use rustc_middle:: { span_bug, traits} ;
1616use rustc_span:: { DUMMY_SP , Spanned , dummy_spanned} ;
1717use tracing:: { debug, instrument} ;
@@ -371,7 +371,9 @@ where
371371 bug ! ( ) ;
372372 } ;
373373 let obj_ptr_ty = Ty :: new_mut_ptr ( tcx, drop_ty) ;
374- let unwrap_ty = adt_def. non_enum_variant ( ) . fields [ FieldIdx :: ZERO ] . ty ( tcx, adt_args) ;
374+ let unwrap_ty = adt_def. non_enum_variant ( ) . fields [ FieldIdx :: ZERO ]
375+ . ty ( tcx, adt_args)
376+ . skip_norm_wip ( ) ;
375377 let obj_ref_place = Place :: from ( self . new_temp ( unwrap_ty) ) ;
376378 call_statements. push ( self . assign (
377379 obj_ref_place,
@@ -566,19 +568,11 @@ where
566568 }
567569 }
568570 let field_ty = field. ty ( tcx, args) ;
569- let field_ty = match tcx. try_normalize_erasing_regions (
570- self . elaborator . typing_env ( ) ,
571- Unnormalized :: new_wip ( field_ty) ,
572- ) {
573- Ok ( t) => t,
574- Err ( _) => Ty :: new_error (
575- self . tcx ( ) ,
576- self . tcx ( ) . dcx ( ) . span_delayed_bug (
577- self . elaborator . body ( ) . span ,
578- "Error normalizing in drop elaboration." ,
579- ) ,
580- ) ,
581- } ;
571+ // We silently leave an unnormalized type here to support polymorphic drop
572+ // elaboration for users of rustc internal APIs
573+ let field_ty = tcx
574+ . try_normalize_erasing_regions ( self . elaborator . typing_env ( ) , field_ty)
575+ . unwrap_or ( field_ty. skip_norm_wip ( ) ) ;
582576
583577 ( tcx. mk_place_field ( base_place, field_idx, field_ty) , subpath)
584578 } )
@@ -781,9 +775,13 @@ where
781775 ) -> BasicBlock {
782776 // drop glue is sent straight to codegen
783777 // box cannot be directly dereferenced
784- let unique_ty = adt. non_enum_variant ( ) . fields [ FieldIdx :: ZERO ] . ty ( self . tcx ( ) , args) ;
778+ let unique_ty = adt. non_enum_variant ( ) . fields [ FieldIdx :: ZERO ]
779+ . ty ( self . tcx ( ) , args)
780+ . skip_norm_wip ( ) ;
785781 let unique_variant = unique_ty. ty_adt_def ( ) . unwrap ( ) . non_enum_variant ( ) ;
786- let nonnull_ty = unique_variant. fields [ FieldIdx :: ZERO ] . ty ( self . tcx ( ) , args) ;
782+ let nonnull_ty = unique_variant. fields [ FieldIdx :: ZERO ]
783+ . ty ( self . tcx ( ) , args)
784+ . skip_norm_wip ( ) ;
787785 let ptr_ty = Ty :: new_imm_ptr ( self . tcx ( ) , args[ 0 ] . expect_ty ( ) ) ;
788786
789787 let unique_place = self
@@ -954,10 +952,12 @@ where
954952 have_otherwise = true ;
955953
956954 let typing_env = self . elaborator . typing_env ( ) ;
957- let have_field_with_drop_glue = variant
958- . fields
959- . iter ( )
960- . any ( |field| field. ty ( tcx, args) . needs_drop ( tcx, typing_env) ) ;
955+ let have_field_with_drop_glue = variant. fields . iter ( ) . any ( |field| {
956+ field
957+ . ty ( tcx, args)
958+ . skip_norm_wip ( )
959+ . needs_drop ( tcx, typing_env)
960+ } ) ;
961961 if have_field_with_drop_glue {
962962 have_otherwise_with_drop_glue = true ;
963963 }
0 commit comments