Skip to content

Commit

Permalink
record previous unresolve span for generator error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
csmoe committed Oct 22, 2019
1 parent add21c4 commit c337cb2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1833,9 +1833,9 @@ impl fmt::Display for YieldSource {
}
}

impl core::convert::From<GeneratorKind> for YieldSource {
fn from(gen_kind: GeneratorKind) -> Self {
match gen_kind {
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,
Expand Down
11 changes: 9 additions & 2 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 Down Expand Up @@ -68,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 @@ -89,9 +93,11 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
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) {
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

0 comments on commit c337cb2

Please sign in to comment.