Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 765a6ca

Browse files
committedMar 20, 2025·
Auto merge of rust-lang#138733 - jieyouxu:rollup-hcgwhei, r=jieyouxu
Rollup of 15 pull requests Successful merges: - rust-lang#138321 ([bootstrap] Distribute split debuginfo if present) - rust-lang#138364 (ports the compiler test cases to new rust_intrinsic format) - rust-lang#138410 (Couple mir building cleanups) - rust-lang#138435 (Add support for postfix yield expressions) - rust-lang#138536 (stable_mir: Add `MutMirVisitor`) - rust-lang#138623 ([bootstrap] Use llvm_runtimes for compiler-rt) - rust-lang#138650 (Optimize `io::Write::write_fmt` for constant strings) - rust-lang#138652 (Reintroduce remote-test support in run-make tests) - rust-lang#138685 (Use `Option<Ident>` for lowered param names.) - rust-lang#138694 (Fix: add ohos target notes) - rust-lang#138700 (Suggest `-Whelp` when pass `--print lints` to rustc) - rust-lang#138709 (Update GCC submodule) - rust-lang#138724 (Check attrs: Don't try to retrieve the name of list stems) - rust-lang#138731 (coverage: Add LLVM plumbing for expansion regions) - rust-lang#138732 (Use `def_path_str` for def id arg in `UnsupportedOpInfo`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 87e60a7 + 0575fc1 commit 765a6ca

File tree

75 files changed

+1300
-689
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1300
-689
lines changed
 

‎compiler/rustc_ast/src/ast.rs

+39-1
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,7 @@ pub enum ExprKind {
16571657
Try(P<Expr>),
16581658

16591659
/// A `yield`, with an optional value to be yielded.
1660-
Yield(Option<P<Expr>>),
1660+
Yield(YieldKind),
16611661

16621662
/// A `do yeet` (aka `throw`/`fail`/`bail`/`raise`/whatever),
16631663
/// with an optional value to be returned.
@@ -1903,6 +1903,44 @@ pub enum MatchKind {
19031903
Postfix,
19041904
}
19051905

1906+
/// The kind of yield expression
1907+
#[derive(Clone, Encodable, Decodable, Debug)]
1908+
pub enum YieldKind {
1909+
/// yield expr { ... }
1910+
Prefix(Option<P<Expr>>),
1911+
/// expr.yield { ... }
1912+
Postfix(P<Expr>),
1913+
}
1914+
1915+
impl YieldKind {
1916+
/// Returns the expression inside the yield expression, if any.
1917+
///
1918+
/// For postfix yields, this is guaranteed to be `Some`.
1919+
pub const fn expr(&self) -> Option<&P<Expr>> {
1920+
match self {
1921+
YieldKind::Prefix(expr) => expr.as_ref(),
1922+
YieldKind::Postfix(expr) => Some(expr),
1923+
}
1924+
}
1925+
1926+
/// Returns a mutable reference to the expression being yielded, if any.
1927+
pub const fn expr_mut(&mut self) -> Option<&mut P<Expr>> {
1928+
match self {
1929+
YieldKind::Prefix(expr) => expr.as_mut(),
1930+
YieldKind::Postfix(expr) => Some(expr),
1931+
}
1932+
}
1933+
1934+
/// Returns true if both yields are prefix or both are postfix.
1935+
pub const fn same_kind(&self, other: &Self) -> bool {
1936+
match (self, other) {
1937+
(YieldKind::Prefix(_), YieldKind::Prefix(_)) => true,
1938+
(YieldKind::Postfix(_), YieldKind::Postfix(_)) => true,
1939+
_ => false,
1940+
}
1941+
}
1942+
}
1943+
19061944
/// A literal in a meta item.
19071945
#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)]
19081946
pub struct MetaItemLit {

‎compiler/rustc_ast/src/mut_visit.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1813,8 +1813,11 @@ pub fn walk_expr<T: MutVisitor>(vis: &mut T, Expr { kind, id, span, attrs, token
18131813
ExprKind::Paren(expr) => {
18141814
vis.visit_expr(expr);
18151815
}
1816-
ExprKind::Yield(expr) => {
1817-
visit_opt(expr, |expr| vis.visit_expr(expr));
1816+
ExprKind::Yield(kind) => {
1817+
let expr = kind.expr_mut();
1818+
if let Some(expr) = expr {
1819+
vis.visit_expr(expr);
1820+
}
18181821
}
18191822
ExprKind::Try(expr) => vis.visit_expr(expr),
18201823
ExprKind::TryBlock(body) => vis.visit_block(body),

0 commit comments

Comments
 (0)
Please sign in to comment.