Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync subtree #5944

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
dc7dc3e
Implement `become` expression formatting in rustfmt
WaffleLapkin May 9, 2023
ed3e96e
Merge commit '3f7c366fc0464e01ddcaefbd70647cb3da4202be' into rustfmt-…
calebcartwright Jun 20, 2023
80bf3ea
Rollup merge of #112790 - WaffleLapkin:syntactically, r=Nilstrieb
Noratrieb Jun 21, 2023
78331ee
Merge commit 'dca1cf90ad6b8e45afbed2061803befbb2d159e9' into sync-rus…
calebcartwright Jul 1, 2023
d0762f0
always emit consider `AutoImplCandidates` for them if they don't also…
Ddystopia Jul 4, 2023
6013a80
On nightly, dump ICE backtraces to disk
estebank Mar 3, 2023
a3dfd82
Use a builder instead of boolean/option arguments
oli-obk Jul 25, 2023
c0ee8f5
Make `x test src/tools/rustfmt --bless` format rustfmt with the fresh…
oli-obk Jul 26, 2023
08fd164
Unite bless environment variables under `RUSTC_BLESS`
tgross35 Jul 3, 2023
e60a9e2
Avoid `into_trees` usage in rustfmt.
nnethercote Jul 27, 2023
1f369f8
Auto merge of #114115 - nnethercote:less-token-tree-cloning, r=petroc…
bors Jul 28, 2023
4eeecae
Auto merge of #113312 - Ddystopia:auto-trait-fun, r=lcnr
bors Jul 28, 2023
f122a33
Use builder pattern instead of lots of arguments for `EmitterWriter::…
oli-obk Jul 25, 2023
e42bc9e
Fix rustfmt dep
mu001999 Aug 2, 2023
d165d4a
Remove `MacDelimiter`.
nnethercote Aug 1, 2023
2c8cc96
Rollup merge of #114300 - MU001999:fix/turbofish-pat, r=estebank
matthiaskrgr Aug 3, 2023
e83a7ca
Improve spans for indexing expressions
Noratrieb Aug 3, 2023
e6c4606
Auto merge of #114104 - oli-obk:syn2, r=compiler-errors
bors Aug 4, 2023
af72b88
Rollup merge of #114434 - Nilstrieb:indexing-spans, r=est31
matthiaskrgr Aug 4, 2023
00b60cd
Auto merge of #114481 - matthiaskrgr:rollup-58pczpl, r=matthiaskrgr
bors Aug 4, 2023
cef3117
Parse unnamed fields and anonymous structs or unions
frank-king Aug 23, 2023
9c25fbf
Use conditional synchronization for Lock
Zoxc Oct 31, 2020
96e583f
Use relative positions inside a SourceFile.
cjgillot Sep 3, 2023
b8e3cb0
Update tools and fulldeps tests
matthewjasper Sep 8, 2023
8ac561a
Fix spans for comments in rustfmt
compiler-errors Oct 4, 2023
0f73981
s/generator/coroutine/
oli-obk Oct 19, 2023
4b5ef37
Rename lots of files that had `generator` in their name
oli-obk Oct 20, 2023
f35f252
Merge remote-tracking branch 'upstream/master' into subtree-sync-2023…
calebcartwright Oct 22, 2023
746bf48
chore: bump toolchain and apply minor updates
calebcartwright Oct 22, 2023
75d8497
deps: bump bytecount version
calebcartwright Oct 22, 2023
c2515df
tests: fix let chain tests
calebcartwright Oct 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@
- Support for formatting let-else statements [#5690]
- 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]

<<<<<<< HEAD
[#5690]: (https://github.com/rust-lang/rustfmt/pulls/5690)
=======
[#5690]: https://github.com/rust-lang/rustfmt/pull/5690
>>>>>>> upstream/master
[#5684]: https://github.com/rust-lang/rustfmt/issues/5684
Comment on lines +84 to 89
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh 🤮

I clearly got tired of merge conflicts. Mercifully this is just noise in the changelog, so i'll clean this up later when I add the additional entries

Copy link
Contributor

@ytmimi ytmimi Oct 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤣 I know you mentioned that there were a lot of conflicts. No worries on this!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaning up orphan processes


## [1.5.3] 2023-06-20
Expand All @@ -90,7 +94,11 @@

- When formatting doc comments with `wrap_comments = true` rustfmt will no longer wrap markdown tables [#4210](https://github.com/rust-lang/rustfmt/issues/4210)
- Properly handle wrapping comments that include a numbered list in markdown [#5416](https://github.com/rust-lang/rustfmt/issues/5416)
<<<<<<< HEAD
- Properly handle markdown sublists that utilize a `+` [#4041](https://github.com/rust-lang/rustfmt/issues/4210)
=======
- Properly handle markdown sublists that utilize a `+` [#4041](https://github.com/rust-lang/rustfmt/issues/4041)
>>>>>>> upstream/master
- 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.
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)
- 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:
Expand Down
28 changes: 19 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ generic-simd = ["bytecount/generic-simd"]
[dependencies]
annotate-snippets = { version = "0.9", features = ["color"] }
anyhow = "1.0"
bytecount = "0.6.3"
bytecount = "0.6.4"
cargo_metadata = "0.15.4"
clap = { version = "4.4.2", features = ["derive"] }
clap-cargo = "0.12.0"
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-07-01"
channel = "nightly-2023-10-22"
components = ["llvm-tools", "rustc-dev"]
16 changes: 6 additions & 10 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub(crate) fn format_expr(
ast::ExprKind::Tup(ref items) => {
rewrite_tuple(context, items.iter(), expr.span, shape, items.len() == 1)
}
ast::ExprKind::Let(ref pat, ref expr, _span) => rewrite_let(context, shape, pat, expr),
ast::ExprKind::Let(ref pat, ref expr, _span, _) => rewrite_let(context, shape, pat, expr),
ast::ExprKind::If(..)
| ast::ExprKind::ForLoop(..)
| ast::ExprKind::Loop(..)
Expand Down Expand Up @@ -261,7 +261,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(
Expand Down Expand Up @@ -662,7 +662,7 @@ struct ControlFlow<'a> {

fn extract_pats_and_cond(expr: &ast::Expr) -> (Option<&ast::Pat>, &ast::Expr) {
match expr.kind {
ast::ExprKind::Let(ref pat, ref cond, _) => (Some(pat), cond),
ast::ExprKind::Let(ref pat, ref cond, _, _) => (Some(pat), cond),
_ => (None, expr),
}
}
Expand Down Expand Up @@ -1339,7 +1339,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)
}
Expand Down Expand Up @@ -1379,12 +1379,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,
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2608,7 +2608,8 @@ fn rewrite_fn_base(
if where_clause_str.is_empty() {
if let ast::FnRetTy::Default(ret_span) = fd.output {
match recover_missing_comment_in_span(
mk_sp(params_span.hi(), ret_span.hi()),
// from after the closing paren to right before block or semicolon
mk_sp(ret_span.lo(), span.hi()),
shape,
context,
last_line_width(&result),
Expand Down
28 changes: 14 additions & 14 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -411,7 +411,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,
Expand Down Expand Up @@ -760,9 +760,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, _),
..
Expand Down Expand Up @@ -792,7 +792,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;
Expand Down Expand Up @@ -892,11 +892,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,
Expand Down Expand Up @@ -925,7 +925,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();
Expand Down Expand Up @@ -1143,12 +1143,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 }
}

Expand All @@ -1167,9 +1167,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 {
Expand Down
2 changes: 1 addition & 1 deletion src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,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,
}
Expand Down
4 changes: 2 additions & 2 deletions src/pairs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl<'a, 'b> PairList<'a, 'b, ast::Expr> {
fn let_chain_count(&self) -> usize {
self.list
.iter()
.filter(|(expr, _)| matches!(expr.kind, ast::ExprKind::Let(_, _, _)))
.filter(|(expr, _)| matches!(expr.kind, ast::ExprKind::Let(..)))
.count()
}

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

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

fist_item_is_ident && second_item_is_let_chain
}
Expand Down
2 changes: 1 addition & 1 deletion src/parse/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>`.
Expand Down
49 changes: 17 additions & 32 deletions src/parse/session.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::path::Path;
use std::sync::atomic::{AtomicBool, Ordering};

