@@ -22,6 +22,7 @@ use rustc_middle::traits::solve::{
2222 CanonicalResponse , Certainty , ExternalConstraintsData , Goal , GoalSource , IsNormalizesToHack ,
2323 QueryResult , Response ,
2424} ;
25+ use rustc_middle:: traits:: Reveal ;
2526use rustc_middle:: ty:: { self , OpaqueTypeKey , Ty , TyCtxt , UniverseIndex } ;
2627use rustc_middle:: ty:: {
2728 CoercePredicate , RegionOutlivesPredicate , SubtypePredicate , TypeOutlivesPredicate ,
@@ -317,18 +318,21 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
317318 } ;
318319
319320 // 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) ;
332336 }
333337 }
334338
0 commit comments