@@ -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 ;
@@ -106,47 +106,44 @@ impl<'tcx> InferCtxt<'tcx> {
106106 b,
107107 ) ) ;
108108 }
109- match self . defining_use_anchor {
110- DefiningAnchor :: Bind ( _) => {
111- // Check that this is `impl Trait` type is
112- // declared by `parent_def_id` -- i.e., one whose
113- // value we are inferring. At present, this is
114- // always true during the first phase of
115- // type-check, but not always true later on during
116- // NLL. Once we support named opaque types more fully,
117- // this same scenario will be able to arise during all phases.
118- //
119- // Here is an example using type alias `impl Trait`
120- // that indicates the distinction we are checking for:
121- //
122- // ```rust
123- // mod a {
124- // pub type Foo = impl Iterator;
125- // pub fn make_foo() -> Foo { .. }
126- // }
127- //
128- // mod b {
129- // fn foo() -> a::Foo { a::make_foo() }
130- // }
131- // ```
132- //
133- // Here, the return type of `foo` references an
134- // `Opaque` indeed, but not one whose value is
135- // presently being inferred. You can get into a
136- // similar situation with closure return types
137- // today:
138- //
139- // ```rust
140- // fn foo() -> impl Iterator { .. }
141- // fn bar() {
142- // let x = || foo(); // returns the Opaque assoc with `foo`
143- // }
144- // ```
145- if self . opaque_type_origin ( def_id) . is_none ( ) {
146- return None ;
147- }
148- }
109+ // Check that this is `impl Trait` type is
110+ // declared by `parent_def_id` -- i.e., one whose
111+ // value we are inferring. At present, this is
112+ // always true during the first phase of
113+ // type-check, but not always true later on during
114+ // NLL. Once we support named opaque types more fully,
115+ // this same scenario will be able to arise during all phases.
116+ //
117+ // Here is an example using type alias `impl Trait`
118+ // that indicates the distinction we are checking for:
119+ //
120+ // ```rust
121+ // mod a {
122+ // pub type Foo = impl Iterator;
123+ // pub fn make_foo() -> Foo { .. }
124+ // }
125+ //
126+ // mod b {
127+ // fn foo() -> a::Foo { a::make_foo() }
128+ // }
129+ // ```
130+ //
131+ // Here, the return type of `foo` references an
132+ // `Opaque` indeed, but not one whose value is
133+ // presently being inferred. You can get into a
134+ // similar situation with closure return types
135+ // today:
136+ //
137+ // ```rust
138+ // fn foo() -> impl Iterator { .. }
139+ // fn bar() {
140+ // let x = || foo(); // returns the Opaque assoc with `foo`
141+ // }
142+ // ```
143+ if self . opaque_type_origin ( def_id) . is_none ( ) {
144+ return None ;
149145 }
146+
150147 if let ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id : b_def_id, .. } ) = * b. kind ( ) {
151148 // We could accept this, but there are various ways to handle this situation, and we don't
152149 // want to make a decision on it right now. Likely this case is so super rare anyway, that
@@ -371,13 +368,9 @@ impl<'tcx> InferCtxt<'tcx> {
371368 /// in its defining scope.
372369 #[ instrument( skip( self ) , level = "trace" , ret) ]
373370 pub fn opaque_type_origin ( & self , def_id : LocalDefId ) -> Option < OpaqueTyOrigin > {
374- let defined_opaque_types = match self . defining_use_anchor {
375- DefiningAnchor :: Bind ( bind) => bind,
376- } ;
377-
378371 let origin = self . tcx . opaque_type_origin ( def_id) ;
379372
380- defined_opaque_types . contains ( & def_id) . then_some ( origin)
373+ self . defining_opaque_types . contains ( & def_id) . then_some ( origin)
381374 }
382375}
383376
0 commit comments