Skip to content

Commit

Permalink
Rollup merge of #92636 - compiler-errors:normalize-generator-const-ex…
Browse files Browse the repository at this point in the history
…pr, r=oli-obk

Normalize generator-local types with unevaluated constants

Normalize generator-interior types in addition to (i.e. instead of just) erasing regions, since sometimes we collect types with unevaluated const exprs.

Fixes #84737
Fixes #88171
Fixes #92091
Fixes #92634
Probably also fixes #73114, but that one has no code I could test. It looks like it's the same issue, though.
  • Loading branch information
matthiaskrgr authored Jan 9, 2022
2 parents 6650a6f + d35b23e commit a8edbfe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
10 changes: 6 additions & 4 deletions compiler/rustc_mir_transform/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,9 +726,13 @@ fn sanitize_witness<'tcx>(
saved_locals: &GeneratorSavedLocals,
) {
let did = body.source.def_id();
let allowed_upvars = tcx.erase_regions(upvars);
let param_env = tcx.param_env(did);

let allowed_upvars = tcx.normalize_erasing_regions(param_env, upvars);
let allowed = match witness.kind() {
&ty::GeneratorWitness(s) => tcx.erase_late_bound_regions(s),
&ty::GeneratorWitness(interior_tys) => {
tcx.normalize_erasing_late_bound_regions(param_env, interior_tys)
}
_ => {
tcx.sess.delay_span_bug(
body.span,
Expand All @@ -738,8 +742,6 @@ fn sanitize_witness<'tcx>(
}
};

let param_env = tcx.param_env(did);

for (local, decl) in body.local_decls.iter_enumerated() {
// Ignore locals which are internal or not saved between yields.
if !saved_locals.contains(local) || decl.internal {
Expand Down
26 changes: 26 additions & 0 deletions src/test/ui/async-await/interior-with-const-generic-expr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// edition:2018
// run-pass

#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
#![allow(unused)]

fn main() {
let x = test();
}

fn concat<const A: usize, const B: usize>(a: [f32; A], b: [f32; B]) -> [f32; A + B] {
todo!()
}

async fn reverse<const A: usize>(x: [f32; A]) -> [f32; A] {
todo!()
}

async fn test() {
let a = [0.0];
let b = [1.0, 2.0];
let ab = concat(a,b);
let ba = reverse(ab).await;
println!("{:?}", ba);
}

0 comments on commit a8edbfe

Please sign in to comment.