@@ -32,7 +32,7 @@ use crate::constraints::ConstraintSccIndex;
32
32
use crate :: type_check:: canonical:: fully_perform_op_raw;
33
33
use crate :: type_check:: free_region_relations:: UniversalRegionRelations ;
34
34
use crate :: type_check:: { Locations , MirTypeckRegionConstraints } ;
35
- use crate :: universal_regions:: { RegionClassification , UniversalRegions } ;
35
+ use crate :: universal_regions:: UniversalRegions ;
36
36
use crate :: { BorrowCheckRootCtxt , BorrowckInferCtxt , BorrowckState } ;
37
37
38
38
pub ( crate ) enum DeferredOpaqueTypeError < ' tcx > {
@@ -261,31 +261,30 @@ fn collect_defining_uses<'tcx>(
261
261
262
262
let mut defining_uses = vec ! [ ] ;
263
263
for & ( opaque_type_key, hidden_type) in opaque_types {
264
- // Check whether the arguments are fully universal.
265
- //
266
- // FIXME: We currently treat `Opaque<'a, 'a>` as a defining use and then emit an error
267
- // as it's not fully universal. We should share this code with `check_opaque_type_parameter_valid`
268
- // to only consider actual defining uses as defining.
269
-
270
- let is_non_external_free_region = |r| {
271
- let vid = rcx. representative ( r) ;
272
- matches ! ( rcx. definitions[ vid] . origin, NllRegionVariableOrigin :: FreeRegion )
273
- && !matches ! (
274
- rcx. universal_regions( ) . region_classification( vid) ,
275
- Some ( RegionClassification :: External )
276
- )
277
- } ;
278
- let arg_regions = opaque_type_key
279
- . iter_captured_args ( tcx)
280
- . filter_map ( |( _, arg) | arg. as_region ( ) )
281
- . map ( Region :: as_var)
282
- . map ( |r| if is_non_external_free_region ( r) { Some ( r) } else { None } ) ;
283
- let arg_regions =
284
- iter:: once ( Some ( rcx. universal_regions ( ) . fr_static ) ) . chain ( arg_regions) . collect ( ) ;
285
-
286
- if let Some ( arg_regions) = arg_regions {
287
- defining_uses. push ( DefiningUse { opaque_type_key, arg_regions, hidden_type } ) ;
264
+ let non_nll_opaque_type_key =
265
+ opaque_type_key. fold_captured_lifetime_args ( rcx. infcx . tcx , |r| {
266
+ let vid = rcx. representative ( r. as_var ( ) ) ;
267
+ rcx. definitions [ vid] . external_name . unwrap_or ( r)
268
+ } ) ;
269
+ if let Err ( _) = check_opaque_type_parameter_valid (
270
+ infcx,
271
+ non_nll_opaque_type_key,
272
+ hidden_type. span ,
273
+ DefiningScopeKind :: MirBorrowck ,
274
+ ) {
275
+ debug ! ( ?non_nll_opaque_type_key, "not a defining use" ) ;
276
+ continue ;
288
277
}
278
+
279
+ let arg_regions = iter:: once ( rcx. universal_regions ( ) . fr_static )
280
+ . chain (
281
+ opaque_type_key
282
+ . iter_captured_args ( tcx)
283
+ . filter_map ( |( _, arg) | arg. as_region ( ) )
284
+ . map ( Region :: as_var) ,
285
+ )
286
+ . collect ( ) ;
287
+ defining_uses. push ( DefiningUse { opaque_type_key, arg_regions, hidden_type } ) ;
289
288
}
290
289
291
290
debug ! ( ?defining_uses) ;
0 commit comments