Skip to content

Commit 028ffd1

Browse files
authored
Rollup merge of #64989 - sinkuu:fix_ice_64964, r=davidtwco
Fix ICE #64964 Fixes #64964, which is an ICE with `await`ing in a method + incr-comp.
2 parents 7daf2e8 + f0fddb1 commit 028ffd1

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

src/librustc/ty/context.rs

+6
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,12 @@ pub struct GeneratorInteriorTypeCause<'tcx> {
317317
pub scope_span: Option<Span>,
318318
}
319319

320+
BraceStructTypeFoldableImpl! {
321+
impl<'tcx> TypeFoldable<'tcx> for GeneratorInteriorTypeCause<'tcx> {
322+
ty, span, scope_span
323+
}
324+
}
325+
320326
#[derive(RustcEncodable, RustcDecodable, Debug)]
321327
pub struct TypeckTables<'tcx> {
322328
/// The HirId::owner all ItemLocalIds in this table are relative to.

src/librustc_typeck/check/generator_interior.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,6 @@ pub fn resolve_interior<'a, 'tcx>(
123123
// Sort types by insertion order
124124
types.sort_by_key(|t| t.1);
125125

126-
// Store the generator types and spans into the tables for this generator.
127-
let interior_types = types.iter().cloned().map(|t| t.0).collect::<Vec<_>>();
128-
visitor.fcx.inh.tables.borrow_mut().generator_interior_types = interior_types;
129-
130-
// Extract type components
131-
let type_list = fcx.tcx.mk_type_list(types.into_iter().map(|t| (t.0).ty));
132-
133126
// The types in the generator interior contain lifetimes local to the generator itself,
134127
// which should not be exposed outside of the generator. Therefore, we replace these
135128
// lifetimes with existentially-bound lifetimes, which reflect the exact value of the
@@ -139,18 +132,25 @@ pub fn resolve_interior<'a, 'tcx>(
139132
// if a Sync generator contains an &'α T, we need to check whether &'α T: Sync),
140133
// so knowledge of the exact relationships between them isn't particularly important.
141134

142-
debug!("types in generator {:?}, span = {:?}", type_list, body.value.span);
135+
debug!("types in generator {:?}, span = {:?}", types, body.value.span);
143136

144137
// Replace all regions inside the generator interior with late bound regions
145138
// Note that each region slot in the types gets a new fresh late bound region,
146139
// which means that none of the regions inside relate to any other, even if
147140
// typeck had previously found constraints that would cause them to be related.
148141
let mut counter = 0;
149-
let type_list = fcx.tcx.fold_regions(&type_list, &mut false, |_, current_depth| {
142+
let types = fcx.tcx.fold_regions(&types, &mut false, |_, current_depth| {
150143
counter += 1;
151144
fcx.tcx.mk_region(ty::ReLateBound(current_depth, ty::BrAnon(counter)))
152145
});
153146

147+
// Store the generator types and spans into the tables for this generator.
148+
let interior_types = types.iter().map(|t| t.0.clone()).collect::<Vec<_>>();
149+
visitor.fcx.inh.tables.borrow_mut().generator_interior_types = interior_types;
150+
151+
// Extract type components
152+
let type_list = fcx.tcx.mk_type_list(types.into_iter().map(|t| (t.0).ty));
153+
154154
let witness = fcx.tcx.mk_generator_witness(ty::Binder::bind(type_list));
155155

156156
debug!("types in generator after region replacement {:?}, span = {:?}",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// check-pass
2+
// compile-flags: -Z query-dep-graph
3+
// edition:2018
4+
5+
// Regression test for ICE related to `await`ing in a method + incr. comp. (#64964)
6+
7+
struct Body;
8+
impl Body {
9+
async fn next(&mut self) {
10+
async {}.await
11+
}
12+
}
13+
14+
// Another reproduction: `await`ing with a variable from for-loop.
15+
16+
async fn bar() {
17+
for x in 0..10 {
18+
async { Some(x) }.await.unwrap();
19+
}
20+
}
21+
22+
fn main() {}

0 commit comments

Comments
 (0)