Skip to content

Commit ff4f6a1

Browse files
committed
record previous unresolve span for generator error reporting
1 parent c1241bf commit ff4f6a1

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/librustc/hir/mod.rs

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

1860-
impl core::convert::From<GeneratorKind> for YieldSource {
1861-
fn from(gen_kind: GeneratorKind) -> Self {
1862-
match gen_kind {
1860+
impl From<GeneratorKind> for YieldSource {
1861+
fn from(kind: GeneratorKind) -> Self {
1862+
match kind {
18631863
// Guess based on the kind of the current generator.
18641864
GeneratorKind::Gen => Self::Yield,
18651865
GeneratorKind::Async(_) => Self::Await,
18661866
}
18671867
}
18681868
}
18691869

1870-
#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)]
1871-
pub enum CaptureClause {
1872-
CaptureByValue,
1873-
CaptureByRef,
1874-
}
1875-
18761870
// N.B., if you change this, you'll probably want to change the corresponding
18771871
// type structure in middle/ty.rs as well.
18781872
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]

src/librustc_typeck/check/generator_interior.rs

+9-2
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> {
@@ -69,9 +70,12 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
6970
yield_data.source);
7071

7172
// 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+
);
7276
self.fcx.need_type_info_err_in_generator(
7377
self.kind,
74-
unresolved_type_span.unwrap_or(source_span),
78+
span,
7579
unresolved_type,
7680
)
7781
.span_note(yield_data.span, &*note)
@@ -90,9 +94,11 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
9094
debug!("no type in expr = {:?}, count = {:?}, span = {:?}",
9195
expr, self.expr_count, expr.map(|e| e.span));
9296
let ty = self.fcx.resolve_vars_if_possible(&ty);
93-
if let Some((unresolved_type, unresolved_type_span)) = self.fcx.unresolved_type_vars(&ty) {
97+
if let Some((unresolved_type, unresolved_type_span))
98+
= self.fcx.unresolved_type_vars(&ty) {
9499
debug!("remained unresolved_type = {:?}, unresolved_type_span: {:?}",
95100
unresolved_type, unresolved_type_span);
101+
self.prev_unresolved_span = unresolved_type_span;
96102
}
97103
}
98104
}
@@ -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)