Skip to content

Commit 0bb2acf

Browse files
Merge pull request rust-lang#5944 from calebcartwright/subtree-sync-2023-10-22
sync subtree
2 parents 547577f + c2515df commit 0bb2acf

20 files changed

+111
-85
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@
8181
- Support for formatting let-else statements [#5690]
8282
- New config option, `single_line_let_else_max_width`, that allows users to configure the maximum length of single line `let-else` statements. `let-else` statements that otherwise meet the requirements to be formatted on a single line will have their divergent`else` block formatted over multiple lines if they exceed this length [#5684]
8383

84+
<<<<<<< HEAD
85+
[#5690]: (https://github.com/rust-lang/rustfmt/pulls/5690)
86+
=======
8487
[#5690]: https://github.com/rust-lang/rustfmt/pull/5690
88+
>>>>>>> upstream/master
8589
[#5684]: https://github.com/rust-lang/rustfmt/issues/5684
8690

8791
## [1.5.3] 2023-06-20
@@ -90,7 +94,11 @@
9094

9195
- When formatting doc comments with `wrap_comments = true` rustfmt will no longer wrap markdown tables [#4210](https://github.com/rust-lang/rustfmt/issues/4210)
9296
- Properly handle wrapping comments that include a numbered list in markdown [#5416](https://github.com/rust-lang/rustfmt/issues/5416)
97+
<<<<<<< HEAD
98+
- Properly handle markdown sublists that utilize a `+` [#4041](https://github.com/rust-lang/rustfmt/issues/4210)
99+
=======
93100
- Properly handle markdown sublists that utilize a `+` [#4041](https://github.com/rust-lang/rustfmt/issues/4041)
101+
>>>>>>> upstream/master
94102
- rustfmt will no longer use shorthand initialization when rewriting a tuple struct even when `use_field_init_shorthand = true` as this leads to code that could no longer compile.
95103
Take the following struct as an example `struct MyStruct(u64);`. rustfmt will no longer format `MyStruct { 0: 0 }` as `MyStruct { 0 }` [#5488](https://github.com/rust-lang/rustfmt/issues/5488)
96104
- rustfmt no longer panics when formatting an empty code block in a doc comment with `format_code_in_doc_comments = true` [#5234](https://github.com/rust-lang/rustfmt/issues/5234). For example:

Cargo.lock

Lines changed: 19 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ generic-simd = ["bytecount/generic-simd"]
3535
[dependencies]
3636
annotate-snippets = { version = "0.9", features = ["color"] }
3737
anyhow = "1.0"
38-
bytecount = "0.6.3"
38+
bytecount = "0.6.4"
3939
cargo_metadata = "0.15.4"
4040
clap = { version = "4.4.2", features = ["derive"] }
4141
clap-cargo = "0.12.0"

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2023-07-01"
2+
channel = "nightly-2023-10-22"
33
components = ["llvm-tools", "rustc-dev"]

src/expr.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub(crate) fn format_expr(
132132
ast::ExprKind::Tup(ref items) => {
133133
rewrite_tuple(context, items.iter(), expr.span, shape, items.len() == 1)
134134
}
135-
ast::ExprKind::Let(ref pat, ref expr, _span) => rewrite_let(context, shape, pat, expr),
135+
ast::ExprKind::Let(ref pat, ref expr, _span, _) => rewrite_let(context, shape, pat, expr),
136136
ast::ExprKind::If(..)
137137
| ast::ExprKind::ForLoop(..)
138138
| ast::ExprKind::Loop(..)
@@ -261,7 +261,7 @@ pub(crate) fn format_expr(
261261
shape,
262262
SeparatorPlace::Back,
263263
),
264-
ast::ExprKind::Index(ref expr, ref index) => {
264+
ast::ExprKind::Index(ref expr, ref index, _) => {
265265
rewrite_index(&**expr, &**index, context, shape)
266266
}
267267
ast::ExprKind::Repeat(ref expr, ref repeats) => rewrite_pair(
@@ -662,7 +662,7 @@ struct ControlFlow<'a> {
662662

663663
fn extract_pats_and_cond(expr: &ast::Expr) -> (Option<&ast::Pat>, &ast::Expr) {
664664
match expr.kind {
665-
ast::ExprKind::Let(ref pat, ref cond, _) => (Some(pat), cond),
665+
ast::ExprKind::Let(ref pat, ref cond, _, _) => (Some(pat), cond),
666666
_ => (None, expr),
667667
}
668668
}
@@ -1339,7 +1339,7 @@ pub(crate) fn is_simple_expr(expr: &ast::Expr) -> bool {
13391339
| ast::ExprKind::Field(ref expr, _)
13401340
| ast::ExprKind::Try(ref expr)
13411341
| ast::ExprKind::Unary(_, ref expr) => is_simple_expr(expr),
1342-
ast::ExprKind::Index(ref lhs, ref rhs) => is_simple_expr(lhs) && is_simple_expr(rhs),
1342+
ast::ExprKind::Index(ref lhs, ref rhs, _) => is_simple_expr(lhs) && is_simple_expr(rhs),
13431343
ast::ExprKind::Repeat(ref lhs, ref rhs) => {
13441344
is_simple_expr(lhs) && is_simple_expr(&*rhs.value)
13451345
}
@@ -1379,12 +1379,8 @@ pub(crate) fn can_be_overflowed_expr(
13791379
|| (context.use_block_indent() && args_len == 1)
13801380
}
13811381
ast::ExprKind::MacCall(ref mac) => {
1382-
match (
1383-
rustc_ast::ast::MacDelimiter::from_token(mac.args.delim.to_token()),
1384-
context.config.overflow_delimited_expr(),
1385-
) {
1386-
(Some(ast::MacDelimiter::Bracket), true)
1387-
| (Some(ast::MacDelimiter::Brace), true) => true,
1382+
match (mac.args.delim, context.config.overflow_delimited_expr()) {
1383+
(Delimiter::Bracket, true) | (Delimiter::Brace, true) => true,
13881384
_ => context.use_block_indent() && args_len == 1,
13891385
}
13901386
}

src/items.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2608,7 +2608,8 @@ fn rewrite_fn_base(
26082608
if where_clause_str.is_empty() {
26092609
if let ast::FnRetTy::Default(ret_span) = fd.output {
26102610
match recover_missing_comment_in_span(
2611-
mk_sp(params_span.hi(), ret_span.hi()),
2611+
// from after the closing paren to right before block or semicolon
2612+
mk_sp(ret_span.lo(), span.hi()),
26122613
shape,
26132614
context,
26142615
last_line_width(&result),

src/macros.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::collections::HashMap;
1313
use std::panic::{catch_unwind, AssertUnwindSafe};
1414

1515
use rustc_ast::token::{BinOpToken, Delimiter, Token, TokenKind};
16-
use rustc_ast::tokenstream::{TokenStream, TokenTree, TokenTreeCursor};
16+
use rustc_ast::tokenstream::{RefTokenTreeCursor, TokenStream, TokenTree};
1717
use rustc_ast::{ast, ptr};
1818
use rustc_ast_pretty::pprust;
1919
use rustc_span::{
@@ -411,7 +411,7 @@ pub(crate) fn rewrite_macro_def(
411411
}
412412

413413
let ts = def.body.tokens.clone();
414-
let mut parser = MacroParser::new(ts.into_trees());
414+
let mut parser = MacroParser::new(ts.trees());
415415
let parsed_def = match parser.parse() {
416416
Some(def) => def,
417417
None => return snippet,
@@ -760,9 +760,9 @@ impl MacroArgParser {
760760
self.buf.clear();
761761
}
762762

763-
fn add_meta_variable(&mut self, iter: &mut TokenTreeCursor) -> Option<()> {
763+
fn add_meta_variable(&mut self, iter: &mut RefTokenTreeCursor<'_>) -> Option<()> {
764764
match iter.next() {
765-
Some(TokenTree::Token(
765+
Some(&TokenTree::Token(
766766
Token {
767767
kind: TokenKind::Ident(name, _),
768768
..
@@ -792,7 +792,7 @@ impl MacroArgParser {
792792
&mut self,
793793
inner: Vec<ParsedMacroArg>,
794794
delim: Delimiter,
795-
iter: &mut TokenTreeCursor,
795+
iter: &mut RefTokenTreeCursor<'_>,
796796
) -> Option<()> {
797797
let mut buffer = String::new();
798798
let mut first = true;
@@ -892,11 +892,11 @@ impl MacroArgParser {
892892

893893
/// Returns a collection of parsed macro def's arguments.
894894
fn parse(mut self, tokens: TokenStream) -> Option<Vec<ParsedMacroArg>> {
895-
let mut iter = tokens.into_trees();
895+
let mut iter = tokens.trees();
896896

897897
while let Some(tok) = iter.next() {
898898
match tok {
899-
TokenTree::Token(
899+
&TokenTree::Token(
900900
Token {
901901
kind: TokenKind::Dollar,
902902
span,
@@ -925,7 +925,7 @@ impl MacroArgParser {
925925
self.add_meta_variable(&mut iter)?;
926926
}
927927
TokenTree::Token(ref t, _) => self.update_buffer(t),
928-
TokenTree::Delimited(_delimited_span, delimited, ref tts) => {
928+
&TokenTree::Delimited(_delimited_span, delimited, ref tts) => {
929929
if !self.buf.is_empty() {
930930
if next_space(&self.last_tok.kind) == SpaceState::Always {
931931
self.add_separator();
@@ -1143,12 +1143,12 @@ pub(crate) fn macro_style(mac: &ast::MacCall, context: &RewriteContext<'_>) -> D
11431143

11441144
// A very simple parser that just parses a macros 2.0 definition into its branches.
11451145
// Currently we do not attempt to parse any further than that.
1146-
struct MacroParser {
1147-
toks: TokenTreeCursor,
1146+
struct MacroParser<'a> {
1147+
toks: RefTokenTreeCursor<'a>,
11481148
}
11491149

1150-
impl MacroParser {
1151-
const fn new(toks: TokenTreeCursor) -> Self {
1150+
impl<'a> MacroParser<'a> {
1151+
const fn new(toks: RefTokenTreeCursor<'a>) -> Self {
11521152
Self { toks }
11531153
}
11541154

@@ -1167,9 +1167,9 @@ impl MacroParser {
11671167
let tok = self.toks.next()?;
11681168
let (lo, args_paren_kind) = match tok {
11691169
TokenTree::Token(..) => return None,
1170-
TokenTree::Delimited(delimited_span, d, _) => (delimited_span.open.lo(), d),
1170+
&TokenTree::Delimited(delimited_span, d, _) => (delimited_span.open.lo(), d),
11711171
};
1172-
let args = TokenStream::new(vec![tok]);
1172+
let args = TokenStream::new(vec![tok.clone()]);
11731173
match self.toks.next()? {
11741174
TokenTree::Token(
11751175
Token {

src/matches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ fn can_flatten_block_around_this(body: &ast::Expr) -> bool {
605605
ast::ExprKind::AddrOf(_, _, ref expr)
606606
| ast::ExprKind::Try(ref expr)
607607
| ast::ExprKind::Unary(_, ref expr)
608-
| ast::ExprKind::Index(ref expr, _)
608+
| ast::ExprKind::Index(ref expr, _, _)
609609
| ast::ExprKind::Cast(ref expr, _) => can_flatten_block_around_this(expr),
610610
_ => false,
611611
}

src/pairs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl<'a, 'b> PairList<'a, 'b, ast::Expr> {
274274
fn let_chain_count(&self) -> usize {
275275
self.list
276276
.iter()
277-
.filter(|(expr, _)| matches!(expr.kind, ast::ExprKind::Let(_, _, _)))
277+
.filter(|(expr, _)| matches!(expr.kind, ast::ExprKind::Let(..)))
278278
.count()
279279
}
280280

@@ -284,7 +284,7 @@ impl<'a, 'b> PairList<'a, 'b, ast::Expr> {
284284
}
285285

286286
let fist_item_is_ident = is_ident(self.list[0].0);
287-
let second_item_is_let_chain = matches!(self.list[1].0.kind, ast::ExprKind::Let(_, _, _));
287+
let second_item_is_let_chain = matches!(self.list[1].0.kind, ast::ExprKind::Let(..));
288288

289289
fist_item_is_ident && second_item_is_let_chain
290290
}

src/parse/macros/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
5656
);
5757
parse_macro_arg!(
5858
Pat,
59-
|parser: &mut rustc_parse::parser::Parser<'b>| parser.parse_pat_no_top_alt(None),
59+
|parser: &mut rustc_parse::parser::Parser<'b>| parser.parse_pat_no_top_alt(None, None),
6060
|x: ptr::P<ast::Pat>| Some(x)
6161
);
6262
// `parse_item` returns `Option<ptr::P<ast::Item>>`.

src/parse/session.rs

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::path::Path;
22
use std::sync::atomic::{AtomicBool, Ordering};
33

4-
use rustc_data_structures::sync::{Lrc, Send};
5-
use rustc_errors::emitter::{Emitter, EmitterWriter};
4+
use rustc_data_structures::sync::{IntoDynSyncSend, Lrc};
5+
use rustc_errors::emitter::{DynEmitter, Emitter, EmitterWriter};
66
use rustc_errors::translation::Translate;
7-
use rustc_errors::{ColorConfig, Diagnostic, Handler, Level as DiagnosticLevel, TerminalUrl};
7+
use rustc_errors::{ColorConfig, Diagnostic, Handler, Level as DiagnosticLevel};
88
use rustc_session::parse::ParseSess as RawParseSess;
99
use rustc_span::{
1010
source_map::{FilePathMapping, SourceMap},
@@ -48,15 +48,15 @@ impl Emitter for SilentEmitter {
4848
fn emit_diagnostic(&mut self, _db: &Diagnostic) {}
4949
}
5050

51-
fn silent_emitter() -> Box<dyn Emitter + Send> {
51+
fn silent_emitter() -> Box<DynEmitter> {
5252
Box::new(SilentEmitter {})
5353
}
5454

5555
/// Emit errors against every files expect ones specified in the `ignore_path_set`.
5656
struct SilentOnIgnoredFilesEmitter {
57-
ignore_path_set: Lrc<IgnorePathSet>,
57+
ignore_path_set: IntoDynSyncSend<Lrc<IgnorePathSet>>,
5858
source_map: Lrc<SourceMap>,
59-
emitter: Box<dyn Emitter + Send>,
59+
emitter: Box<DynEmitter>,
6060
has_non_ignorable_parser_errors: bool,
6161
can_reset: Lrc<AtomicBool>,
6262
}
@@ -139,30 +139,15 @@ fn default_handler(
139139
rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
140140
false,
141141
);
142-
Box::new(EmitterWriter::stderr(
143-
emit_color,
144-
Some(source_map.clone()),
145-
None,
146-
fallback_bundle,
147-
false,
148-
false,
149-
None,
150-
false,
151-
false,
152-
TerminalUrl::No,
153-
))
142+
Box::new(EmitterWriter::stderr(emit_color, fallback_bundle).sm(Some(source_map.clone())))
154143
};
155-
Handler::with_emitter(
156-
true,
157-
None,
158-
Box::new(SilentOnIgnoredFilesEmitter {
159-
has_non_ignorable_parser_errors: false,
160-
source_map,
161-
emitter,
162-
ignore_path_set,
163-
can_reset,
164-
}),
165-
)
144+
Handler::with_emitter(Box::new(SilentOnIgnoredFilesEmitter {
145+
has_non_ignorable_parser_errors: false,
146+
source_map,
147+
emitter,
148+
ignore_path_set: IntoDynSyncSend(ignore_path_set),
149+
can_reset,
150+
}))
166151
}
167152

168153
impl ParseSess {
@@ -233,7 +218,7 @@ impl ParseSess {
233218
}
234219

235220
pub(crate) fn set_silent_emitter(&mut self) {
236-
self.parse_sess.span_diagnostic = Handler::with_emitter(true, None, silent_emitter());
221+
self.parse_sess.span_diagnostic = Handler::with_emitter(silent_emitter());
237222
}
238223

239224
pub(crate) fn span_to_filename(&self, span: Span) -> FileName {
@@ -283,7 +268,7 @@ impl ParseSess {
283268
let source_file = self.parse_sess.source_map().lookup_char_pos(span.lo()).file;
284269
SnippetProvider::new(
285270
source_file.start_pos,
286-
source_file.end_pos,
271+
source_file.end_position(),
287272
Lrc::clone(source_file.src.as_ref().unwrap()),
288273
)
289274
}
@@ -410,7 +395,7 @@ mod tests {
410395
has_non_ignorable_parser_errors: false,
411396
source_map,
412397
emitter: Box::new(emitter_writer),
413-
ignore_path_set,
398+
ignore_path_set: IntoDynSyncSend(ignore_path_set),
414399
can_reset,
415400
}
416401
}

src/test/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,10 @@ fn handle_result(
834834

835835
// Ignore LF and CRLF difference for Windows.
836836
if !string_eq_ignore_newline_repr(&fmt_text, &text) {
837+
if std::env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0") {
838+
std::fs::write(file_name, fmt_text).unwrap();
839+
continue;
840+
}
837841
let diff = make_diff(&text, &fmt_text, DIFF_CONTEXT_SIZE);
838842
assert!(
839843
!diff.is_empty(),

0 commit comments

Comments
 (0)