summaryrefslogtreecommitdiffstats
path: root/src/tools/rustfmt
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /src/tools/rustfmt
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/rustfmt')
-rw-r--r--src/tools/rustfmt/src/expr.rs12
-rw-r--r--src/tools/rustfmt/src/macros.rs28
-rw-r--r--src/tools/rustfmt/src/matches.rs2
-rw-r--r--src/tools/rustfmt/src/parse/macros/mod.rs2
-rw-r--r--src/tools/rustfmt/src/parse/session.rs35
-rw-r--r--src/tools/rustfmt/src/test/mod.rs4
-rw-r--r--src/tools/rustfmt/src/utils.rs4
7 files changed, 36 insertions, 51 deletions
diff --git a/src/tools/rustfmt/src/expr.rs b/src/tools/rustfmt/src/expr.rs
index 5b1b4fbd4..c3c07f310 100644
--- a/src/tools/rustfmt/src/expr.rs
+++ b/src/tools/rustfmt/src/expr.rs
@@ -256,7 +256,7 @@ pub(crate) fn format_expr(
shape,
SeparatorPlace::Back,
),
- ast::ExprKind::Index(ref expr, ref index) => {
+ ast::ExprKind::Index(ref expr, ref index, _) => {
rewrite_index(&**expr, &**index, context, shape)
}
ast::ExprKind::Repeat(ref expr, ref repeats) => rewrite_pair(
@@ -1342,7 +1342,7 @@ pub(crate) fn is_simple_expr(expr: &ast::Expr) -> bool {
| ast::ExprKind::Field(ref expr, _)
| ast::ExprKind::Try(ref expr)
| ast::ExprKind::Unary(_, ref expr) => is_simple_expr(expr),
- ast::ExprKind::Index(ref lhs, ref rhs) => is_simple_expr(lhs) && is_simple_expr(rhs),
+ ast::ExprKind::Index(ref lhs, ref rhs, _) => is_simple_expr(lhs) && is_simple_expr(rhs),
ast::ExprKind::Repeat(ref lhs, ref rhs) => {
is_simple_expr(lhs) && is_simple_expr(&*rhs.value)
}
@@ -1382,12 +1382,8 @@ pub(crate) fn can_be_overflowed_expr(
|| (context.use_block_indent() && args_len == 1)
}
ast::ExprKind::MacCall(ref mac) => {
- match (
- rustc_ast::ast::MacDelimiter::from_token(mac.args.delim.to_token()),
- context.config.overflow_delimited_expr(),
- ) {
- (Some(ast::MacDelimiter::Bracket), true)
- | (Some(ast::MacDelimiter::Brace), true) => true,
+ match (mac.args.delim, context.config.overflow_delimited_expr()) {
+ (Delimiter::Bracket, true) | (Delimiter::Brace, true) => true,
_ => context.use_block_indent() && args_len == 1,
}
}
diff --git a/src/tools/rustfmt/src/macros.rs b/src/tools/rustfmt/src/macros.rs
index e9a298a27..4f45d0c74 100644
--- a/src/tools/rustfmt/src/macros.rs
+++ b/src/tools/rustfmt/src/macros.rs
@@ -13,7 +13,7 @@ use std::collections::HashMap;
use std::panic::{catch_unwind, AssertUnwindSafe};
use rustc_ast::token::{BinOpToken, Delimiter, Token, TokenKind};
-use rustc_ast::tokenstream::{TokenStream, TokenTree, TokenTreeCursor};
+use rustc_ast::tokenstream::{RefTokenTreeCursor, TokenStream, TokenTree};
use rustc_ast::{ast, ptr};
use rustc_ast_pretty::pprust;
use rustc_span::{
@@ -394,7 +394,7 @@ pub(crate) fn rewrite_macro_def(
}
let ts = def.body.tokens.clone();
- let mut parser = MacroParser::new(ts.into_trees());
+ let mut parser = MacroParser::new(ts.trees());
let parsed_def = match parser.parse() {
Some(def) => def,
None => return snippet,
@@ -736,9 +736,9 @@ impl MacroArgParser {
self.buf.clear();
}
- fn add_meta_variable(&mut self, iter: &mut TokenTreeCursor) -> Option<()> {
+ fn add_meta_variable(&mut self, iter: &mut RefTokenTreeCursor<'_>) -> Option<()> {
match iter.next() {
- Some(TokenTree::Token(
+ Some(&TokenTree::Token(
Token {
kind: TokenKind::Ident(name, _),
..
@@ -768,7 +768,7 @@ impl MacroArgParser {
&mut self,
inner: Vec<ParsedMacroArg>,
delim: Delimiter,
- iter: &mut TokenTreeCursor,
+ iter: &mut RefTokenTreeCursor<'_>,
) -> Option<()> {
let mut buffer = String::new();
let mut first = true;
@@ -868,11 +868,11 @@ impl MacroArgParser {
/// Returns a collection of parsed macro def's arguments.
fn parse(mut self, tokens: TokenStream) -> Option<Vec<ParsedMacroArg>> {
- let mut iter = tokens.into_trees();
+ let mut iter = tokens.trees();
while let Some(tok) = iter.next() {
match tok {
- TokenTree::Token(
+ &TokenTree::Token(
Token {
kind: TokenKind::Dollar,
span,
@@ -901,7 +901,7 @@ impl MacroArgParser {
self.add_meta_variable(&mut iter)?;
}
TokenTree::Token(ref t, _) => self.update_buffer(t),
- TokenTree::Delimited(_delimited_span, delimited, ref tts) => {
+ &TokenTree::Delimited(_delimited_span, delimited, ref tts) => {
if !self.buf.is_empty() {
if next_space(&self.last_tok.kind) == SpaceState::Always {
self.add_separator();
@@ -1119,12 +1119,12 @@ pub(crate) fn macro_style(mac: &ast::MacCall, context: &RewriteContext<'_>) -> D
// A very simple parser that just parses a macros 2.0 definition into its branches.
// Currently we do not attempt to parse any further than that.
-struct MacroParser {
- toks: TokenTreeCursor,
+struct MacroParser<'a> {
+ toks: RefTokenTreeCursor<'a>,
}
-impl MacroParser {
- const fn new(toks: TokenTreeCursor) -> Self {
+impl<'a> MacroParser<'a> {
+ const fn new(toks: RefTokenTreeCursor<'a>) -> Self {
Self { toks }
}
@@ -1143,9 +1143,9 @@ impl MacroParser {
let tok = self.toks.next()?;
let (lo, args_paren_kind) = match tok {
TokenTree::Token(..) => return None,
- TokenTree::Delimited(delimited_span, d, _) => (delimited_span.open.lo(), d),
+ &TokenTree::Delimited(delimited_span, d, _) => (delimited_span.open.lo(), d),
};
- let args = TokenStream::new(vec![tok]);
+ let args = TokenStream::new(vec![tok.clone()]);
match self.toks.next()? {
TokenTree::Token(
Token {
diff --git a/src/tools/rustfmt/src/matches.rs b/src/tools/rustfmt/src/matches.rs
index aac5e59b8..4c37116f1 100644
--- a/src/tools/rustfmt/src/matches.rs
+++ b/src/tools/rustfmt/src/matches.rs
@@ -594,7 +594,7 @@ fn can_flatten_block_around_this(body: &ast::Expr) -> bool {
ast::ExprKind::AddrOf(_, _, ref expr)
| ast::ExprKind::Try(ref expr)
| ast::ExprKind::Unary(_, ref expr)
- | ast::ExprKind::Index(ref expr, _)
+ | ast::ExprKind::Index(ref expr, _, _)
| ast::ExprKind::Cast(ref expr, _) => can_flatten_block_around_this(expr),
_ => false,
}
diff --git a/src/tools/rustfmt/src/parse/macros/mod.rs b/src/tools/rustfmt/src/parse/macros/mod.rs
index 67f398592..7a802f7a8 100644
--- a/src/tools/rustfmt/src/parse/macros/mod.rs
+++ b/src/tools/rustfmt/src/parse/macros/mod.rs
@@ -56,7 +56,7 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
);
parse_macro_arg!(
Pat,
- |parser: &mut rustc_parse::parser::Parser<'b>| parser.parse_pat_no_top_alt(None),
+ |parser: &mut rustc_parse::parser::Parser<'b>| parser.parse_pat_no_top_alt(None, None),
|x: ptr::P<ast::Pat>| Some(x)
);
// `parse_item` returns `Option<ptr::P<ast::Item>>`.
diff --git a/src/tools/rustfmt/src/parse/session.rs b/src/tools/rustfmt/src/parse/session.rs
index 81b5015dd..945e3e42f 100644
--- a/src/tools/rustfmt/src/parse/session.rs
+++ b/src/tools/rustfmt/src/parse/session.rs
@@ -4,7 +4,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use rustc_data_structures::sync::{Lrc, Send};
use rustc_errors::emitter::{Emitter, EmitterWriter};
use rustc_errors::translation::Translate;
-use rustc_errors::{ColorConfig, Diagnostic, Handler, Level as DiagnosticLevel, TerminalUrl};
+use rustc_errors::{ColorConfig, Diagnostic, Handler, Level as DiagnosticLevel};
use rustc_session::parse::ParseSess as RawParseSess;
use rustc_span::{
source_map::{FilePathMapping, SourceMap},
@@ -139,30 +139,15 @@ fn default_handler(
rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
false,
);
- Box::new(EmitterWriter::stderr(
- emit_color,
- Some(source_map.clone()),
- None,
- fallback_bundle,
- false,
- false,
- None,
- false,
- false,
- TerminalUrl::No,
- ))
+ Box::new(EmitterWriter::stderr(emit_color, fallback_bundle).sm(Some(source_map.clone())))
};
- Handler::with_emitter(
- true,
- None,
- Box::new(SilentOnIgnoredFilesEmitter {
- has_non_ignorable_parser_errors: false,
- source_map,
- emitter,
- ignore_path_set,
- can_reset,
- }),
- )
+ Handler::with_emitter(Box::new(SilentOnIgnoredFilesEmitter {
+ has_non_ignorable_parser_errors: false,
+ source_map,
+ emitter,
+ ignore_path_set,
+ can_reset,
+ }))
}
impl ParseSess {
@@ -233,7 +218,7 @@ impl ParseSess {
}
pub(crate) fn set_silent_emitter(&mut self) {
- self.parse_sess.span_diagnostic = Handler::with_emitter(true, None, silent_emitter());
+ self.parse_sess.span_diagnostic = Handler::with_emitter(silent_emitter());
}
pub(crate) fn span_to_filename(&self, span: Span) -> FileName {
diff --git a/src/tools/rustfmt/src/test/mod.rs b/src/tools/rustfmt/src/test/mod.rs
index cfad4a8ed..37854ead2 100644
--- a/src/tools/rustfmt/src/test/mod.rs
+++ b/src/tools/rustfmt/src/test/mod.rs
@@ -838,6 +838,10 @@ fn handle_result(
// Ignore LF and CRLF difference for Windows.
if !string_eq_ignore_newline_repr(&fmt_text, &text) {
+ if std::env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0") {
+ std::fs::write(file_name, fmt_text).unwrap();
+ continue;
+ }
let diff = make_diff(&text, &fmt_text, DIFF_CONTEXT_SIZE);
assert!(
!diff.is_empty(),
diff --git a/src/tools/rustfmt/src/utils.rs b/src/tools/rustfmt/src/utils.rs
index 890a05b8c..4fc5a9b68 100644
--- a/src/tools/rustfmt/src/utils.rs
+++ b/src/tools/rustfmt/src/utils.rs
@@ -441,7 +441,7 @@ pub(crate) fn left_most_sub_expr(e: &ast::Expr) -> &ast::Expr {
| ast::ExprKind::Assign(ref e, _, _)
| ast::ExprKind::AssignOp(_, ref e, _)
| ast::ExprKind::Field(ref e, _)
- | ast::ExprKind::Index(ref e, _)
+ | ast::ExprKind::Index(ref e, _, _)
| ast::ExprKind::Range(Some(ref e), _, _)
| ast::ExprKind::Try(ref e) => left_most_sub_expr(e),
_ => e,
@@ -479,7 +479,7 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
| ast::ExprKind::Match(..) => repr.contains('\n'),
ast::ExprKind::Paren(ref expr)
| ast::ExprKind::Binary(_, _, ref expr)
- | ast::ExprKind::Index(_, ref expr)
+ | ast::ExprKind::Index(_, ref expr, _)
| ast::ExprKind::Unary(_, ref expr)
| ast::ExprKind::Try(ref expr)
| ast::ExprKind::Yield(Some(ref expr)) => is_block_expr(context, expr, repr),