Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not ICE when evaluating locals' types of invalid yield #82245

Merged
merged 1 commit into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2081,6 +2081,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
_ => {
self.tcx.sess.emit_err(YieldExprOutsideOfGenerator { span: expr.span });
// Avoid expressions without types during writeback (#78653).
self.check_expr(value);
self.tcx.mk_unit()
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/generator/yield-outside-generator-issue-78653.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![feature(generators)]

fn main() {
yield || for i in 0 { }
//~^ ERROR yield expression outside of generator literal
//~| ERROR `{integer}` is not an iterator
}
21 changes: 21 additions & 0 deletions src/test/ui/generator/yield-outside-generator-issue-78653.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error[E0627]: yield expression outside of generator literal
--> $DIR/yield-outside-generator-issue-78653.rs:4:5
|
LL | yield || for i in 0 { }
| ^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: `{integer}` is not an iterator
--> $DIR/yield-outside-generator-issue-78653.rs:4:23
|
LL | yield || for i in 0 { }
| ^ `{integer}` is not an iterator
|
= help: the trait `Iterator` is not implemented for `{integer}`
= 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`
= note: required because of the requirements on the impl of `IntoIterator` for `{integer}`
= note: required by `into_iter`

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0277, E0627.
For more information about an error, try `rustc --explain E0277`.