Skip to content

Commit 7c108ab

Browse files
Fix ICE when yielding in fn returning impl Trait
1 parent ff23ad3 commit 7c108ab

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

compiler/rustc_borrowck/src/type_check/input_output.rs

+23-3
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,29 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
117117
}
118118
}
119119

120-
assert!(body.yield_ty().is_some() == universal_regions.yield_ty.is_some());
121-
if let Some(mir_yield_ty) = body.yield_ty() {
122-
let ur_yield_ty = universal_regions.yield_ty.unwrap();
120+
debug!(
121+
"equate_inputs_and_outputs: body.yield_ty {:?}, universal_regions.yield_ty {:?}",
122+
body.yield_ty(),
123+
universal_regions.yield_ty
124+
);
125+
126+
// We will not have a universal_regions.yield_ty if we yield (by accident)
127+
// outside of a generator and return an `impl Trait`, so emit a delay_span_bug
128+
// because we don't want to panic in an assert here if we've already got errors.
129+
if body.yield_ty().is_some() != universal_regions.yield_ty.is_some() {
130+
self.tcx().sess.delay_span_bug(
131+
body.span,
132+
&format!(
133+
"Expected body to have yield_ty ({:?}) iff we have a UR yield_ty ({:?})",
134+
body.yield_ty(),
135+
universal_regions.yield_ty,
136+
),
137+
);
138+
}
139+
140+
if let (Some(mir_yield_ty), Some(ur_yield_ty)) =
141+
(body.yield_ty(), universal_regions.yield_ty)
142+
{
123143
let yield_span = body.local_decls[RETURN_PLACE].source_info.span;
124144
self.equate_normalized_input_or_output(ur_yield_ty, mir_yield_ty, yield_span);
125145
}

src/test/ui/generator/issue-91477.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(generators)]
2+
3+
fn foo() -> impl Sized {
4+
yield 1; //~ ERROR E0627
5+
}
6+
7+
fn main() {}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0627]: yield expression outside of generator literal
2+
--> $DIR/issue-91477.rs:4:5
3+
|
4+
LL | yield 1;
5+
| ^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0627`.

0 commit comments

Comments
 (0)