@@ -26,6 +26,7 @@ use rustc_middle::mir::tcx::PlaceTy;
2626use rustc_middle:: mir:: visit:: { NonMutatingUseContext , PlaceContext , Visitor } ;
2727use rustc_middle:: mir:: AssertKind ;
2828use rustc_middle:: mir:: * ;
29+ use rustc_middle:: traits:: ObligationCause ;
2930use rustc_middle:: ty:: adjustment:: PointerCast ;
3031use rustc_middle:: ty:: cast:: CastTy ;
3132use rustc_middle:: ty:: subst:: { SubstsRef , UserSubsts } ;
@@ -48,6 +49,7 @@ use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
4849use rustc_mir_dataflow:: move_paths:: MoveData ;
4950use rustc_mir_dataflow:: ResultsCursor ;
5051
52+ use crate :: renumber:: RegionCtxt ;
5153use crate :: session_diagnostics:: MoveUnsized ;
5254use crate :: {
5355 borrow_set:: BorrowSet ,
@@ -183,6 +185,15 @@ pub(crate) fn type_check<'mir, 'tcx>(
183185 & mut borrowck_context,
184186 ) ;
185187
188+ // FIXME(-Ztrait-solver=next): A bit dubious that we're only registering
189+ // predefined opaques in the typeck root.
190+ // FIXME(-Ztrait-solver=next): This is also totally wrong for TAITs, since
191+ // the HIR typeck map defining usages back to their definition params,
192+ // they won't actually match up with the usages in this body...
193+ if infcx. tcx . trait_solver_next ( ) && !infcx. tcx . is_typeck_child ( body. source . def_id ( ) ) {
194+ checker. register_predefined_opaques_in_new_solver ( ) ;
195+ }
196+
186197 let mut verifier = TypeVerifier :: new ( & mut checker, promoted) ;
187198 verifier. visit_body ( & body) ;
188199
@@ -1023,6 +1034,57 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10231034 checker
10241035 }
10251036
1037+ pub ( super ) fn register_predefined_opaques_in_new_solver ( & mut self ) {
1038+ // OK to use the identity substitutions for each opaque type key, since
1039+ // we remap opaques from HIR typeck back to their definition params.
1040+ let opaques: Vec < _ > = self
1041+ . infcx
1042+ . tcx
1043+ . typeck ( self . body . source . def_id ( ) . expect_local ( ) )
1044+ . concrete_opaque_types
1045+ . iter ( )
1046+ . map ( |( & def_id, & hidden_ty) | {
1047+ let substs = ty:: InternalSubsts :: identity_for_item ( self . infcx . tcx , def_id) ;
1048+ ( ty:: OpaqueTypeKey { def_id, substs } , hidden_ty)
1049+ } )
1050+ . collect ( ) ;
1051+
1052+ let renumbered_opaques = self . infcx . tcx . fold_regions ( opaques, |_, _| {
1053+ self . infcx . next_nll_region_var (
1054+ NllRegionVariableOrigin :: Existential { from_forall : false } ,
1055+ || RegionCtxt :: Unknown ,
1056+ )
1057+ } ) ;
1058+
1059+ let param_env = self . param_env ;
1060+ let result = self . fully_perform_op (
1061+ Locations :: All ( self . body . span ) ,
1062+ ConstraintCategory :: OpaqueType ,
1063+ CustomTypeOp :: new (
1064+ |ocx| {
1065+ for ( key, hidden_ty) in renumbered_opaques {
1066+ ocx. register_infer_ok_obligations (
1067+ ocx. infcx . register_hidden_type_in_new_solver (
1068+ key,
1069+ param_env,
1070+ hidden_ty. ty ,
1071+ ) ?,
1072+ ) ;
1073+ }
1074+ Ok ( ( ) )
1075+ } ,
1076+ "register pre-defined opaques" ,
1077+ ) ,
1078+ ) ;
1079+
1080+ if result. is_err ( ) {
1081+ self . infcx . tcx . sess . delay_span_bug (
1082+ self . body . span ,
1083+ "failed re-defining predefined opaques in mir typeck" ,
1084+ ) ;
1085+ }
1086+ }
1087+
10261088 fn body ( & self ) -> & Body < ' tcx > {
10271089 self . body
10281090 }
0 commit comments