diff options
| author | Eric Holk <ericholk@microsoft.com> | 2025-03-12 16:27:52 -0700 |
|---|---|---|
| committer | Eric Holk <ericholk@microsoft.com> | 2025-03-14 12:21:59 -0700 |
| commit | 1c0916a2b3cd6c595e1c7b69a31d507f7619bb67 (patch) | |
| tree | 51e37950d5efc1cee3074816313740909128b344 /compiler/rustc_ast_pretty/src/pprust | |
| parent | edf65e735cd871d01149131f5d050293a9f1037c (diff) | |
| download | rust-1c0916a2b3cd6c595e1c7b69a31d507f7619bb67.tar.gz rust-1c0916a2b3cd6c595e1c7b69a31d507f7619bb67.zip | |
Preserve yield position during pretty printing
Diffstat (limited to 'compiler/rustc_ast_pretty/src/pprust')
| -rw-r--r-- | compiler/rustc_ast_pretty/src/pprust/state/expr.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs index e3c41f117ab..9e53ed41c46 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs @@ -8,7 +8,7 @@ use rustc_ast::util::literal::escape_byte_str_symbol; use rustc_ast::util::parser::{self, ExprPrecedence, Fixity}; use rustc_ast::{ self as ast, BlockCheckMode, FormatAlignment, FormatArgPosition, FormatArgsPiece, FormatCount, - FormatDebugHex, FormatSign, FormatTrait, token, + FormatDebugHex, FormatSign, FormatTrait, YieldKind, token, }; use crate::pp::Breaks::Inconsistent; @@ -761,7 +761,7 @@ impl<'a> State<'a> { self.print_expr(e, FixupContext::default()); self.pclose(); } - ast::ExprKind::Yield(e) => { + ast::ExprKind::Yield(e, YieldKind::Prefix) => { self.word("yield"); if let Some(expr) = e { @@ -773,6 +773,16 @@ impl<'a> State<'a> { ); } } + ast::ExprKind::Yield(e, YieldKind::Postfix) => { + // it's not possible to have a postfix yield with no expression. + let e = e.as_ref().unwrap(); + self.print_expr_cond_paren( + e, + e.precedence() < ExprPrecedence::Unambiguous, + fixup.leftmost_subexpression_with_dot(), + ); + self.word(".yield"); + } ast::ExprKind::Try(e) => { self.print_expr_cond_paren( e, |
