@@ -22,6 +22,7 @@ use rustc_middle::traits::solve::{
22
22
CanonicalResponse , Certainty , ExternalConstraintsData , Goal , GoalSource , IsNormalizesToHack ,
23
23
QueryResult , Response ,
24
24
} ;
25
+ use rustc_middle:: traits:: Reveal ;
25
26
use rustc_middle:: ty:: { self , OpaqueTypeKey , Ty , TyCtxt , UniverseIndex } ;
26
27
use rustc_middle:: ty:: {
27
28
CoercePredicate , RegionOutlivesPredicate , SubtypePredicate , TypeOutlivesPredicate ,
@@ -317,18 +318,21 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
317
318
} ;
318
319
319
320
// We do no always define opaque types eagerly to allow non-defining uses in the defining scope.
320
- if let ( DefineOpaqueTypes :: No , ty:: AliasKind :: Opaque ) = ( define_opaque_types, kind) {
321
- if let Some ( def_id) = alias. def_id . as_local ( ) {
322
- if self
323
- . unify_existing_opaque_tys (
324
- param_env,
325
- OpaqueTypeKey { def_id, args : alias. args } ,
326
- self . next_ty_infer ( ) ,
327
- )
328
- . is_empty ( )
329
- {
330
- return Some ( ty) ;
331
- }
321
+ if let DefineOpaqueTypes :: No = define_opaque_types
322
+ && let Reveal :: UserFacing = param_env. reveal ( )
323
+ && let ty:: Opaque = kind
324
+ && let Some ( def_id) = alias. def_id . as_local ( )
325
+ && self . can_define_opaque_ty ( def_id)
326
+ {
327
+ if self
328
+ . unify_existing_opaque_tys (
329
+ param_env,
330
+ OpaqueTypeKey { def_id, args : alias. args } ,
331
+ self . next_ty_infer ( ) ,
332
+ )
333
+ . is_empty ( )
334
+ {
335
+ return Some ( ty) ;
332
336
}
333
337
}
334
338
0 commit comments