Skip to content

Commit 4eb47de

Browse files
committed
wrap expr id into GeneratorInteriorTypeCause
1 parent 5ad8b9e commit 4eb47de

File tree

5 files changed

+23
-18
lines changed

5 files changed

+23
-18
lines changed

src/librustc/traits/error_reporting.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -2456,7 +2456,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
24562456
let target_span = tables
24572457
.generator_interior_types
24582458
.iter()
2459-
.find(|(ty::GeneratorInteriorTypeCause { ty, .. }, _)| {
2459+
.find(|ty::GeneratorInteriorTypeCause { ty, .. }| {
24602460
// Careful: the regions for types that appear in the
24612461
// generator interior are not generally known, so we
24622462
// want to erase them when comparing (and anyway,
@@ -2479,7 +2479,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
24792479
);
24802480
eq
24812481
})
2482-
.map(|(ty::GeneratorInteriorTypeCause { span, scope_span, .. }, expr)| {
2482+
.map(|ty::GeneratorInteriorTypeCause { span, scope_span, expr, .. }| {
24832483
(span, source_map.span_to_snippet(*span), scope_span, expr)
24842484
});
24852485

@@ -2585,8 +2585,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
25852585
};
25862586

25872587
// Look at the last interior type to get a span for the `.await`.
2588-
let await_span =
2589-
tables.generator_interior_types.iter().map(|(i, _)| i.span).last().unwrap();
2588+
let await_span = tables.generator_interior_types.iter().map(|t| t.span).last().unwrap();
25902589
let mut span = MultiSpan::from_span(await_span);
25912590
span.push_span_label(
25922591
await_span,

src/librustc/ty/context.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -315,15 +315,16 @@ pub struct ResolvedOpaqueTy<'tcx> {
315315
///
316316
/// Here, we would store the type `T`, the span of the value `x`, and the "scope-span" for
317317
/// the scope that contains `x`.
318-
#[derive(RustcEncodable, RustcDecodable, Clone, Debug, Eq, Hash, PartialEq)]
319-
#[derive(HashStable, TypeFoldable)]
318+
#[derive(RustcEncodable, RustcDecodable, Clone, Debug, Eq, Hash, PartialEq, HashStable)]
320319
pub struct GeneratorInteriorTypeCause<'tcx> {
321320
/// Type of the captured binding.
322321
pub ty: Ty<'tcx>,
323322
/// Span of the binding that was captured.
324323
pub span: Span,
325324
/// Span of the scope of the captured binding.
326325
pub scope_span: Option<Span>,
326+
/// Expr which the type evaluated from.
327+
pub expr: Option<hir::HirId>,
327328
}
328329

329330
#[derive(RustcEncodable, RustcDecodable, Debug)]
@@ -438,7 +439,7 @@ pub struct TypeckTables<'tcx> {
438439

439440
/// Stores the type, expression, span and optional scope span of all types
440441
/// that are live across the yield of this generator (if a generator).
441-
pub generator_interior_types: Vec<(GeneratorInteriorTypeCause<'tcx>, Option<hir::HirId>)>,
442+
pub generator_interior_types: Vec<GeneratorInteriorTypeCause<'tcx>>,
442443
}
443444

444445
impl<'tcx> TypeckTables<'tcx> {

src/librustc_typeck/check/generator_interior.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use rustc_span::Span;
1818
struct InteriorVisitor<'a, 'tcx> {
1919
fcx: &'a FnCtxt<'a, 'tcx>,
2020
types: FxHashMap<ty::GeneratorInteriorTypeCause<'tcx>, usize>,
21-
exprs: Vec<Option<hir::HirId>>,
2221
region_scope_tree: &'tcx region::ScopeTree,
2322
expr_count: usize,
2423
kind: hir::GeneratorKind,
@@ -98,9 +97,9 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
9897
span: source_span,
9998
ty: &ty,
10099
scope_span,
100+
expr: expr.map(|e| e.hir_id),
101101
})
102102
.or_insert(entries);
103-
self.exprs.push(expr.map(|e| e.hir_id));
104103
}
105104
} else {
106105
debug!(
@@ -138,7 +137,6 @@ pub fn resolve_interior<'a, 'tcx>(
138137
expr_count: 0,
139138
kind,
140139
prev_unresolved_span: None,
141-
exprs: vec![],
142140
};
143141
intravisit::walk_body(&mut visitor, body);
144142

@@ -167,18 +165,25 @@ pub fn resolve_interior<'a, 'tcx>(
167165
// which means that none of the regions inside relate to any other, even if
168166
// typeck had previously found constraints that would cause them to be related.
169167
let mut counter = 0;
170-
let types = fcx.tcx.fold_regions(&types, &mut false, |_, current_depth| {
168+
let fold_types: Vec<_> = types.iter().map(|(t, _)| t.ty).collect();
169+
let folded_types = fcx.tcx.fold_regions(&fold_types, &mut false, |_, current_depth| {
171170
counter += 1;
172171
fcx.tcx.mk_region(ty::ReLateBound(current_depth, ty::BrAnon(counter)))
173172
});
174173

175174
// Store the generator types and spans into the tables for this generator.
176-
let interior_types =
177-
types.iter().zip(visitor.exprs).map(|(t, e)| (t.0.clone(), e)).collect::<Vec<_>>();
178-
visitor.fcx.inh.tables.borrow_mut().generator_interior_types = interior_types;
175+
let types = types
176+
.into_iter()
177+
.zip(&folded_types)
178+
.map(|((mut interior_cause, _), ty)| {
179+
interior_cause.ty = ty;
180+
interior_cause
181+
})
182+
.collect();
183+
visitor.fcx.inh.tables.borrow_mut().generator_interior_types = types;
179184

180185
// Extract type components
181-
let type_list = fcx.tcx.mk_type_list(types.into_iter().map(|t| (t.0).ty));
186+
let type_list = fcx.tcx.mk_type_list(folded_types.iter());
182187

183188
let witness = fcx.tcx.mk_generator_witness(ty::Binder::bind(type_list));
184189

src/test/ui/generator/not-send-sync.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ LL | fn assert_sync<T: Sync>(_: T) {}
2020
LL | assert_sync(|| {
2121
| ^^^^^^^^^^^ future returned by `main` is not `Sync`
2222
|
23-
= help: within `[generator@$DIR/not-send-sync.rs:9:17: 13:6 {std::cell::Cell<i32>, ()}]`, the trait `std::marker::Sync` is not implemented for `std::cell::Cell<i32>`
23+
= help: within `[generator@$DIR/not-send-sync.rs:9:17: 13:6 {std::cell::Cell<i32>, (), ()}]`, the trait `std::marker::Sync` is not implemented for `std::cell::Cell<i32>`
2424
note: future is not `Sync` as this value is used across an yield
2525
--> $DIR/not-send-sync.rs:12:9
2626
|

src/test/ui/impl-trait/recursive-impl-trait-type-indirect.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ error[E0720]: opaque type expands to a recursive type
7676
LL | fn generator_capture() -> impl Sized {
7777
| ^^^^^^^^^^ expands to a recursive type
7878
|
79-
= note: expanded type is `[generator@$DIR/recursive-impl-trait-type-indirect.rs:50:5: 50:26 x:impl Sized {()}]`
79+
= note: expanded type is `[generator@$DIR/recursive-impl-trait-type-indirect.rs:50:5: 50:26 x:impl Sized {(), ()}]`
8080

8181
error[E0720]: opaque type expands to a recursive type
8282
--> $DIR/recursive-impl-trait-type-indirect.rs:53:26
@@ -92,7 +92,7 @@ error[E0720]: opaque type expands to a recursive type
9292
LL | fn generator_hold() -> impl Sized {
9393
| ^^^^^^^^^^ expands to a recursive type
9494
|
95-
= note: expanded type is `[generator@$DIR/recursive-impl-trait-type-indirect.rs:58:5: 62:6 {impl Sized, ()}]`
95+
= note: expanded type is `[generator@$DIR/recursive-impl-trait-type-indirect.rs:58:5: 62:6 {impl Sized, (), ()}]`
9696

9797
error[E0720]: opaque type expands to a recursive type
9898
--> $DIR/recursive-impl-trait-type-indirect.rs:69:26

0 commit comments

Comments
 (0)