Skip to content

Commit 3d0d04c

Browse files
authored
Rollup merge of rust-lang#138435 - eholk:prefix-yield, r=oli-obk
Add support for postfix yield expressions We've been having a discussion about whether we want postfix yield, or want to stick with prefix yield, or have both. I figured it's easy enough to support both for now and let us play around with them while the feature is still experimental. This PR treats `yield x` and `x.yield` as semantically equivalent. There was a suggestion to make `yield x` have a `()` type (so it only works in coroutines with `Resume = ()`. I think that'd be worth trying, either in a later PR, or before this one merges, depending on people's opinions. rust-lang#43122
2 parents e85fcab + e3f1bc8 commit 3d0d04c

File tree

1 file changed

+3
-2
lines changed
  • clippy_utils/src/ast_utils

1 file changed

+3
-2
lines changed

clippy_utils/src/ast_utils/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
201201
(Loop(lt, ll, _), Loop(rt, rl, _)) => eq_label(ll.as_ref(), rl.as_ref()) && eq_block(lt, rt),
202202
(Block(lb, ll), Block(rb, rl)) => eq_label(ll.as_ref(), rl.as_ref()) && eq_block(lb, rb),
203203
(TryBlock(l), TryBlock(r)) => eq_block(l, r),
204-
(Yield(l), Yield(r)) | (Ret(l), Ret(r)) => eq_expr_opt(l.as_ref(), r.as_ref()),
204+
(Yield(l), Yield(r)) => eq_expr_opt(l.expr(), r.expr()) && l.same_kind(r),
205+
(Ret(l), Ret(r)) => eq_expr_opt(l.as_ref(), r.as_ref()),
205206
(Break(ll, le), Break(rl, re)) => eq_label(ll.as_ref(), rl.as_ref()) && eq_expr_opt(le.as_ref(), re.as_ref()),
206207
(Continue(ll), Continue(rl)) => eq_label(ll.as_ref(), rl.as_ref()),
207208
(Assign(l1, l2, _), Assign(r1, r2, _)) | (Index(l1, l2, _), Index(r1, r2, _)) => {
@@ -688,7 +689,7 @@ pub fn eq_generics(l: &Generics, r: &Generics) -> bool {
688689

689690
pub fn eq_where_predicate(l: &WherePredicate, r: &WherePredicate) -> bool {
690691
use WherePredicateKind::*;
691-
over(&l.attrs, &r.attrs, eq_attr)
692+
over(&l.attrs, &r.attrs, eq_attr)
692693
&& match (&l.kind, &r.kind) {
693694
(BoundPredicate(l), BoundPredicate(r)) => {
694695
over(&l.bound_generic_params, &r.bound_generic_params, |l, r| {

0 commit comments

Comments
 (0)