@@ -8,7 +8,7 @@ use rustc_infer::infer::outlives::env::RegionBoundPairs;
8
8
use rustc_infer:: infer:: { InferCtxt , NllRegionVariableOrigin , OpaqueTypeStorageEntries } ;
9
9
use rustc_infer:: traits:: ObligationCause ;
10
10
use rustc_macros:: extension;
11
- use rustc_middle:: mir:: { Body , ConcreteOpaqueTypes , ConstraintCategory } ;
11
+ use rustc_middle:: mir:: { Body , ConstraintCategory , DefinitionSiteHiddenTypes } ;
12
12
use rustc_middle:: ty:: {
13
13
self , DefiningScopeKind , EarlyBinder , FallibleTypeFolder , GenericArg , GenericArgsRef ,
14
14
OpaqueHiddenType , OpaqueTypeKey , Region , RegionVid , Ty , TyCtxt , TypeFoldable ,
@@ -129,17 +129,17 @@ fn nll_var_to_universal_region<'tcx>(
129
129
/// Collect all defining uses of opaque types inside of this typeck root. This
130
130
/// expects the hidden type to be mapped to the definition parameters of the opaque
131
131
/// and errors if we end up with distinct hidden types.
132
- fn add_concrete_opaque_type < ' tcx > (
132
+ fn add_hidden_type < ' tcx > (
133
133
tcx : TyCtxt < ' tcx > ,
134
- concrete_opaque_types : & mut ConcreteOpaqueTypes < ' tcx > ,
134
+ hidden_types : & mut DefinitionSiteHiddenTypes < ' tcx > ,
135
135
def_id : LocalDefId ,
136
136
hidden_ty : OpaqueHiddenType < ' tcx > ,
137
137
) {
138
138
// Sometimes two opaque types are the same only after we remap the generic parameters
139
139
// back to the opaque type definition. E.g. we may have `OpaqueType<X, Y>` mapped to
140
140
// `(X, Y)` and `OpaqueType<Y, X>` mapped to `(Y, X)`, and those are the same, but we
141
141
// 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) {
143
143
if prev. ty != hidden_ty. ty {
144
144
let guar = hidden_ty. ty . error_reported ( ) . err ( ) . unwrap_or_else ( || {
145
145
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>(
151
151
// FIXME(oli-obk): collect multiple spans for better diagnostics down the road.
152
152
prev. span = prev. span . substitute_dummy ( hidden_ty. span ) ;
153
153
} else {
154
- concrete_opaque_types . 0 . insert ( def_id, hidden_ty) ;
154
+ hidden_types . 0 . insert ( def_id, hidden_ty) ;
155
155
}
156
156
}
157
157
158
- fn get_concrete_opaque_type < ' tcx > (
159
- concrete_opaque_types : & ConcreteOpaqueTypes < ' tcx > ,
158
+ fn get_hidden_type < ' tcx > (
159
+ hidden_types : & DefinitionSiteHiddenTypes < ' tcx > ,
160
160
def_id : LocalDefId ,
161
161
) -> 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) )
163
163
}
164
164
165
165
#[ derive( Debug ) ]
@@ -173,22 +173,22 @@ struct DefiningUse<'tcx> {
173
173
}
174
174
175
175
/// 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
177
177
/// does not mutate the current borrowck state.
178
178
///
179
179
/// 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
181
181
/// are correct. This is necessary to support non-defining uses of opaques in their
182
182
/// defining scope.
183
183
///
184
184
/// It also means that this whole function is not really soundness critical as we
185
185
/// 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 > (
187
187
infcx : & BorrowckInferCtxt < ' tcx > ,
188
188
universal_region_relations : & Frozen < UniversalRegionRelations < ' tcx > > ,
189
189
constraints : & MirTypeckRegionConstraints < ' tcx > ,
190
190
location_map : Rc < DenseLocationMap > ,
191
- concrete_opaque_types : & mut ConcreteOpaqueTypes < ' tcx > ,
191
+ hidden_types : & mut DefinitionSiteHiddenTypes < ' tcx > ,
192
192
opaque_types : & [ ( OpaqueTypeKey < ' tcx > , OpaqueHiddenType < ' tcx > ) ] ,
193
193
) -> Vec < DeferredOpaqueTypeError < ' tcx > > {
194
194
let mut errors = Vec :: new ( ) ;
@@ -201,20 +201,19 @@ pub(crate) fn compute_concrete_opaque_types<'tcx>(
201
201
// We start by checking each use of an opaque type during type check and
202
202
// check whether the generic arguments of the opaque type are fully
203
203
// 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) ;
206
205
207
206
// We now compute and apply member constraints for all regions in the hidden
208
207
// types of each defining use. This mutates the region values of the `rcx` which
209
208
// is used when mapping the defining uses to the definition site.
210
209
apply_member_constraints ( & mut rcx, & defining_uses) ;
211
210
212
211
// 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
214
213
// 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 (
216
215
& rcx,
217
- concrete_opaque_types ,
216
+ hidden_types ,
218
217
& defining_uses,
219
218
& mut errors,
220
219
) ;
@@ -224,7 +223,7 @@ pub(crate) fn compute_concrete_opaque_types<'tcx>(
224
223
#[ instrument( level = "debug" , skip_all, ret) ]
225
224
fn collect_defining_uses < ' tcx > (
226
225
rcx : & mut RegionCtxt < ' _ , ' tcx > ,
227
- concrete_opaque_types : & mut ConcreteOpaqueTypes < ' tcx > ,
226
+ hidden_types : & mut DefinitionSiteHiddenTypes < ' tcx > ,
228
227
opaque_types : & [ ( OpaqueTypeKey < ' tcx > , OpaqueHiddenType < ' tcx > ) ] ,
229
228
errors : & mut Vec < DeferredOpaqueTypeError < ' tcx > > ,
230
229
) -> Vec < DefiningUse < ' tcx > > {
@@ -244,9 +243,9 @@ fn collect_defining_uses<'tcx>(
244
243
// with `TypingMode::Borrowck`.
245
244
if infcx. tcx . use_typing_mode_borrowck ( ) {
246
245
match err {
247
- NonDefiningUseReason :: Tainted ( guar) => add_concrete_opaque_type (
246
+ NonDefiningUseReason :: Tainted ( guar) => add_hidden_type (
248
247
infcx. tcx ,
249
- concrete_opaque_types ,
248
+ hidden_types ,
250
249
opaque_type_key. def_id ,
251
250
OpaqueHiddenType :: new_error ( infcx. tcx , guar) ,
252
251
) ,
@@ -277,9 +276,9 @@ fn collect_defining_uses<'tcx>(
277
276
defining_uses
278
277
}
279
278
280
- fn compute_concrete_types_from_defining_uses < ' tcx > (
279
+ fn compute_definition_site_hidden_types_from_defining_uses < ' tcx > (
281
280
rcx : & RegionCtxt < ' _ , ' tcx > ,
282
- concrete_opaque_types : & mut ConcreteOpaqueTypes < ' tcx > ,
281
+ hidden_types : & mut DefinitionSiteHiddenTypes < ' tcx > ,
283
282
defining_uses : & [ DefiningUse < ' tcx > ] ,
284
283
errors : & mut Vec < DeferredOpaqueTypeError < ' tcx > > ,
285
284
) {
@@ -358,9 +357,9 @@ fn compute_concrete_types_from_defining_uses<'tcx>(
358
357
} ,
359
358
) ) ;
360
359
}
361
- add_concrete_opaque_type (
360
+ add_hidden_type (
362
361
tcx,
363
- concrete_opaque_types ,
362
+ hidden_types ,
364
363
opaque_type_key. def_id ,
365
364
OpaqueHiddenType { span : hidden_type. span , ty } ,
366
365
) ;
@@ -489,20 +488,20 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for ToArgRegionsFolder<'_, 'tcx> {
489
488
///
490
489
/// It does this by equating the hidden type of each use with the instantiated final
491
490
/// 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 > (
493
492
infcx : & BorrowckInferCtxt < ' tcx > ,
494
493
body : & Body < ' tcx > ,
495
494
universal_regions : & UniversalRegions < ' tcx > ,
496
495
region_bound_pairs : & RegionBoundPairs < ' tcx > ,
497
496
known_type_outlives_obligations : & [ ty:: PolyTypeOutlivesPredicate < ' tcx > ] ,
498
497
constraints : & mut MirTypeckRegionConstraints < ' tcx > ,
499
- concrete_opaque_types : & mut ConcreteOpaqueTypes < ' tcx > ,
498
+ hidden_types : & mut DefinitionSiteHiddenTypes < ' tcx > ,
500
499
opaque_types : & [ ( OpaqueTypeKey < ' tcx > , OpaqueHiddenType < ' tcx > ) ] ,
501
500
) -> Vec < DeferredOpaqueTypeError < ' tcx > > {
502
501
let tcx = infcx. tcx ;
503
502
let mut errors = Vec :: new ( ) ;
504
503
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 {
506
505
if !tcx. use_typing_mode_borrowck ( ) {
507
506
if let ty:: Alias ( ty:: Opaque , alias_ty) = hidden_type. ty . kind ( )
508
507
&& alias_ty. def_id == key. def_id . to_def_id ( )
@@ -521,12 +520,7 @@ pub(crate) fn apply_computed_concrete_opaque_types<'tcx>(
521
520
hidden_type. span ,
522
521
"non-defining use in the defining scope with no defining uses" ,
523
522
) ;
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) ) ;
530
524
continue ;
531
525
} ;
532
526
@@ -566,18 +560,13 @@ pub(crate) fn apply_computed_concrete_opaque_types<'tcx>(
566
560
"equating opaque types" ,
567
561
) ,
568
562
) {
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) ) ;
575
564
}
576
565
}
577
566
errors
578
567
}
579
568
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.
581
570
/// We do not check these new uses so this could be unsound.
582
571
///
583
572
/// 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> {
682
671
///
683
672
/// (*) C1 and C2 were introduced in the comments on
684
673
/// `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`
692
674
#[ instrument( level = "debug" , skip( self ) ) ]
693
675
fn infer_opaque_definition_from_instantiation (
694
676
& self ,
0 commit comments