use rustc_data_structures::sync::{Lrc, Send};
use rustc_errors::emitter::{Emitter, EmitterWriter};
use rustc_data_structures::sync::{IntoDynSyncSend, Lrc};
use rustc_errors::emitter::{DynEmitter, 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},
Expand Down Expand Up @@ -48,15 +48,15 @@ impl Emitter for SilentEmitter {
fn emit_diagnostic(&mut self, _db: &Diagnostic) {}
}

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

/// Emit errors against every files expect ones specified in the `ignore_path_set`.
struct SilentOnIgnoredFilesEmitter {
ignore_path_set: Lrc<IgnorePathSet>,
ignore_path_set: IntoDynSyncSend<Lrc<IgnorePathSet>>,
source_map: Lrc<SourceMap>,
emitter: Box<dyn Emitter + Send>,
emitter: Box<DynEmitter>,
has_non_ignorable_parser_errors: bool,
can_reset: Lrc<AtomicBool>,
}
Expand Down Expand Up @@ -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: IntoDynSyncSend(ignore_path_set),
can_reset,
}))
}

impl ParseSess {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -283,7 +268,7 @@ impl ParseSess {
let source_file = self.parse_sess.source_map().lookup_char_pos(span.lo()).file;
SnippetProvider::new(
source_file.start_pos,
source_file.end_pos,
source_file.end_position(),
Lrc::clone(source_file.src.as_ref().unwrap()),
)
}
Expand Down Expand Up @@ -410,7 +395,7 @@ mod tests {
has_non_ignorable_parser_errors: false,
source_map,
emitter: Box::new(emitter_writer),
ignore_path_set,
ignore_path_set: IntoDynSyncSend(ignore_path_set),
can_reset,
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,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(),
Expand Down
Loading
Loading