Skip to content

Commit c244546

Browse files
authored
Rollup merge of #82245 - estebank:issue-78653, r=matthewjasper
Do not ICE when evaluating locals' types of invalid `yield` When a `yield` is outside of a generator, check its value regardless to avoid an ICE while trying to get all locals' types in writeback. Fix #78653.
2 parents 30f39fe + 3eb454a commit c244546

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

compiler/rustc_typeck/src/check/expr.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2081,6 +2081,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20812081
}
20822082
_ => {
20832083
self.tcx.sess.emit_err(YieldExprOutsideOfGenerator { span: expr.span });
2084+
// Avoid expressions without types during writeback (#78653).
2085+
self.check_expr(value);
20842086
self.tcx.mk_unit()
20852087
}
20862088
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(generators)]
2+
3+
fn main() {
4+
yield || for i in 0 { }
5+
//~^ ERROR yield expression outside of generator literal
6+
//~| ERROR `{integer}` is not an iterator
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0627]: yield expression outside of generator literal
2+
--> $DIR/yield-outside-generator-issue-78653.rs:4:5
3+
|
4+
LL | yield || for i in 0 { }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error[E0277]: `{integer}` is not an iterator
8+
--> $DIR/yield-outside-generator-issue-78653.rs:4:23
9+
|
10+
LL | yield || for i in 0 { }
11+
| ^ `{integer}` is not an iterator
12+
|
13+
= help: the trait `Iterator` is not implemented for `{integer}`
14+
= note: if you want to iterate between `start` until a value `end`, use the exclusive range syntax `start..end` or the inclusive range syntax `start..=end`
15+
= note: required because of the requirements on the impl of `IntoIterator` for `{integer}`
16+
= note: required by `into_iter`
17+
18+
error: aborting due to 2 previous errors
19+
20+
Some errors have detailed explanations: E0277, E0627.
21+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)