@@ -19,6 +19,7 @@ struct InteriorVisitor<'a, 'tcx> {
1919 region_scope_tree : & ' tcx region:: ScopeTree ,
2020 expr_count : usize ,
2121 kind : hir:: GeneratorKind ,
22+ prev_unresolved_span : Option < Span > ,
2223}
2324
2425impl < ' a , ' tcx > InteriorVisitor < ' a , ' tcx > {
@@ -32,7 +33,6 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
3233 debug ! ( "generator_interior: attempting to record type {:?} {:?} {:?} {:?}" ,
3334 ty, scope, expr, source_span) ;
3435
35-
3636 let live_across_yield = scope. map ( |s| {
3737 self . region_scope_tree . yield_in_scope ( s) . and_then ( |yield_data| {
3838 // If we are recording an expression that is the last yield
@@ -54,15 +54,11 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
5454 } ) . unwrap_or_else ( || Some ( YieldData {
5555 span : DUMMY_SP ,
5656 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 ( ) ,
6158 } ) ) ;
6259
6360 if let Some ( yield_data) = live_across_yield {
6461 let ty = self . fcx . resolve_vars_if_possible ( & ty) ;
65-
6662 debug ! ( "type in expr = {:?}, scope = {:?}, type = {:?}, count = {}, yield_span = {:?}" ,
6763 expr, scope, ty, self . expr_count, yield_data. span) ;
6864
@@ -74,9 +70,12 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
7470 yield_data. source) ;
7571
7672 // 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+ ) ;
7776 self . fcx . need_type_info_err_in_generator (
7877 self . kind ,
79- unresolved_type_span . unwrap_or ( source_span ) ,
78+ span ,
8079 unresolved_type,
8180 )
8281 . span_note ( yield_data. span , & * note)
@@ -94,6 +93,13 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
9493 } else {
9594 debug ! ( "no type in expr = {:?}, count = {:?}, span = {:?}" ,
9695 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+ }
97103 }
98104 }
99105}
@@ -112,6 +118,7 @@ pub fn resolve_interior<'a, 'tcx>(
112118 region_scope_tree : fcx. tcx . region_scope_tree ( def_id) ,
113119 expr_count : 0 ,
114120 kind,
121+ prev_unresolved_span : None ,
115122 } ;
116123 intravisit:: walk_body ( & mut visitor, body) ;
117124
0 commit comments