Skip to content

Commit 27e39b1

Browse files
authored
Rollup merge of rust-lang#67392 - csmoe:async-typeinfo, r=estebank
Fix unresolved type span inside async object Closes rust-lang#65180 r? @estebank It's hard to create a minimal repro for that issue, [decided](https://rust-lang.zulipchat.com/#narrow/stream/187312-wg-async-foundations/topic/meeting.202019.2E12.2E17/near/183675659) to give up finding mcve. cc [previous take](rust-lang#65668)
2 parents d9f1f48 + ff4f6a1 commit 27e39b1

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/librustc/hir/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1857,6 +1857,16 @@ impl fmt::Display for YieldSource {
18571857
}
18581858
}
18591859

1860+
impl From<GeneratorKind> for YieldSource {
1861+
fn from(kind: GeneratorKind) -> Self {
1862+
match kind {
1863+
// Guess based on the kind of the current generator.
1864+
GeneratorKind::Gen => Self::Yield,
1865+
GeneratorKind::Async(_) => Self::Await,
1866+
}
1867+
}
1868+
}
1869+
18601870
// N.B., if you change this, you'll probably want to change the corresponding
18611871
// type structure in middle/ty.rs as well.
18621872
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]

src/librustc_typeck/check/generator_interior.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -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

2425
impl<'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

Comments
 (0)