summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_ast_pretty/src/pprust
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:29 +0000
commit631cd5845e8de329d0e227aaa707d7ea228b8f8f (patch)
treea1b87c8f8cad01cf18f7c5f57a08f102771ed303 /compiler/rustc_ast_pretty/src/pprust
parentAdding debian version 1.69.0+dfsg1-1. (diff)
downloadrustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.tar.xz
rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_ast_pretty/src/pprust')
-rw-r--r--compiler/rustc_ast_pretty/src/pprust/state.rs6
-rw-r--r--compiler/rustc_ast_pretty/src/pprust/state/expr.rs10
-rw-r--r--compiler/rustc_ast_pretty/src/pprust/state/item.rs18
3 files changed, 22 insertions, 12 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs
index 694d688bf..849336c86 100644
--- a/compiler/rustc_ast_pretty/src/pprust/state.rs
+++ b/compiler/rustc_ast_pretty/src/pprust/state.rs
@@ -686,7 +686,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
fn bclose_maybe_open(&mut self, span: rustc_span::Span, empty: bool, close_box: bool) {
let has_comment = self.maybe_print_comment(span.hi());
if !empty || has_comment {
- self.break_offset_if_not_bol(1, -(INDENT_UNIT as isize));
+ self.break_offset_if_not_bol(1, -INDENT_UNIT);
}
self.word("}");
if close_box {
@@ -984,7 +984,9 @@ impl<'a> State<'a> {
pub fn print_assoc_constraint(&mut self, constraint: &ast::AssocConstraint) {
self.print_ident(constraint.ident);
- constraint.gen_args.as_ref().map(|args| self.print_generic_args(args, false));
+ if let Some(args) = constraint.gen_args.as_ref() {
+ self.print_generic_args(args, false)
+ }
self.space();
match &constraint.kind {
ast::AssocConstraintKind::Equality { term } => {
diff --git a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs
index cacfe9eb2..776bf5424 100644
--- a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs
+++ b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs
@@ -244,6 +244,10 @@ impl<'a> State<'a> {
(&ast::ExprKind::Let { .. }, _) if !parser::needs_par_as_let_scrutinee(prec) => {
parser::PREC_FORCE_PAREN
}
+ // For a binary expression like `(match () { _ => a }) OP b`, the parens are required
+ // otherwise the parser would interpret `match () { _ => a }` as a statement,
+ // with the remaining `OP b` not making sense. So we force parens.
+ (&ast::ExprKind::Match(..), _) => parser::PREC_FORCE_PAREN,
_ => left_prec,
};
@@ -292,10 +296,6 @@ impl<'a> State<'a> {
self.ibox(INDENT_UNIT);
self.ann.pre(self, AnnNode::Expr(expr));
match &expr.kind {
- ast::ExprKind::Box(expr) => {
- self.word_space("box");
- self.print_expr_maybe_paren(expr, parser::PREC_PREFIX);
- }
ast::ExprKind::Array(exprs) => {
self.print_expr_vec(exprs);
}
@@ -439,7 +439,7 @@ impl<'a> State<'a> {
self.ibox(0);
self.print_block_with_attrs(blk, attrs);
}
- ast::ExprKind::Async(capture_clause, _, blk) => {
+ ast::ExprKind::Async(capture_clause, blk) => {
self.word_nbsp("async");
self.print_capture_clause(*capture_clause);
// cbox/ibox in analogy to the `ExprKind::Block` arm above
diff --git a/compiler/rustc_ast_pretty/src/pprust/state/item.rs b/compiler/rustc_ast_pretty/src/pprust/state/item.rs
index bf2c73a66..c465f8c94 100644
--- a/compiler/rustc_ast_pretty/src/pprust/state/item.rs
+++ b/compiler/rustc_ast_pretty/src/pprust/state/item.rs
@@ -2,6 +2,7 @@ use crate::pp::Breaks::Inconsistent;
use crate::pprust::state::delimited::IterDelimited;
use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT};
+use ast::StaticItem;
use rustc_ast as ast;
use rustc_ast::GenericBound;
use rustc_ast::ModKind;
@@ -156,7 +157,7 @@ impl<'a> State<'a> {
self.print_use_tree(tree);
self.word(";");
}
- ast::ItemKind::Static(ty, mutbl, body) => {
+ ast::ItemKind::Static(box StaticItem { ty, mutability: mutbl, expr: body }) => {
let def = ast::Defaultness::Final;
self.print_item_const(
item.ident,
@@ -167,8 +168,15 @@ impl<'a> State<'a> {
def,
);
}
- ast::ItemKind::Const(def, ty, body) => {
- self.print_item_const(item.ident, None, ty, body.as_deref(), &item.vis, *def);
+ ast::ItemKind::Const(box ast::ConstItem { defaultness, ty, expr }) => {
+ self.print_item_const(
+ item.ident,
+ None,
+ ty,
+ expr.as_deref(),
+ &item.vis,
+ *defaultness,
+ );
}
ast::ItemKind::Fn(box ast::Fn { defaultness, sig, generics, body }) => {
self.print_fn_full(
@@ -507,8 +515,8 @@ impl<'a> State<'a> {
ast::AssocItemKind::Fn(box ast::Fn { defaultness, sig, generics, body }) => {
self.print_fn_full(sig, ident, generics, vis, *defaultness, body.as_deref(), attrs);
}
- ast::AssocItemKind::Const(def, ty, body) => {
- self.print_item_const(ident, None, ty, body.as_deref(), vis, *def);
+ ast::AssocItemKind::Const(box ast::ConstItem { defaultness, ty, expr }) => {
+ self.print_item_const(ident, None, ty, expr.as_deref(), vis, *defaultness);
}
ast::AssocItemKind::Type(box ast::TyAlias {
defaultness,