@@ -80,12 +80,47 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
80
80
}
81
81
if self . defining_use_anchor . is_some ( ) {
82
82
let process = |a : Ty < ' tcx > , b : Ty < ' tcx > | match * a. kind ( ) {
83
- ty:: Opaque ( def_id, substs) => self . fold_opaque_ty_new (
83
+ ty:: Opaque ( def_id, substs) => Some ( self . register_hidden_type (
84
84
OpaqueTypeKey { def_id, substs } ,
85
85
cause. clone ( ) ,
86
86
param_env,
87
87
b,
88
- ) ,
88
+ // Check that this is `impl Trait` type is
89
+ // declared by `parent_def_id` -- i.e., one whose
90
+ // value we are inferring. At present, this is
91
+ // always true during the first phase of
92
+ // type-check, but not always true later on during
93
+ // NLL. Once we support named opaque types more fully,
94
+ // this same scenario will be able to arise during all phases.
95
+ //
96
+ // Here is an example using type alias `impl Trait`
97
+ // that indicates the distinction we are checking for:
98
+ //
99
+ // ```rust
100
+ // mod a {
101
+ // pub type Foo = impl Iterator;
102
+ // pub fn make_foo() -> Foo { .. }
103
+ // }
104
+ //
105
+ // mod b {
106
+ // fn foo() -> a::Foo { a::make_foo() }
107
+ // }
108
+ // ```
109
+ //
110
+ // Here, the return type of `foo` references an
111
+ // `Opaque` indeed, but not one whose value is
112
+ // presently being inferred. You can get into a
113
+ // similar situation with closure return types
114
+ // today:
115
+ //
116
+ // ```rust
117
+ // fn foo() -> impl Iterator { .. }
118
+ // fn bar() {
119
+ // let x = || foo(); // returns the Opaque assoc with `foo`
120
+ // }
121
+ // ```
122
+ self . opaque_type_origin ( def_id, cause. span ) ?,
123
+ ) ) ,
89
124
_ => None ,
90
125
} ;
91
126
if let Some ( res) = process ( a, b) {
@@ -479,63 +514,14 @@ impl UseKind {
479
514
}
480
515
481
516
impl < ' a , ' tcx > InferCtxt < ' a , ' tcx > {
482
- fn fold_opaque_ty_new (
517
+ #[ instrument( skip( self ) , level = "debug" ) ]
518
+ fn register_hidden_type (
483
519
& self ,
484
520
opaque_type_key : OpaqueTypeKey < ' tcx > ,
485
521
cause : ObligationCause < ' tcx > ,
486
522
param_env : ty:: ParamEnv < ' tcx > ,
487
523
hidden_ty : Ty < ' tcx > ,
488
- ) -> Option < InferResult < ' tcx , ( ) > > {
489
- // Check that this is `impl Trait` type is
490
- // declared by `parent_def_id` -- i.e., one whose
491
- // value we are inferring. At present, this is
492
- // always true during the first phase of
493
- // type-check, but not always true later on during
494
- // NLL. Once we support named opaque types more fully,
495
- // this same scenario will be able to arise during all phases.
496
- //
497
- // Here is an example using type alias `impl Trait`
498
- // that indicates the distinction we are checking for:
499
- //
500
- // ```rust
501
- // mod a {
502
- // pub type Foo = impl Iterator;
503
- // pub fn make_foo() -> Foo { .. }
504
- // }
505
- //
506
- // mod b {
507
- // fn foo() -> a::Foo { a::make_foo() }
508
- // }
509
- // ```
510
- //
511
- // Here, the return type of `foo` references an
512
- // `Opaque` indeed, but not one whose value is
513
- // presently being inferred. You can get into a
514
- // similar situation with closure return types
515
- // today:
516
- //
517
- // ```rust
518
- // fn foo() -> impl Iterator { .. }
519
- // fn bar() {
520
- // let x = || foo(); // returns the Opaque assoc with `foo`
521
- // }
522
- // ```
523
- if let Some ( origin) = self . opaque_type_origin ( opaque_type_key. def_id , cause. span ) {
524
- return Some ( self . fold_opaque_ty ( cause, param_env, opaque_type_key, origin, hidden_ty) ) ;
525
- }
526
-
527
- debug ! ( ?opaque_type_key, "encountered opaque outside its definition scope" , ) ;
528
- None
529
- }
530
-
531
- #[ instrument( skip( self ) , level = "debug" ) ]
532
- fn fold_opaque_ty (
533
- & self ,
534
- cause : ObligationCause < ' tcx > ,
535
- param_env : ty:: ParamEnv < ' tcx > ,
536
- opaque_type_key : OpaqueTypeKey < ' tcx > ,
537
524
origin : hir:: OpaqueTyOrigin ,
538
- hidden_ty : Ty < ' tcx > ,
539
525
) -> InferResult < ' tcx , ( ) > {
540
526
let tcx = self . tcx ;
541
527
let OpaqueTypeKey { def_id, substs } = opaque_type_key;
0 commit comments