1515//! crate as a kind of pass. This should eventually be factored away.
1616
1717use std:: assert_matches:: assert_matches;
18- use std:: cell:: Cell ;
18+ use std:: cell:: { Cell , RefCell } ;
1919use std:: iter;
2020use std:: ops:: Bound ;
2121
@@ -33,19 +33,21 @@ use rustc_hir::def_id::{DefId, LocalDefId};
3333use rustc_hir:: intravisit:: { InferKind , Visitor , VisitorExt } ;
3434use rustc_hir:: { self as hir, GenericParamKind , HirId , Node , PreciseCapturingArgKind , find_attr} ;
3535use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
36- use rustc_infer:: traits:: { DynCompatibilityViolation , ObligationCause } ;
36+ use rustc_infer:: traits:: { DynCompatibilityViolation , ObligationCause , TraitEngine } ;
3737use rustc_middle:: query:: Providers ;
3838use rustc_middle:: ty:: util:: { Discr , IntTypeExt } ;
3939use rustc_middle:: ty:: {
40- self , AdtKind , Const , FieldPath , FieldPathKind , IsSuggestable , Ty , TyCtxt , TypeVisitableExt ,
41- TypingMode , fold_regions,
40+ self , AdtKind , Const , FieldPath , FieldPathKind , IsSuggestable , ParamEnv , Ty , TyCtxt ,
41+ TypeVisitableExt , TypingMode , fold_regions,
4242} ;
4343use rustc_middle:: { bug, span_bug} ;
4444use rustc_span:: { DUMMY_SP , Ident , Span , Symbol , kw, sym} ;
45+ use rustc_trait_selection:: error_reporting:: InferCtxtErrorExt ;
4546use rustc_trait_selection:: error_reporting:: traits:: suggestions:: NextTypeParamName ;
4647use rustc_trait_selection:: infer:: InferCtxtExt ;
4748use rustc_trait_selection:: traits:: {
48- FulfillmentError , ObligationCtxt , hir_ty_lowering_dyn_compatibility_violations,
49+ FulfillmentError , ObligationCtxt , StructurallyNormalizeExt , TraitEngineExt ,
50+ hir_ty_lowering_dyn_compatibility_violations,
4951} ;
5052use tracing:: { debug, instrument} ;
5153
@@ -368,9 +370,17 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
368370 infcx = Some ( self . tcx ( ) . infer_ctxt ( ) . build ( ty:: TypingMode :: non_body_analysis ( ) ) ) ;
369371 infcx. as_ref ( ) . unwrap ( )
370372 } ) ;
373+ let cause = ObligationCause :: misc ( span, self . item_def_id ) ;
374+ let at = infcx. at ( & cause, ParamEnv :: empty ( ) ) ;
375+ let ty_ch_cx = RefCell :: new ( <dyn TraitEngine < ' _ , FulfillmentError < ' tcx > > >:: new ( & infcx) ) ;
371376
372377 while let Some ( & field) = fields. next ( ) {
373- let container = infcx. shallow_resolve ( current_container) ;
378+ let result =
379+ at. structurally_normalize_ty ( current_container, & mut * * ty_ch_cx. borrow_mut ( ) ) ;
380+ let container = match result {
381+ Ok ( normalized_ty) => normalized_ty,
382+ Err ( errors) => return Err ( infcx. err_ctxt ( ) . report_fulfillment_errors ( errors) ) ,
383+ } ;
374384 match container. kind ( ) {
375385 ty:: Adt ( def, args) if !def. is_enum ( ) => {
376386 let block = self . tcx . local_def_id_to_hir_id ( self . item_def_id ) ;
0 commit comments