Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unresolved type span inside async object #65668

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,16 @@ impl fmt::Display for YieldSource {
}
}

impl From<GeneratorKind> for YieldSource {
fn from(kind: GeneratorKind) -> Self {
match kind {
// Guess based on the kind of the current generator.
GeneratorKind::Gen => Self::Yield,
GeneratorKind::Async(_) => Self::Await,
}
}
}

#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum CaptureClause {
CaptureByValue,
Expand Down
21 changes: 14 additions & 7 deletions src/librustc_typeck/check/generator_interior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct InteriorVisitor<'a, 'tcx> {
region_scope_tree: &'tcx region::ScopeTree,
expr_count: usize,
kind: hir::GeneratorKind,
prev_unresolved_span: Option<Span>,
}

impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
Expand All @@ -31,7 +32,6 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
debug!("generator_interior: attempting to record type {:?} {:?} {:?} {:?}",
ty, scope, expr, source_span);


let live_across_yield = scope.map(|s| {
self.region_scope_tree.yield_in_scope(s).and_then(|yield_data| {
// If we are recording an expression that is the last yield
Expand All @@ -53,15 +53,11 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
}).unwrap_or_else(|| Some(YieldData {
span: DUMMY_SP,
expr_and_pat_count: 0,
source: match self.kind { // Guess based on the kind of the current generator.
hir::GeneratorKind::Gen => hir::YieldSource::Yield,
hir::GeneratorKind::Async(_) => hir::YieldSource::Await,
},
source: self.kind.into(),
}));

if let Some(yield_data) = live_across_yield {
let ty = self.fcx.resolve_vars_if_possible(&ty);

debug!("type in expr = {:?}, scope = {:?}, type = {:?}, count = {}, yield_span = {:?}",
expr, scope, ty, self.expr_count, yield_data.span);

Expand All @@ -73,9 +69,12 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
yield_data.source);

// If unresolved type isn't a ty_var then unresolved_type_span is None
let span = self.prev_unresolved_span.unwrap_or_else(
|| unresolved_type_span.unwrap_or(source_span)
);
self.fcx.need_type_info_err_in_generator(
self.kind,
unresolved_type_span.unwrap_or(source_span),
span,
unresolved_type,
)
.span_note(yield_data.span, &*note)
Expand All @@ -93,6 +92,13 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
} else {
debug!("no type in expr = {:?}, count = {:?}, span = {:?}",
expr, self.expr_count, expr.map(|e| e.span));
let ty = self.fcx.resolve_vars_if_possible(&ty);
if let Some((unresolved_type, unresolved_type_span))
= self.fcx.unresolved_type_vars(&ty) {
debug!("remained unresolved_type = {:?}, unresolved_type_span: {:?}",
unresolved_type, unresolved_type_span);
self.prev_unresolved_span = unresolved_type_span;
}
}
}
}
Expand All @@ -111,6 +117,7 @@ pub fn resolve_interior<'a, 'tcx>(
region_scope_tree: fcx.tcx.region_scope_tree(def_id),
expr_count: 0,
kind,
prev_unresolved_span: None,
};
intravisit::walk_body(&mut visitor, body);

Expand Down