-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Support yield keyword #7209
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
Support yield keyword #7209
Conversation
19: Add YieldExpr r=lnicola a=sasurau4 Adding YieldExpr Part of rust-lang/rust-analyzer#7209 ref: https://doc.rust-lang.org/beta/unstable-book/language-features/generators.html Co-authored-by: Daiki Ihara <sasurau4@gmail.com>
|
As a heads up since you haven't touched that part here before either, to make the parser support the yield syntax you will have to add the parsing for it at the correct places in the https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/parser/src/grammar/expressions/atom.rs module. |
38550ac
to
d2fb5a5
Compare
d2fb5a5
to
b557ea7
Compare
@Veykril Thanks for guiding! |
Expr::Return { expr } => { | ||
Expr::Return { expr } | Expr::Yield { expr } => { | ||
if let Some(expr) = expr { | ||
self.infer_expr_coerce(*expr, &Expectation::has_type(self.return_ty.clone())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't apply to yield I think. A generator may have a return type and a yield type that aren't the same. To properly implement inference for yield
we need to track the yield type in the InferenceContext
I believe but that can be done in a separate PR I'd say.
So for now we probably want something like this:
Expr::Yield { expr } => {
// FIXME: track yield type for coercion
if let Some(expr) = expr {
self.infer_expr(expr, &Expectation::none());
}
Ty::simple(TypeCtor::Never)
}
b557ea7
to
138514b
Compare
lgtm 👍 |
Release Notes: - Added `yield` keyword highlight for Rust Ref: - rust-lang/rust-analyzer#7209 - https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide/src/syntax_highlighting/highlight.rs#L177 - https://doc.rust-lang.org/reference/keywords.html?highlight=yield#reserved-keywords In VS Code:  docs.rs: https://docs.rs/async-stream/latest/async_stream/macro.try_stream.html  ## Before <img width="644" alt="image" src="https://github.com/zed-industries/zed/assets/5518/da349187-57e6-4cea-b3e3-f628ce6a99e8"> ## After update in Zed 
Part of #4309
The inference of yield will be implemented at another PR.