@@ -19,6 +19,7 @@ struct InteriorVisitor<'a, 'tcx> {
19
19
region_scope_tree : & ' tcx region:: ScopeTree ,
20
20
expr_count : usize ,
21
21
kind : hir:: GeneratorKind ,
22
+ prev_unresolved_span : Option < Span > ,
22
23
}
23
24
24
25
impl < ' a , ' tcx > InteriorVisitor < ' a , ' tcx > {
@@ -32,7 +33,6 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
32
33
debug ! ( "generator_interior: attempting to record type {:?} {:?} {:?} {:?}" ,
33
34
ty, scope, expr, source_span) ;
34
35
35
-
36
36
let live_across_yield = scope. map ( |s| {
37
37
self . region_scope_tree . yield_in_scope ( s) . and_then ( |yield_data| {
38
38
// If we are recording an expression that is the last yield
@@ -54,15 +54,11 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
54
54
} ) . unwrap_or_else ( || Some ( YieldData {
55
55
span : DUMMY_SP ,
56
56
expr_and_pat_count : 0 ,
57
- source : match self . kind { // Guess based on the kind of the current generator.
58
- hir:: GeneratorKind :: Gen => hir:: YieldSource :: Yield ,
59
- hir:: GeneratorKind :: Async ( _) => hir:: YieldSource :: Await ,
60
- } ,
57
+ source : self . kind . into ( ) ,
61
58
} ) ) ;
62
59
63
60
if let Some ( yield_data) = live_across_yield {
64
61
let ty = self . fcx . resolve_vars_if_possible ( & ty) ;
65
-
66
62
debug ! ( "type in expr = {:?}, scope = {:?}, type = {:?}, count = {}, yield_span = {:?}" ,
67
63
expr, scope, ty, self . expr_count, yield_data. span) ;
68
64
@@ -74,9 +70,12 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
74
70
yield_data. source) ;
75
71
76
72
// If unresolved type isn't a ty_var then unresolved_type_span is None
73
+ let span = self . prev_unresolved_span . unwrap_or_else (
74
+ || unresolved_type_span. unwrap_or ( source_span)
75
+ ) ;
77
76
self . fcx . need_type_info_err_in_generator (
78
77
self . kind ,
79
- unresolved_type_span . unwrap_or ( source_span ) ,
78
+ span ,
80
79
unresolved_type,
81
80
)
82
81
. span_note ( yield_data. span , & * note)
@@ -94,6 +93,13 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
94
93
} else {
95
94
debug ! ( "no type in expr = {:?}, count = {:?}, span = {:?}" ,
96
95
expr, self . expr_count, expr. map( |e| e. span) ) ;
96
+ let ty = self . fcx . resolve_vars_if_possible ( & ty) ;
97
+ if let Some ( ( unresolved_type, unresolved_type_span) )
98
+ = self . fcx . unresolved_type_vars ( & ty) {
99
+ debug ! ( "remained unresolved_type = {:?}, unresolved_type_span: {:?}" ,
100
+ unresolved_type, unresolved_type_span) ;
101
+ self . prev_unresolved_span = unresolved_type_span;
102
+ }
97
103
}
98
104
}
99
105
}
@@ -112,6 +118,7 @@ pub fn resolve_interior<'a, 'tcx>(
112
118
region_scope_tree : fcx. tcx . region_scope_tree ( def_id) ,
113
119
expr_count : 0 ,
114
120
kind,
121
+ prev_unresolved_span : None ,
115
122
} ;
116
123
intravisit:: walk_body ( & mut visitor, body) ;
117
124
0 commit comments