@@ -8,7 +8,7 @@ use hir::OpaqueTyOrigin;
88use rustc_data_structures:: fx:: FxIndexMap ;
99use rustc_data_structures:: sync:: Lrc ;
1010use rustc_hir as hir;
11- use rustc_middle:: traits:: { DefiningAnchor , ObligationCause } ;
11+ use rustc_middle:: traits:: ObligationCause ;
1212use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
1313use rustc_middle:: ty:: fold:: BottomUpFolder ;
1414use rustc_middle:: ty:: GenericArgKind ;
@@ -109,47 +109,44 @@ impl<'tcx> InferCtxt<'tcx> {
109109 b,
110110 ) ) ;
111111 }
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 ;
152148 }
149+
153150 if let ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id : b_def_id, .. } ) = * b. kind ( ) {
154151 // We could accept this, but there are various ways to handle this situation, and we don't
155152 // 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> {
374371 /// in its defining scope.
375372 #[ instrument( skip( self ) , level = "trace" , ret) ]
376373 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-
381374 let origin = self . tcx . opaque_type_origin ( def_id) ;
382375
383- defined_opaque_types . contains ( & def_id) . then_some ( origin)
376+ self . defining_opaque_types . contains ( & def_id) . then_some ( origin)
384377 }
385378}
386379
0 commit comments