summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_ast_pretty
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /compiler/rustc_ast_pretty
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_ast_pretty')
-rw-r--r--compiler/rustc_ast_pretty/src/pprust/state.rs20
-rw-r--r--compiler/rustc_ast_pretty/src/pprust/state/expr.rs10
-rw-r--r--compiler/rustc_ast_pretty/src/pprust/state/item.rs4
3 files changed, 19 insertions, 15 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs
index d3d8431c1..6a8064b0e 100644
--- a/compiler/rustc_ast_pretty/src/pprust/state.rs
+++ b/compiler/rustc_ast_pretty/src/pprust/state.rs
@@ -191,23 +191,23 @@ fn doc_comment_to_string(
data: Symbol,
) -> String {
match (comment_kind, attr_style) {
- (CommentKind::Line, ast::AttrStyle::Outer) => format!("///{}", data),
- (CommentKind::Line, ast::AttrStyle::Inner) => format!("//!{}", data),
- (CommentKind::Block, ast::AttrStyle::Outer) => format!("/**{}*/", data),
- (CommentKind::Block, ast::AttrStyle::Inner) => format!("/*!{}*/", data),
+ (CommentKind::Line, ast::AttrStyle::Outer) => format!("///{data}"),
+ (CommentKind::Line, ast::AttrStyle::Inner) => format!("//!{data}"),
+ (CommentKind::Block, ast::AttrStyle::Outer) => format!("/**{data}*/"),
+ (CommentKind::Block, ast::AttrStyle::Inner) => format!("/*!{data}*/"),
}
}
pub fn literal_to_string(lit: token::Lit) -> String {
let token::Lit { kind, symbol, suffix } = lit;
let mut out = match kind {
- token::Byte => format!("b'{}'", symbol),
- token::Char => format!("'{}'", symbol),
- token::Str => format!("\"{}\"", symbol),
+ token::Byte => format!("b'{symbol}'"),
+ token::Char => format!("'{symbol}'"),
+ token::Str => format!("\"{symbol}\""),
token::StrRaw(n) => {
format!("r{delim}\"{string}\"{delim}", delim = "#".repeat(n as usize), string = symbol)
}
- token::ByteStr => format!("b\"{}\"", symbol),
+ token::ByteStr => format!("b\"{symbol}\""),
token::ByteStrRaw(n) => {
format!("br{delim}\"{string}\"{delim}", delim = "#".repeat(n as usize), string = symbol)
}
@@ -376,7 +376,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
}
fn print_meta_item_lit(&mut self, lit: &ast::MetaItemLit) {
- self.print_token_literal(lit.token_lit, lit.span)
+ self.print_token_literal(lit.as_token_lit(), lit.span)
}
fn print_token_literal(&mut self, token_lit: token::Lit, span: Span) {
@@ -1025,7 +1025,7 @@ impl<'a> State<'a> {
self.word("*");
self.print_mt(mt, true);
}
- ast::TyKind::Rptr(lifetime, mt) => {
+ ast::TyKind::Ref(lifetime, mt) => {
self.word("&");
self.print_opt_lifetime(lifetime);
self.print_mt(mt, false);
diff --git a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs
index 4ed16e337..2a18e5164 100644
--- a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs
+++ b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs
@@ -2,6 +2,8 @@ use crate::pp::Breaks::Inconsistent;
use crate::pprust::state::{AnnNode, IterDelimited, PrintState, State, INDENT_UNIT};
use rustc_ast::ptr::P;
+use rustc_ast::token;
+use rustc_ast::util::literal::escape_byte_str_symbol;
use rustc_ast::util::parser::{self, AssocOp, Fixity};
use rustc_ast::{self as ast, BlockCheckMode};
@@ -323,7 +325,7 @@ impl<'a> State<'a> {
self.print_token_literal(*token_lit, expr.span);
}
ast::ExprKind::IncludedBytes(bytes) => {
- let lit = ast::LitKind::ByteStr(bytes.clone()).to_token_lit();
+ let lit = token::Lit::new(token::ByteStr, escape_byte_str_symbol(bytes), None);
self.print_token_literal(lit, expr.span)
}
ast::ExprKind::Cast(expr, ty) => {
@@ -397,6 +399,7 @@ impl<'a> State<'a> {
ast::ExprKind::Closure(box ast::Closure {
binder,
capture_clause,
+ constness,
asyncness,
movability,
fn_decl,
@@ -405,6 +408,7 @@ impl<'a> State<'a> {
fn_arg_span: _,
}) => {
self.print_closure_binder(binder);
+ self.print_constness(*constness);
self.print_movability(*movability);
self.print_asyncness(*asyncness);
self.print_capture_clause(*capture_clause);
@@ -469,10 +473,10 @@ impl<'a> State<'a> {
self.word("]");
}
ast::ExprKind::Range(start, end, limits) => {
- // Special case for `Range`. `AssocOp` claims that `Range` has higher precedence
+ // Special case for `Range`. `AssocOp` claims that `Range` has higher precedence
// than `Assign`, but `x .. x = x` gives a parse error instead of `x .. (x = x)`.
// Here we use a fake precedence value so that any child with lower precedence than
- // a "normal" binop gets parenthesized. (`LOr` is the lowest-precedence binop.)
+ // a "normal" binop gets parenthesized. (`LOr` is the lowest-precedence binop.)
let fake_prec = AssocOp::LOr.precedence() as i8;
if let Some(e) = start {
self.print_expr_maybe_paren(e, fake_prec);
diff --git a/compiler/rustc_ast_pretty/src/pprust/state/item.rs b/compiler/rustc_ast_pretty/src/pprust/state/item.rs
index 5b6a07721..bf2c73a66 100644
--- a/compiler/rustc_ast_pretty/src/pprust/state/item.rs
+++ b/compiler/rustc_ast_pretty/src/pprust/state/item.rs
@@ -411,9 +411,9 @@ impl<'a> State<'a> {
ast::VisibilityKind::Restricted { path, shorthand, .. } => {
let path = Self::to_string(|s| s.print_path(path, false, 0));
if *shorthand && (path == "crate" || path == "self" || path == "super") {
- self.word_nbsp(format!("pub({})", path))
+ self.word_nbsp(format!("pub({path})"))
} else {
- self.word_nbsp(format!("pub(in {})", path))
+ self.word_nbsp(format!("pub(in {path})"))
}
}
ast::VisibilityKind::Inherited => {}