Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
edf65e7
Add support for postfix yield expressions
eholk Mar 12, 2025
1c0916a
Preserve yield position during pretty printing
eholk Mar 12, 2025
635eae2
Teach rustfmt to handle postfix yield
eholk Mar 13, 2025
c5093ac
Fix clippy
eholk Mar 13, 2025
9b0e7f6
Teach rustfmt to handle postfix yield
eholk Mar 18, 2025
299e5d0
Apply suggestions from code review
eholk Mar 18, 2025
2bd7f73
Refactor YieldKind so postfix yield must have an expression
eholk Mar 18, 2025
f27cab8
Use `Option<Ident>` for lowered param names.
nnethercote Mar 13, 2025
5a52b5d
Suggest `-Whelp` when pass `--print lints` to rustc
xizheyin Mar 19, 2025
d07ef5b
coverage: Add LLVM plumbing for expansion regions
Zalathar Mar 4, 2025
220851c
Do not rely on type_var_origin in OrphanCheckErr::NonLocalInputType
compiler-errors Mar 20, 2025
b14de91
Pre cleanups
compiler-errors Mar 18, 2025
2e36990
coverage: Convert and check span coordinates without a local file ID
Zalathar Mar 20, 2025
e6004cc
Use def_path_str for def id arg in UnsupportedOpInfo
compiler-errors Mar 20, 2025
974f759
Remove `llvm` and `llvms` triagebot ping aliases for icebreakers-llvm
jieyouxu Mar 20, 2025
496c251
Disambiguate between wg-llvm and icebreakers-llvm in rustc-dev-guide
jieyouxu Mar 20, 2025
b3c5caf
Rollup merge of #138435 - eholk:prefix-yield, r=oli-obk
matthiaskrgr Mar 20, 2025
00f3ad0
Rollup merge of #138685 - nnethercote:use-Option-Ident-for-lowered-pa…
matthiaskrgr Mar 20, 2025
d4218c2
Rollup merge of #138700 - xizheyin:issue-138612, r=Nadrieril
matthiaskrgr Mar 20, 2025
4659493
Rollup merge of #138727 - compiler-errors:ty-var-origin, r=fmease
matthiaskrgr Mar 20, 2025
84a2bb9
Rollup merge of #138729 - compiler-errors:gen, r=lcnr
matthiaskrgr Mar 20, 2025
7df0170
Rollup merge of #138731 - Zalathar:llvm-expansion, r=jieyouxu
matthiaskrgr Mar 20, 2025
73ed8b3
Rollup merge of #138732 - compiler-errors:did, r=jieyouxu
matthiaskrgr Mar 20, 2025
4a87516
Rollup merge of #138735 - jieyouxu:drop-llvm-alias, r=nikic
matthiaskrgr Mar 20, 2025
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
Prev Previous commit
Next Next commit
Teach rustfmt to handle postfix yield
  • Loading branch information
eholk committed Mar 14, 2025
commit 635eae2d4fc724cb53a3a45975bc18779a3293b1
5 changes: 3 additions & 2 deletions src/tools/clippy/clippy_utils/src/ast_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
(Loop(lt, ll, _), Loop(rt, rl, _)) => eq_label(ll.as_ref(), rl.as_ref()) && eq_block(lt, rt),
(Block(lb, ll), Block(rb, rl)) => eq_label(ll.as_ref(), rl.as_ref()) && eq_block(lb, rb),
(TryBlock(l), TryBlock(r)) => eq_block(l, r),
(Yield(l), Yield(r)) | (Ret(l), Ret(r)) => eq_expr_opt(l.as_ref(), r.as_ref()),
(Yield(l, lk), Yield(r, rk)) => eq_expr_opt(l.as_ref(), r.as_ref()) && lk == rk,
(Ret(l), Ret(r)) => eq_expr_opt(l.as_ref(), r.as_ref()),
(Break(ll, le), Break(rl, re)) => eq_label(ll.as_ref(), rl.as_ref()) && eq_expr_opt(le.as_ref(), re.as_ref()),
(Continue(ll), Continue(rl)) => eq_label(ll.as_ref(), rl.as_ref()),
(Assign(l1, l2, _), Assign(r1, r2, _)) | (Index(l1, l2, _), Index(r1, r2, _)) => {
Expand Down Expand Up @@ -688,7 +689,7 @@ pub fn eq_generics(l: &Generics, r: &Generics) -> bool {

pub fn eq_where_predicate(l: &WherePredicate, r: &WherePredicate) -> bool {
use WherePredicateKind::*;
over(&l.attrs, &r.attrs, eq_attr)
over(&l.attrs, &r.attrs, eq_attr)
&& match (&l.kind, &r.kind) {
(BoundPredicate(l), BoundPredicate(r)) => {
over(&l.bound_generic_params, &r.bound_generic_params, |l, r| {
Expand Down
5 changes: 3 additions & 2 deletions src/tools/rustfmt/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub(crate) fn format_expr(
Ok(format!("break{id_str}"))
}
}
ast::ExprKind::Yield(ref opt_expr) => {
ast::ExprKind::Yield(ref opt_expr, ast::YieldKind::Prefix) => {
if let Some(ref expr) = *opt_expr {
rewrite_unary_prefix(context, "yield ", &**expr, shape)
} else {
Expand All @@ -243,7 +243,8 @@ pub(crate) fn format_expr(
ast::ExprKind::Try(..)
| ast::ExprKind::Field(..)
| ast::ExprKind::MethodCall(..)
| ast::ExprKind::Await(_, _) => rewrite_chain(expr, context, shape),
| ast::ExprKind::Await(_, _)
| ast::ExprKind::Yield(_, ast::YieldKind::Postfix) => rewrite_chain(expr, context, shape),
ast::ExprKind::MacCall(ref mac) => {
rewrite_macro(mac, None, context, shape, MacroPosition::Expression).or_else(|_| {
wrap_str(
Expand Down
15 changes: 15 additions & 0 deletions src/tools/rustfmt/tests/source/postfix-yield.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This demonstrates a proposed alternate or additional option of having yield in postfix position.
//@ edition: 2024

#![feature(gen_blocks, coroutines, coroutine_trait, yield_expr)]

use std::ops::{Coroutine, CoroutineState};
use std::pin::pin;

fn main() {
let mut coro =
pin!(#[coroutine] |_: i32| { let x = 1.yield;


(x + 2).yield; });
}
12 changes: 12 additions & 0 deletions src/tools/rustfmt/tests/target/postfix-yield.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This demonstrates a proposed alternate or additional option of having yield in postfix position.
//@ edition: 2024

#![feature(gen_blocks, coroutines, coroutine_trait, yield_expr)]

use std::ops::{Coroutine, CoroutineState};
use std::pin::pin;

fn main() {
let mut coro =
pin!(#[coroutine] |_: i32| { let x = 1.yield; (x + 2).yield; });
}