Rollup merge of #91488 - compiler-errors:issue-91477, r=estebank

Fix ICE when `yield`ing in function returning `impl Trait`

Change an assert to a `delay_span_bug` and remove an unwrap, that should fix it.

Fixes #91477
This commit is contained in:
Matthias Krüger 2021-12-04 02:26:26 +01:00 committed by GitHub
commit df51bffe6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 3 deletions

View File

@ -117,9 +117,29 @@ pub(super) fn equate_inputs_and_outputs(
}
}
assert!(body.yield_ty().is_some() == universal_regions.yield_ty.is_some());
if let Some(mir_yield_ty) = body.yield_ty() {
let ur_yield_ty = universal_regions.yield_ty.unwrap();
debug!(
"equate_inputs_and_outputs: body.yield_ty {:?}, universal_regions.yield_ty {:?}",
body.yield_ty(),
universal_regions.yield_ty
);
// We will not have a universal_regions.yield_ty if we yield (by accident)
// outside of a generator and return an `impl Trait`, so emit a delay_span_bug
// because we don't want to panic in an assert here if we've already got errors.
if body.yield_ty().is_some() != universal_regions.yield_ty.is_some() {
self.tcx().sess.delay_span_bug(
body.span,
&format!(
"Expected body to have yield_ty ({:?}) iff we have a UR yield_ty ({:?})",
body.yield_ty(),
universal_regions.yield_ty,
),
);
}
if let (Some(mir_yield_ty), Some(ur_yield_ty)) =
(body.yield_ty(), universal_regions.yield_ty)
{
let yield_span = body.local_decls[RETURN_PLACE].source_info.span;
self.equate_normalized_input_or_output(ur_yield_ty, mir_yield_ty, yield_span);
}

View File

@ -0,0 +1,7 @@
#![feature(generators)]
fn foo() -> impl Sized {
yield 1; //~ ERROR E0627
}
fn main() {}

View File

@ -0,0 +1,9 @@
error[E0627]: yield expression outside of generator literal
--> $DIR/issue-91477.rs:4:5
|
LL | yield 1;
| ^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0627`.