@@ -8,7 +8,7 @@ use hir::OpaqueTyOrigin;
8
8
use rustc_data_structures:: fx:: FxIndexMap ;
9
9
use rustc_data_structures:: sync:: Lrc ;
10
10
use rustc_hir as hir;
11
- use rustc_middle:: traits:: { DefiningAnchor , ObligationCause } ;
11
+ use rustc_middle:: traits:: ObligationCause ;
12
12
use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
13
13
use rustc_middle:: ty:: fold:: BottomUpFolder ;
14
14
use rustc_middle:: ty:: GenericArgKind ;
@@ -109,47 +109,44 @@ impl<'tcx> InferCtxt<'tcx> {
109
109
b,
110
110
) ) ;
111
111
}
112
- match self . defining_use_anchor {
113
- DefiningAnchor :: Bind ( _) => {
114
- // Check that this is `impl Trait` type is
115
- // declared by `parent_def_id` -- i.e., one whose
116
- // value we are inferring. At present, this is
117
- // always true during the first phase of
118
- // type-check, but not always true later on during
119
- // NLL. Once we support named opaque types more fully,
120
- // this same scenario will be able to arise during all phases.
121
- //
122
- // Here is an example using type alias `impl Trait`
123
- // that indicates the distinction we are checking for:
124
- //
125
- // ```rust
126
- // mod a {
127
- // pub type Foo = impl Iterator;
128
- // pub fn make_foo() -> Foo { .. }
129
- // }
130
- //
131
- // mod b {
132
- // fn foo() -> a::Foo { a::make_foo() }
133
- // }
134
- // ```
135
- //
136
- // Here, the return type of `foo` references an
137
- // `Opaque` indeed, but not one whose value is
138
- // presently being inferred. You can get into a
139
- // similar situation with closure return types
140
- // today:
141
- //
142
- // ```rust
143
- // fn foo() -> impl Iterator { .. }
144
- // fn bar() {
145
- // let x = || foo(); // returns the Opaque assoc with `foo`
146
- // }
147
- // ```
148
- if self . opaque_type_origin ( def_id) . is_none ( ) {
149
- return None ;
150
- }
151
- }
112
+ // Check that this is `impl Trait` type is
113
+ // declared by `parent_def_id` -- i.e., one whose
114
+ // value we are inferring. At present, this is
115
+ // always true during the first phase of
116
+ // type-check, but not always true later on during
117
+ // NLL. Once we support named opaque types more fully,
118
+ // this same scenario will be able to arise during all phases.
119
+ //
120
+ // Here is an example using type alias `impl Trait`
121
+ // that indicates the distinction we are checking for:
122
+ //
123
+ // ```rust
124
+ // mod a {
125
+ // pub type Foo = impl Iterator;
126
+ // pub fn make_foo() -> Foo { .. }
127
+ // }
128
+ //
129
+ // mod b {
130
+ // fn foo() -> a::Foo { a::make_foo() }
131
+ // }
132
+ // ```
133
+ //
134
+ // Here, the return type of `foo` references an
135
+ // `Opaque` indeed, but not one whose value is
136
+ // presently being inferred. You can get into a
137
+ // similar situation with closure return types
138
+ // today:
139
+ //
140
+ // ```rust
141
+ // fn foo() -> impl Iterator { .. }
142
+ // fn bar() {
143
+ // let x = || foo(); // returns the Opaque assoc with `foo`
144
+ // }
145
+ // ```
146
+ if self . opaque_type_origin ( def_id) . is_none ( ) {
147
+ return None ;
152
148
}
149
+
153
150
if let ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id : b_def_id, .. } ) = * b. kind ( ) {
154
151
// We could accept this, but there are various ways to handle this situation, and we don't
155
152
// want to make a decision on it right now. Likely this case is so super rare anyway, that
@@ -374,13 +371,9 @@ impl<'tcx> InferCtxt<'tcx> {
374
371
/// in its defining scope.
375
372
#[ instrument( skip( self ) , level = "trace" , ret) ]
376
373
pub fn opaque_type_origin ( & self , def_id : LocalDefId ) -> Option < OpaqueTyOrigin > {
377
- let defined_opaque_types = match self . defining_use_anchor {
378
- DefiningAnchor :: Bind ( bind) => bind,
379
- } ;
380
-
381
374
let origin = self . tcx . opaque_type_origin ( def_id) ;
382
375
383
- defined_opaque_types . contains ( & def_id) . then_some ( origin)
376
+ self . defining_opaque_types . contains ( & def_id) . then_some ( origin)
384
377
}
385
378
}
386
379
0 commit comments