@@ -26,6 +26,7 @@ use rustc_middle::mir::tcx::PlaceTy;
26
26
use rustc_middle:: mir:: visit:: { NonMutatingUseContext , PlaceContext , Visitor } ;
27
27
use rustc_middle:: mir:: AssertKind ;
28
28
use rustc_middle:: mir:: * ;
29
+ use rustc_middle:: traits:: ObligationCause ;
29
30
use rustc_middle:: ty:: adjustment:: PointerCast ;
30
31
use rustc_middle:: ty:: cast:: CastTy ;
31
32
use rustc_middle:: ty:: subst:: { SubstsRef , UserSubsts } ;
@@ -48,6 +49,7 @@ use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
48
49
use rustc_mir_dataflow:: move_paths:: MoveData ;
49
50
use rustc_mir_dataflow:: ResultsCursor ;
50
51
52
+ use crate :: renumber:: RegionCtxt ;
51
53
use crate :: session_diagnostics:: MoveUnsized ;
52
54
use crate :: {
53
55
borrow_set:: BorrowSet ,
@@ -183,6 +185,15 @@ pub(crate) fn type_check<'mir, 'tcx>(
183
185
& mut borrowck_context,
184
186
) ;
185
187
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
+
186
197
let mut verifier = TypeVerifier :: new ( & mut checker, promoted) ;
187
198
verifier. visit_body ( & body) ;
188
199
@@ -1023,6 +1034,57 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
1023
1034
checker
1024
1035
}
1025
1036
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
+
1026
1088
fn body ( & self ) -> & Body < ' tcx > {
1027
1089
self . body
1028
1090
}
0 commit comments