@@ -8,7 +8,7 @@ use rustc_infer::infer::outlives::env::RegionBoundPairs;
88use rustc_infer:: infer:: { InferCtxt , NllRegionVariableOrigin , OpaqueTypeStorageEntries } ;
99use rustc_infer:: traits:: ObligationCause ;
1010use rustc_macros:: extension;
11- use rustc_middle:: mir:: { Body , ConcreteOpaqueTypes , ConstraintCategory } ;
11+ use rustc_middle:: mir:: { Body , ConstraintCategory , DefinitionSiteHiddenTypes } ;
1212use rustc_middle:: ty:: {
1313 self , DefiningScopeKind , EarlyBinder , FallibleTypeFolder , GenericArg , GenericArgsRef ,
1414 OpaqueHiddenType , OpaqueTypeKey , Region , RegionVid , Ty , TyCtxt , TypeFoldable ,
@@ -129,17 +129,17 @@ fn nll_var_to_universal_region<'tcx>(
129129/// Collect all defining uses of opaque types inside of this typeck root. This
130130/// expects the hidden type to be mapped to the definition parameters of the opaque
131131/// and errors if we end up with distinct hidden types.
132- fn add_concrete_opaque_type < ' tcx > (
132+ fn add_hidden_type < ' tcx > (
133133 tcx : TyCtxt < ' tcx > ,
134- concrete_opaque_types : & mut ConcreteOpaqueTypes < ' tcx > ,
134+ hidden_types : & mut DefinitionSiteHiddenTypes < ' tcx > ,
135135 def_id : LocalDefId ,
136136 hidden_ty : OpaqueHiddenType < ' tcx > ,
137137) {
138138 // Sometimes two opaque types are the same only after we remap the generic parameters
139139 // back to the opaque type definition. E.g. we may have `OpaqueType<X, Y>` mapped to
140140 // `(X, Y)` and `OpaqueType<Y, X>` mapped to `(Y, X)`, and those are the same, but we
141141 // only know that once we convert the generic parameters to those of the opaque type.
142- if let Some ( prev) = concrete_opaque_types . 0 . get_mut ( & def_id) {
142+ if let Some ( prev) = hidden_types . 0 . get_mut ( & def_id) {
143143 if prev. ty != hidden_ty. ty {
144144 let guar = hidden_ty. ty . error_reported ( ) . err ( ) . unwrap_or_else ( || {
145145 let ( Ok ( e) | Err ( e) ) = prev. build_mismatch_error ( & hidden_ty, tcx) . map ( |d| d. emit ( ) ) ;
@@ -151,15 +151,15 @@ fn add_concrete_opaque_type<'tcx>(
151151 // FIXME(oli-obk): collect multiple spans for better diagnostics down the road.
152152 prev. span = prev. span . substitute_dummy ( hidden_ty. span ) ;
153153 } else {
154- concrete_opaque_types . 0 . insert ( def_id, hidden_ty) ;
154+ hidden_types . 0 . insert ( def_id, hidden_ty) ;
155155 }
156156}
157157
158- fn get_concrete_opaque_type < ' tcx > (
159- concrete_opaque_types : & ConcreteOpaqueTypes < ' tcx > ,
158+ fn get_hidden_type < ' tcx > (
159+ hidden_types : & DefinitionSiteHiddenTypes < ' tcx > ,
160160 def_id : LocalDefId ,
161161) -> Option < EarlyBinder < ' tcx , OpaqueHiddenType < ' tcx > > > {
162- concrete_opaque_types . 0 . get ( & def_id) . map ( |ty| EarlyBinder :: bind ( * ty) )
162+ hidden_types . 0 . get ( & def_id) . map ( |ty| EarlyBinder :: bind ( * ty) )
163163}
164164
165165#[ derive( Debug ) ]
@@ -173,22 +173,22 @@ struct DefiningUse<'tcx> {
173173}
174174
175175/// This computes the actual hidden types of the opaque types and maps them to their
176- /// definition sites. Outside of registering the computed concrete types this function
176+ /// definition sites. Outside of registering the computed hidden types this function
177177/// does not mutate the current borrowck state.
178178///
179179/// While it may fail to infer the hidden type and return errors, we always apply
180- /// the computed concrete hidden type to all opaque type uses to check whether they
180+ /// the computed hidden type to all opaque type uses to check whether they
181181/// are correct. This is necessary to support non-defining uses of opaques in their
182182/// defining scope.
183183///
184184/// It also means that this whole function is not really soundness critical as we
185185/// recheck all uses of the opaques regardless.
186- pub ( crate ) fn compute_concrete_opaque_types < ' tcx > (
186+ pub ( crate ) fn compute_definition_site_hidden_types < ' tcx > (
187187 infcx : & BorrowckInferCtxt < ' tcx > ,
188188 universal_region_relations : & Frozen < UniversalRegionRelations < ' tcx > > ,
189189 constraints : & MirTypeckRegionConstraints < ' tcx > ,
190190 location_map : Rc < DenseLocationMap > ,
191- concrete_opaque_types : & mut ConcreteOpaqueTypes < ' tcx > ,
191+ hidden_types : & mut DefinitionSiteHiddenTypes < ' tcx > ,
192192 opaque_types : & [ ( OpaqueTypeKey < ' tcx > , OpaqueHiddenType < ' tcx > ) ] ,
193193) -> Vec < DeferredOpaqueTypeError < ' tcx > > {
194194 let mut errors = Vec :: new ( ) ;
@@ -201,20 +201,19 @@ pub(crate) fn compute_concrete_opaque_types<'tcx>(
201201 // We start by checking each use of an opaque type during type check and
202202 // check whether the generic arguments of the opaque type are fully
203203 // universal, if so, it's a defining use.
204- let defining_uses =
205- collect_defining_uses ( & mut rcx, concrete_opaque_types, opaque_types, & mut errors) ;
204+ let defining_uses = collect_defining_uses ( & mut rcx, hidden_types, opaque_types, & mut errors) ;
206205
207206 // We now compute and apply member constraints for all regions in the hidden
208207 // types of each defining use. This mutates the region values of the `rcx` which
209208 // is used when mapping the defining uses to the definition site.
210209 apply_member_constraints ( & mut rcx, & defining_uses) ;
211210
212211 // After applying member constraints, we now check whether all member regions ended
213- // up equal to one of their choice regions and compute the actual concrete type of
212+ // up equal to one of their choice regions and compute the actual hidden type of
214213 // the opaque type definition. This is stored in the `root_cx`.
215- compute_concrete_types_from_defining_uses (
214+ compute_definition_site_hidden_types_from_defining_uses (
216215 & rcx,
217- concrete_opaque_types ,
216+ hidden_types ,
218217 & defining_uses,
219218 & mut errors,
220219 ) ;
@@ -224,7 +223,7 @@ pub(crate) fn compute_concrete_opaque_types<'tcx>(
224223#[ instrument( level = "debug" , skip_all, ret) ]
225224fn collect_defining_uses < ' tcx > (
226225 rcx : & mut RegionCtxt < ' _ , ' tcx > ,
227- concrete_opaque_types : & mut ConcreteOpaqueTypes < ' tcx > ,
226+ hidden_types : & mut DefinitionSiteHiddenTypes < ' tcx > ,
228227 opaque_types : & [ ( OpaqueTypeKey < ' tcx > , OpaqueHiddenType < ' tcx > ) ] ,
229228 errors : & mut Vec < DeferredOpaqueTypeError < ' tcx > > ,
230229) -> Vec < DefiningUse < ' tcx > > {
@@ -244,9 +243,9 @@ fn collect_defining_uses<'tcx>(
244243 // with `TypingMode::Borrowck`.
245244 if infcx. tcx . use_typing_mode_borrowck ( ) {
246245 match err {
247- NonDefiningUseReason :: Tainted ( guar) => add_concrete_opaque_type (
246+ NonDefiningUseReason :: Tainted ( guar) => add_hidden_type (
248247 infcx. tcx ,
249- concrete_opaque_types ,
248+ hidden_types ,
250249 opaque_type_key. def_id ,
251250 OpaqueHiddenType :: new_error ( infcx. tcx , guar) ,
252251 ) ,
@@ -277,9 +276,9 @@ fn collect_defining_uses<'tcx>(
277276 defining_uses
278277}
279278
280- fn compute_concrete_types_from_defining_uses < ' tcx > (
279+ fn compute_definition_site_hidden_types_from_defining_uses < ' tcx > (
281280 rcx : & RegionCtxt < ' _ , ' tcx > ,
282- concrete_opaque_types : & mut ConcreteOpaqueTypes < ' tcx > ,
281+ hidden_types : & mut DefinitionSiteHiddenTypes < ' tcx > ,
283282 defining_uses : & [ DefiningUse < ' tcx > ] ,
284283 errors : & mut Vec < DeferredOpaqueTypeError < ' tcx > > ,
285284) {
@@ -358,9 +357,9 @@ fn compute_concrete_types_from_defining_uses<'tcx>(
358357 } ,
359358 ) ) ;
360359 }
361- add_concrete_opaque_type (
360+ add_hidden_type (
362361 tcx,
363- concrete_opaque_types ,
362+ hidden_types ,
364363 opaque_type_key. def_id ,
365364 OpaqueHiddenType { span : hidden_type. span , ty } ,
366365 ) ;
@@ -489,20 +488,20 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for ToArgRegionsFolder<'_, 'tcx> {
489488///
490489/// It does this by equating the hidden type of each use with the instantiated final
491490/// hidden type of the opaque.
492- pub ( crate ) fn apply_computed_concrete_opaque_types < ' tcx > (
491+ pub ( crate ) fn apply_definition_site_hidden_types < ' tcx > (
493492 infcx : & BorrowckInferCtxt < ' tcx > ,
494493 body : & Body < ' tcx > ,
495494 universal_regions : & UniversalRegions < ' tcx > ,
496495 region_bound_pairs : & RegionBoundPairs < ' tcx > ,
497496 known_type_outlives_obligations : & [ ty:: PolyTypeOutlivesPredicate < ' tcx > ] ,
498497 constraints : & mut MirTypeckRegionConstraints < ' tcx > ,
499- concrete_opaque_types : & mut ConcreteOpaqueTypes < ' tcx > ,
498+ hidden_types : & mut DefinitionSiteHiddenTypes < ' tcx > ,
500499 opaque_types : & [ ( OpaqueTypeKey < ' tcx > , OpaqueHiddenType < ' tcx > ) ] ,
501500) -> Vec < DeferredOpaqueTypeError < ' tcx > > {
502501 let tcx = infcx. tcx ;
503502 let mut errors = Vec :: new ( ) ;
504503 for & ( key, hidden_type) in opaque_types {
505- let Some ( expected) = get_concrete_opaque_type ( concrete_opaque_types , key. def_id ) else {
504+ let Some ( expected) = get_hidden_type ( hidden_types , key. def_id ) else {
506505 if !tcx. use_typing_mode_borrowck ( ) {
507506 if let ty:: Alias ( ty:: Opaque , alias_ty) = hidden_type. ty . kind ( )
508507 && alias_ty. def_id == key. def_id . to_def_id ( )
@@ -521,12 +520,7 @@ pub(crate) fn apply_computed_concrete_opaque_types<'tcx>(
521520 hidden_type. span ,
522521 "non-defining use in the defining scope with no defining uses" ,
523522 ) ;
524- add_concrete_opaque_type (
525- tcx,
526- concrete_opaque_types,
527- key. def_id ,
528- OpaqueHiddenType :: new_error ( tcx, guar) ,
529- ) ;
523+ add_hidden_type ( tcx, hidden_types, key. def_id , OpaqueHiddenType :: new_error ( tcx, guar) ) ;
530524 continue ;
531525 } ;
532526
@@ -566,18 +560,13 @@ pub(crate) fn apply_computed_concrete_opaque_types<'tcx>(
566560 "equating opaque types" ,
567561 ) ,
568562 ) {
569- add_concrete_opaque_type (
570- tcx,
571- concrete_opaque_types,
572- key. def_id ,
573- OpaqueHiddenType :: new_error ( tcx, guar) ,
574- ) ;
563+ add_hidden_type ( tcx, hidden_types, key. def_id , OpaqueHiddenType :: new_error ( tcx, guar) ) ;
575564 }
576565 }
577566 errors
578567}
579568
580- /// In theory `apply_concrete_opaque_types ` could introduce new uses of opaque types.
569+ /// In theory `apply_definition_site_hidden_types ` could introduce new uses of opaque types.
581570/// We do not check these new uses so this could be unsound.
582571///
583572/// We detect any new uses and simply delay a bug if they occur. If this results in
@@ -682,13 +671,6 @@ impl<'tcx> InferCtxt<'tcx> {
682671 ///
683672 /// (*) C1 and C2 were introduced in the comments on
684673 /// `register_member_constraints`. Read that comment for more context.
685- ///
686- /// # Parameters
687- ///
688- /// - `def_id`, the `impl Trait` type
689- /// - `args`, the args used to instantiate this opaque type
690- /// - `instantiated_ty`, the inferred type C1 -- fully resolved, lifted version of
691- /// `opaque_defn.concrete_ty`
692674 #[ instrument( level = "debug" , skip( self ) ) ]
693675 fn infer_opaque_definition_from_instantiation (
694676 & self ,
0 commit comments