@@ -4,7 +4,6 @@ use crate::errors::OpaqueHiddenTypeDiag;
4
4
use crate :: infer:: { InferCtxt , InferOk } ;
5
5
use crate :: traits:: { self , PredicateObligation } ;
6
6
use hir:: def_id:: { DefId , LocalDefId } ;
7
- use hir:: OpaqueTyOrigin ;
8
7
use rustc_data_structures:: fx:: FxIndexMap ;
9
8
use rustc_data_structures:: sync:: Lrc ;
10
9
use rustc_hir as hir;
@@ -54,16 +53,13 @@ impl<'tcx> InferCtxt<'tcx> {
54
53
}
55
54
56
55
let mut obligations = vec ! [ ] ;
57
- let replace_opaque_type = |def_id : DefId | {
58
- def_id. as_local ( ) . is_some_and ( |def_id| self . opaque_type_origin ( def_id) . is_some ( ) )
59
- } ;
60
56
let value = value. fold_with ( & mut BottomUpFolder {
61
57
tcx : self . tcx ,
62
58
lt_op : |lt| lt,
63
59
ct_op : |ct| ct,
64
60
ty_op : |ty| match * ty. kind ( ) {
65
61
ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, .. } )
66
- if replace_opaque_type ( def_id) && !ty. has_escaping_bound_vars ( ) =>
62
+ if self . can_define_opaque_ty ( def_id) && !ty. has_escaping_bound_vars ( ) =>
67
63
{
68
64
let def_span = self . tcx . def_span ( def_id) ;
69
65
let span = if span. contains ( def_span) { def_span } else { span } ;
@@ -140,7 +136,7 @@ impl<'tcx> InferCtxt<'tcx> {
140
136
// let x = || foo(); // returns the Opaque assoc with `foo`
141
137
// }
142
138
// ```
143
- if self . opaque_type_origin ( def_id) . is_none ( ) {
139
+ if ! self . can_define_opaque_ty ( def_id) {
144
140
return None ;
145
141
}
146
142
@@ -150,8 +146,8 @@ impl<'tcx> InferCtxt<'tcx> {
150
146
// no one encounters it in practice.
151
147
// It does occur however in `fn fut() -> impl Future<Output = i32> { async { 42 } }`,
152
148
// where it is of no concern, so we only check for TAITs.
153
- if let Some ( OpaqueTyOrigin :: TyAlias { .. } ) =
154
- b_def_id . as_local ( ) . and_then ( |b_def_id| self . opaque_type_origin ( b_def_id) )
149
+ if self . can_define_opaque_ty ( b_def_id )
150
+ && self . tcx . is_type_alias_impl_trait ( b_def_id)
155
151
{
156
152
self . tcx . dcx ( ) . emit_err ( OpaqueHiddenTypeDiag {
157
153
span : cause. span ,
@@ -363,15 +359,6 @@ impl<'tcx> InferCtxt<'tcx> {
363
359
op : |r| self . member_constraint ( opaque_type_key, span, concrete_ty, r, & choice_regions) ,
364
360
} ) ;
365
361
}
366
-
367
- /// Returns the origin of the opaque type `def_id` if we're currently
368
- /// in its defining scope.
369
- #[ instrument( skip( self ) , level = "trace" , ret) ]
370
- pub fn opaque_type_origin ( & self , def_id : LocalDefId ) -> Option < OpaqueTyOrigin > {
371
- let origin = self . tcx . opaque_type_origin ( def_id) ;
372
-
373
- self . defining_opaque_types . contains ( & def_id) . then_some ( origin)
374
- }
375
362
}
376
363
377
364
/// Visitor that requires that (almost) all regions in the type visited outlive
0 commit comments