Skip to content

Commit f2a0776

Browse files
committed
Auto merge of #116447 - oli-obk:gen_fn, r=compiler-errors
Implement `gen` blocks in the 2024 edition Coroutines tracking issue rust-lang/rust#43122 `gen` block tracking issue rust-lang/rust#117078 This PR implements `gen` blocks that implement `Iterator`. Most of the logic with `async` blocks is shared, and thus I renamed various types that were referring to `async` specifically. An example usage of `gen` blocks is ```rust fn foo() -> impl Iterator<Item = i32> { gen { yield 42; for i in 5..18 { if i.is_even() { continue } yield i * 2; } } } ``` The limitations (to be resolved) of the implementation are listed in the tracking issue
2 parents d736992 + 0c8caee commit f2a0776

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

Diff for: clippy_lints/src/suspicious_operation_groupings.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ fn ident_difference_expr_with_base_location(
578578
| (Assign(_, _, _), Assign(_, _, _))
579579
| (TryBlock(_), TryBlock(_))
580580
| (Await(_, _), Await(_, _))
581-
| (Async(_, _), Async(_, _))
581+
| (Gen(_, _, _), Gen(_, _, _))
582582
| (Block(_, _), Block(_, _))
583583
| (Closure(_), Closure(_))
584584
| (Match(_, _), Match(_, _))

Diff for: clippy_utils/src/ast_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
211211
&& eq_fn_decl(lf, rf)
212212
&& eq_expr(le, re)
213213
},
214-
(Async(lc, lb), Async(rc, rb)) => lc == rc && eq_block(lb, rb),
214+
(Gen(lc, lb, lk), Gen(rc, rb, rk)) => lc == rc && eq_block(lb, rb) && lk == rk,
215215
(Range(lf, lt, ll), Range(rf, rt, rl)) => ll == rl && eq_expr_opt(lf, rf) && eq_expr_opt(lt, rt),
216216
(AddrOf(lbk, lm, le), AddrOf(rbk, rm, re)) => lbk == rbk && lm == rm && eq_expr(le, re),
217217
(Path(lq, lp), Path(rq, rp)) => both(lq, rq, eq_qself) && eq_path(lp, rp),

Diff for: clippy_utils/src/sugg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl<'a> Sugg<'a> {
190190
(snip, false) => Sugg::MaybeParen(snip),
191191
(snip, true) => Sugg::NonParen(snip),
192192
},
193-
ast::ExprKind::Async(..)
193+
ast::ExprKind::Gen(..)
194194
| ast::ExprKind::Block(..)
195195
| ast::ExprKind::Break(..)
196196
| ast::ExprKind::Call(..)

0 commit comments

Comments
 (0)