Merge pull request #5944 from calebcartwright/subtree-sync-2023-10-22
sync subtree
This commit is contained in:
commit
0bb2acf50f
20 changed files with 111 additions and 85 deletions
|
@ -81,7 +81,11 @@
|
||||||
- Support for formatting let-else statements [#5690]
|
- 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]
|
- 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
|
[#5690]: https://github.com/rust-lang/rustfmt/pull/5690
|
||||||
|
>>>>>>> upstream/master
|
||||||
[#5684]: https://github.com/rust-lang/rustfmt/issues/5684
|
[#5684]: https://github.com/rust-lang/rustfmt/issues/5684
|
||||||
|
|
||||||
## [1.5.3] 2023-06-20
|
## [1.5.3] 2023-06-20
|
||||||
|
@ -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)
|
- 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)
|
- 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)
|
- 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.
|
- 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)
|
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:
|
- 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:
|
||||||
|
|
28
Cargo.lock
generated
28
Cargo.lock
generated
|
@ -98,11 +98,11 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytecount"
|
name = "bytecount"
|
||||||
version = "0.6.3"
|
version = "0.6.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2c676a478f63e9fa2dd5368a42f28bba0d6c560b775f38583c8bbaa7fcd67c9c"
|
checksum = "ad152d03a2c813c80bb94fedbf3a3f02b28f793e39e7c214c8a0bcc196343de7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"packed_simd_2",
|
"packed_simd",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -370,9 +370,9 @@ checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libm"
|
name = "libm"
|
||||||
version = "0.1.4"
|
version = "0.2.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a"
|
checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
|
@ -408,6 +408,16 @@ dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.2.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"libm",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.17.1"
|
version = "1.17.1"
|
||||||
|
@ -421,13 +431,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
|
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "packed_simd_2"
|
name = "packed_simd"
|
||||||
version = "0.3.8"
|
version = "0.3.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a1914cd452d8fccd6f9db48147b29fd4ae05bea9dc5d9ad578509f72415de282"
|
checksum = "1f9f08af0c877571712e2e3e686ad79efad9657dbf0f7c3c8ba943ff6c38932d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"libm",
|
"num-traits",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -35,7 +35,7 @@ generic-simd = ["bytecount/generic-simd"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
annotate-snippets = { version = "0.9", features = ["color"] }
|
annotate-snippets = { version = "0.9", features = ["color"] }
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
bytecount = "0.6.3"
|
bytecount = "0.6.4"
|
||||||
cargo_metadata = "0.15.4"
|
cargo_metadata = "0.15.4"
|
||||||
clap = { version = "4.4.2", features = ["derive"] }
|
clap = { version = "4.4.2", features = ["derive"] }
|
||||||
clap-cargo = "0.12.0"
|
clap-cargo = "0.12.0"
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "nightly-2023-07-01"
|
channel = "nightly-2023-10-22"
|
||||||
components = ["llvm-tools", "rustc-dev"]
|
components = ["llvm-tools", "rustc-dev"]
|
||||||
|
|
16
src/expr.rs
16
src/expr.rs
|
@ -132,7 +132,7 @@ pub(crate) fn format_expr(
|
||||||
ast::ExprKind::Tup(ref items) => {
|
ast::ExprKind::Tup(ref items) => {
|
||||||
rewrite_tuple(context, items.iter(), expr.span, shape, items.len() == 1)
|
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::If(..)
|
||||||
| ast::ExprKind::ForLoop(..)
|
| ast::ExprKind::ForLoop(..)
|
||||||
| ast::ExprKind::Loop(..)
|
| ast::ExprKind::Loop(..)
|
||||||
|
@ -261,7 +261,7 @@ pub(crate) fn format_expr(
|
||||||
shape,
|
shape,
|
||||||
SeparatorPlace::Back,
|
SeparatorPlace::Back,
|
||||||
),
|
),
|
||||||
ast::ExprKind::Index(ref expr, ref index) => {
|
ast::ExprKind::Index(ref expr, ref index, _) => {
|
||||||
rewrite_index(&**expr, &**index, context, shape)
|
rewrite_index(&**expr, &**index, context, shape)
|
||||||
}
|
}
|
||||||
ast::ExprKind::Repeat(ref expr, ref repeats) => rewrite_pair(
|
ast::ExprKind::Repeat(ref expr, ref repeats) => rewrite_pair(
|
||||||
|
@ -662,7 +662,7 @@ struct ControlFlow<'a> {
|
||||||
|
|
||||||
fn extract_pats_and_cond(expr: &ast::Expr) -> (Option<&ast::Pat>, &ast::Expr) {
|
fn extract_pats_and_cond(expr: &ast::Expr) -> (Option<&ast::Pat>, &ast::Expr) {
|
||||||
match expr.kind {
|
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),
|
_ => (None, expr),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1339,7 +1339,7 @@ pub(crate) fn is_simple_expr(expr: &ast::Expr) -> bool {
|
||||||
| ast::ExprKind::Field(ref expr, _)
|
| ast::ExprKind::Field(ref expr, _)
|
||||||
| ast::ExprKind::Try(ref expr)
|
| ast::ExprKind::Try(ref expr)
|
||||||
| ast::ExprKind::Unary(_, ref expr) => is_simple_expr(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) => {
|
ast::ExprKind::Repeat(ref lhs, ref rhs) => {
|
||||||
is_simple_expr(lhs) && is_simple_expr(&*rhs.value)
|
is_simple_expr(lhs) && is_simple_expr(&*rhs.value)
|
||||||
}
|
}
|
||||||
|
@ -1379,12 +1379,8 @@ pub(crate) fn can_be_overflowed_expr(
|
||||||
|| (context.use_block_indent() && args_len == 1)
|
|| (context.use_block_indent() && args_len == 1)
|
||||||
}
|
}
|
||||||
ast::ExprKind::MacCall(ref mac) => {
|
ast::ExprKind::MacCall(ref mac) => {
|
||||||
match (
|
match (mac.args.delim, context.config.overflow_delimited_expr()) {
|
||||||
rustc_ast::ast::MacDelimiter::from_token(mac.args.delim.to_token()),
|
(Delimiter::Bracket, true) | (Delimiter::Brace, true) => true,
|
||||||
context.config.overflow_delimited_expr(),
|
|
||||||
) {
|
|
||||||
(Some(ast::MacDelimiter::Bracket), true)
|
|
||||||
| (Some(ast::MacDelimiter::Brace), true) => true,
|
|
||||||
_ => context.use_block_indent() && args_len == 1,
|
_ => context.use_block_indent() && args_len == 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2608,7 +2608,8 @@ fn rewrite_fn_base(
|
||||||
if where_clause_str.is_empty() {
|
if where_clause_str.is_empty() {
|
||||||
if let ast::FnRetTy::Default(ret_span) = fd.output {
|
if let ast::FnRetTy::Default(ret_span) = fd.output {
|
||||||
match recover_missing_comment_in_span(
|
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,
|
shape,
|
||||||
context,
|
context,
|
||||||
last_line_width(&result),
|
last_line_width(&result),
|
||||||
|
|
|
@ -13,7 +13,7 @@ use std::collections::HashMap;
|
||||||
use std::panic::{catch_unwind, AssertUnwindSafe};
|
use std::panic::{catch_unwind, AssertUnwindSafe};
|
||||||
|
|
||||||
use rustc_ast::token::{BinOpToken, Delimiter, Token, TokenKind};
|
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::{ast, ptr};
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_span::{
|
use rustc_span::{
|
||||||
|
@ -411,7 +411,7 @@ pub(crate) fn rewrite_macro_def(
|
||||||
}
|
}
|
||||||
|
|
||||||
let ts = def.body.tokens.clone();
|
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() {
|
let parsed_def = match parser.parse() {
|
||||||
Some(def) => def,
|
Some(def) => def,
|
||||||
None => return snippet,
|
None => return snippet,
|
||||||
|
@ -760,9 +760,9 @@ impl MacroArgParser {
|
||||||
self.buf.clear();
|
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() {
|
match iter.next() {
|
||||||
Some(TokenTree::Token(
|
Some(&TokenTree::Token(
|
||||||
Token {
|
Token {
|
||||||
kind: TokenKind::Ident(name, _),
|
kind: TokenKind::Ident(name, _),
|
||||||
..
|
..
|
||||||
|
@ -792,7 +792,7 @@ impl MacroArgParser {
|
||||||
&mut self,
|
&mut self,
|
||||||
inner: Vec<ParsedMacroArg>,
|
inner: Vec<ParsedMacroArg>,
|
||||||
delim: Delimiter,
|
delim: Delimiter,
|
||||||
iter: &mut TokenTreeCursor,
|
iter: &mut RefTokenTreeCursor<'_>,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
let mut buffer = String::new();
|
let mut buffer = String::new();
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
|
@ -892,11 +892,11 @@ impl MacroArgParser {
|
||||||
|
|
||||||
/// Returns a collection of parsed macro def's arguments.
|
/// Returns a collection of parsed macro def's arguments.
|
||||||
fn parse(mut self, tokens: TokenStream) -> Option<Vec<ParsedMacroArg>> {
|
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() {
|
while let Some(tok) = iter.next() {
|
||||||
match tok {
|
match tok {
|
||||||
TokenTree::Token(
|
&TokenTree::Token(
|
||||||
Token {
|
Token {
|
||||||
kind: TokenKind::Dollar,
|
kind: TokenKind::Dollar,
|
||||||
span,
|
span,
|
||||||
|
@ -925,7 +925,7 @@ impl MacroArgParser {
|
||||||
self.add_meta_variable(&mut iter)?;
|
self.add_meta_variable(&mut iter)?;
|
||||||
}
|
}
|
||||||
TokenTree::Token(ref t, _) => self.update_buffer(t),
|
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 !self.buf.is_empty() {
|
||||||
if next_space(&self.last_tok.kind) == SpaceState::Always {
|
if next_space(&self.last_tok.kind) == SpaceState::Always {
|
||||||
self.add_separator();
|
self.add_separator();
|
||||||
|
@ -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.
|
// 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.
|
// Currently we do not attempt to parse any further than that.
|
||||||
struct MacroParser {
|
struct MacroParser<'a> {
|
||||||
toks: TokenTreeCursor,
|
toks: RefTokenTreeCursor<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MacroParser {
|
impl<'a> MacroParser<'a> {
|
||||||
const fn new(toks: TokenTreeCursor) -> Self {
|
const fn new(toks: RefTokenTreeCursor<'a>) -> Self {
|
||||||
Self { toks }
|
Self { toks }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1167,9 +1167,9 @@ impl MacroParser {
|
||||||
let tok = self.toks.next()?;
|
let tok = self.toks.next()?;
|
||||||
let (lo, args_paren_kind) = match tok {
|
let (lo, args_paren_kind) = match tok {
|
||||||
TokenTree::Token(..) => return None,
|
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()? {
|
match self.toks.next()? {
|
||||||
TokenTree::Token(
|
TokenTree::Token(
|
||||||
Token {
|
Token {
|
||||||
|
|
|
@ -605,7 +605,7 @@ fn can_flatten_block_around_this(body: &ast::Expr) -> bool {
|
||||||
ast::ExprKind::AddrOf(_, _, ref expr)
|
ast::ExprKind::AddrOf(_, _, ref expr)
|
||||||
| ast::ExprKind::Try(ref expr)
|
| ast::ExprKind::Try(ref expr)
|
||||||
| ast::ExprKind::Unary(_, 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),
|
| ast::ExprKind::Cast(ref expr, _) => can_flatten_block_around_this(expr),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
|
|
@ -274,7 +274,7 @@ impl<'a, 'b> PairList<'a, 'b, ast::Expr> {
|
||||||
fn let_chain_count(&self) -> usize {
|
fn let_chain_count(&self) -> usize {
|
||||||
self.list
|
self.list
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(expr, _)| matches!(expr.kind, ast::ExprKind::Let(_, _, _)))
|
.filter(|(expr, _)| matches!(expr.kind, ast::ExprKind::Let(..)))
|
||||||
.count()
|
.count()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ impl<'a, 'b> PairList<'a, 'b, ast::Expr> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let fist_item_is_ident = is_ident(self.list[0].0);
|
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
|
fist_item_is_ident && second_item_is_let_chain
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
|
||||||
);
|
);
|
||||||
parse_macro_arg!(
|
parse_macro_arg!(
|
||||||
Pat,
|
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)
|
|x: ptr::P<ast::Pat>| Some(x)
|
||||||
);
|
);
|
||||||
// `parse_item` returns `Option<ptr::P<ast::Item>>`.
|
// `parse_item` returns `Option<ptr::P<ast::Item>>`.
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
|
||||||
use rustc_data_structures::sync::{Lrc, Send};
|
use rustc_data_structures::sync::{IntoDynSyncSend, Lrc};
|
||||||
use rustc_errors::emitter::{Emitter, EmitterWriter};
|
use rustc_errors::emitter::{DynEmitter, Emitter, EmitterWriter};
|
||||||
use rustc_errors::translation::Translate;
|
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_session::parse::ParseSess as RawParseSess;
|
||||||
use rustc_span::{
|
use rustc_span::{
|
||||||
source_map::{FilePathMapping, SourceMap},
|
source_map::{FilePathMapping, SourceMap},
|
||||||
|
@ -48,15 +48,15 @@ impl Emitter for SilentEmitter {
|
||||||
fn emit_diagnostic(&mut self, _db: &Diagnostic) {}
|
fn emit_diagnostic(&mut self, _db: &Diagnostic) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn silent_emitter() -> Box<dyn Emitter + Send> {
|
fn silent_emitter() -> Box<DynEmitter> {
|
||||||
Box::new(SilentEmitter {})
|
Box::new(SilentEmitter {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Emit errors against every files expect ones specified in the `ignore_path_set`.
|
/// Emit errors against every files expect ones specified in the `ignore_path_set`.
|
||||||
struct SilentOnIgnoredFilesEmitter {
|
struct SilentOnIgnoredFilesEmitter {
|
||||||
ignore_path_set: Lrc<IgnorePathSet>,
|
ignore_path_set: IntoDynSyncSend<Lrc<IgnorePathSet>>,
|
||||||
source_map: Lrc<SourceMap>,
|
source_map: Lrc<SourceMap>,
|
||||||
emitter: Box<dyn Emitter + Send>,
|
emitter: Box<DynEmitter>,
|
||||||
has_non_ignorable_parser_errors: bool,
|
has_non_ignorable_parser_errors: bool,
|
||||||
can_reset: Lrc<AtomicBool>,
|
can_reset: Lrc<AtomicBool>,
|
||||||
}
|
}
|
||||||
|
@ -139,30 +139,15 @@ fn default_handler(
|
||||||
rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
|
rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
Box::new(EmitterWriter::stderr(
|
Box::new(EmitterWriter::stderr(emit_color, fallback_bundle).sm(Some(source_map.clone())))
|
||||||
emit_color,
|
|
||||||
Some(source_map.clone()),
|
|
||||||
None,
|
|
||||||
fallback_bundle,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
None,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
TerminalUrl::No,
|
|
||||||
))
|
|
||||||
};
|
};
|
||||||
Handler::with_emitter(
|
Handler::with_emitter(Box::new(SilentOnIgnoredFilesEmitter {
|
||||||
true,
|
|
||||||
None,
|
|
||||||
Box::new(SilentOnIgnoredFilesEmitter {
|
|
||||||
has_non_ignorable_parser_errors: false,
|
has_non_ignorable_parser_errors: false,
|
||||||
source_map,
|
source_map,
|
||||||
emitter,
|
emitter,
|
||||||
ignore_path_set,
|
ignore_path_set: IntoDynSyncSend(ignore_path_set),
|
||||||
can_reset,
|
can_reset,
|
||||||
}),
|
}))
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParseSess {
|
impl ParseSess {
|
||||||
|
@ -233,7 +218,7 @@ impl ParseSess {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_silent_emitter(&mut self) {
|
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 {
|
pub(crate) fn span_to_filename(&self, span: Span) -> FileName {
|
||||||
|
@ -283,7 +268,7 @@ impl ParseSess {
|
||||||
let source_file = self.parse_sess.source_map().lookup_char_pos(span.lo()).file;
|
let source_file = self.parse_sess.source_map().lookup_char_pos(span.lo()).file;
|
||||||
SnippetProvider::new(
|
SnippetProvider::new(
|
||||||
source_file.start_pos,
|
source_file.start_pos,
|
||||||
source_file.end_pos,
|
source_file.end_position(),
|
||||||
Lrc::clone(source_file.src.as_ref().unwrap()),
|
Lrc::clone(source_file.src.as_ref().unwrap()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -410,7 +395,7 @@ mod tests {
|
||||||
has_non_ignorable_parser_errors: false,
|
has_non_ignorable_parser_errors: false,
|
||||||
source_map,
|
source_map,
|
||||||
emitter: Box::new(emitter_writer),
|
emitter: Box::new(emitter_writer),
|
||||||
ignore_path_set,
|
ignore_path_set: IntoDynSyncSend(ignore_path_set),
|
||||||
can_reset,
|
can_reset,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -834,6 +834,10 @@ fn handle_result(
|
||||||
|
|
||||||
// Ignore LF and CRLF difference for Windows.
|
// Ignore LF and CRLF difference for Windows.
|
||||||
if !string_eq_ignore_newline_repr(&fmt_text, &text) {
|
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);
|
let diff = make_diff(&text, &fmt_text, DIFF_CONTEXT_SIZE);
|
||||||
assert!(
|
assert!(
|
||||||
!diff.is_empty(),
|
!diff.is_empty(),
|
||||||
|
|
|
@ -816,6 +816,8 @@ impl Rewrite for ast::Ty {
|
||||||
ast::TyKind::Tup(ref items) => {
|
ast::TyKind::Tup(ref items) => {
|
||||||
rewrite_tuple(context, items.iter(), self.span, shape, items.len() == 1)
|
rewrite_tuple(context, items.iter(), self.span, shape, items.len() == 1)
|
||||||
}
|
}
|
||||||
|
ast::TyKind::AnonStruct(_) => Some(context.snippet(self.span).to_owned()),
|
||||||
|
ast::TyKind::AnonUnion(_) => Some(context.snippet(self.span).to_owned()),
|
||||||
ast::TyKind::Path(ref q_self, ref path) => {
|
ast::TyKind::Path(ref q_self, ref path) => {
|
||||||
rewrite_path(context, PathContext::Type, q_self, path, shape)
|
rewrite_path(context, PathContext::Type, q_self, path, shape)
|
||||||
}
|
}
|
||||||
|
|
|
@ -442,7 +442,7 @@ pub(crate) fn left_most_sub_expr(e: &ast::Expr) -> &ast::Expr {
|
||||||
| ast::ExprKind::Assign(ref e, _, _)
|
| ast::ExprKind::Assign(ref e, _, _)
|
||||||
| ast::ExprKind::AssignOp(_, ref e, _)
|
| ast::ExprKind::AssignOp(_, ref e, _)
|
||||||
| ast::ExprKind::Field(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::Range(Some(ref e), _, _)
|
||||||
| ast::ExprKind::Try(ref e) => left_most_sub_expr(e),
|
| ast::ExprKind::Try(ref e) => left_most_sub_expr(e),
|
||||||
_ => e,
|
_ => e,
|
||||||
|
@ -480,7 +480,7 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
|
||||||
| ast::ExprKind::Match(..) => repr.contains('\n'),
|
| ast::ExprKind::Match(..) => repr.contains('\n'),
|
||||||
ast::ExprKind::Paren(ref expr)
|
ast::ExprKind::Paren(ref expr)
|
||||||
| ast::ExprKind::Binary(_, _, ref expr)
|
| ast::ExprKind::Binary(_, _, ref expr)
|
||||||
| ast::ExprKind::Index(_, ref expr)
|
| ast::ExprKind::Index(_, ref expr, _)
|
||||||
| ast::ExprKind::Unary(_, ref expr)
|
| ast::ExprKind::Unary(_, ref expr)
|
||||||
| ast::ExprKind::Try(ref expr)
|
| ast::ExprKind::Try(ref expr)
|
||||||
| ast::ExprKind::Yield(Some(ref expr)) => is_block_expr(context, expr, repr),
|
| ast::ExprKind::Yield(Some(ref expr)) => is_block_expr(context, expr, repr),
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#![feature(generators)]
|
#![feature(coroutines)]
|
||||||
|
|
||||||
unsafe fn foo() {
|
unsafe fn foo() {
|
||||||
let mut ga = static || {
|
let mut ga = static || {
|
|
@ -5,11 +5,11 @@ fn main() {
|
||||||
|
|
||||||
if aaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaa && aaaaaaaaa && let Some(x) = xxxxxxxxxxxx && aaaaaaa && let None = aaaaaaaaaa {}
|
if aaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaa && aaaaaaaaa && let Some(x) = xxxxxxxxxxxx && aaaaaaa && let None = aaaaaaaaaa {}
|
||||||
|
|
||||||
if aaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaa || aaaaaaaaa && let Some(x) = xxxxxxxxxxxx && aaaaaaa && let None = aaaaaaaaaa {}
|
if aaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaa && aaaaaaaaa && let Some(x) = xxxxxxxxxxxx && aaaaaaa && let None = aaaaaaaaaa {}
|
||||||
|
|
||||||
if let Some(Struct { x:TS(1,2) }) = path::to::<_>(hehe)
|
if let Some(Struct { x:TS(1,2) }) = path::to::<_>(hehe)
|
||||||
&& let [Simple, people] = /* get ready */ create_universe(/* hi */ GreatPowers).initialize_badminton().populate_swamps() &&
|
&& let [Simple, people] = /* get ready */ create_universe(/* hi */ GreatPowers).initialize_badminton().populate_swamps() &&
|
||||||
let everybody = (Loops { hi /*hi*/ , ..loopy() }) || summons::triumphantly() { todo!() }
|
let everybody = (Loops { hi /*hi*/ , ..loopy() }) && summons::triumphantly() { todo!() }
|
||||||
|
|
||||||
if let XXXXXXXXX { xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyy, zzzzzzzzzzzzz} = xxxxxxx()
|
if let XXXXXXXXX { xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyy, zzzzzzzzzzzzz} = xxxxxxx()
|
||||||
&& let Foo = bar() { todo!() }
|
&& let Foo = bar() { todo!() }
|
||||||
|
|
19
tests/target/anonymous-types.rs
Normal file
19
tests/target/anonymous-types.rs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
// Test for issue 85480
|
||||||
|
// Pretty print anonymous struct and union types
|
||||||
|
|
||||||
|
// pp-exact
|
||||||
|
// pretty-compare-only
|
||||||
|
|
||||||
|
struct Foo {
|
||||||
|
_: union {
|
||||||
|
_: struct {
|
||||||
|
a: u8,
|
||||||
|
b: u16,
|
||||||
|
},
|
||||||
|
c: u32,
|
||||||
|
},
|
||||||
|
d: u64,
|
||||||
|
e: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -1,4 +1,4 @@
|
||||||
#![feature(generators)]
|
#![feature(coroutines)]
|
||||||
|
|
||||||
unsafe fn foo() {
|
unsafe fn foo() {
|
||||||
let mut ga = static || {
|
let mut ga = static || {
|
|
@ -12,7 +12,7 @@ fn bindings() {
|
||||||
span,
|
span,
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
) if borrow_spans.for_generator() | borrow_spans.for_closure() => self
|
) if borrow_spans.for_coroutine() | borrow_spans.for_closure() => self
|
||||||
.report_escaping_closure_capture(
|
.report_escaping_closure_capture(
|
||||||
borrow_spans,
|
borrow_spans,
|
||||||
borrow_span,
|
borrow_span,
|
||||||
|
|
|
@ -13,8 +13,9 @@ fn main() {
|
||||||
&& let None = aaaaaaaaaa
|
&& let None = aaaaaaaaaa
|
||||||
{}
|
{}
|
||||||
|
|
||||||
if aaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaa
|
if aaaaaaaaaaaaaaaaaaaaa
|
||||||
|| aaaaaaaaa
|
&& aaaaaaaaaaaaaaa
|
||||||
|
&& aaaaaaaaa
|
||||||
&& let Some(x) = xxxxxxxxxxxx
|
&& let Some(x) = xxxxxxxxxxxx
|
||||||
&& aaaaaaa
|
&& aaaaaaa
|
||||||
&& let None = aaaaaaaaaa
|
&& let None = aaaaaaaaaa
|
||||||
|
@ -29,7 +30,7 @@ fn main() {
|
||||||
hi, /*hi*/
|
hi, /*hi*/
|
||||||
..loopy()
|
..loopy()
|
||||||
})
|
})
|
||||||
|| summons::triumphantly()
|
&& summons::triumphantly()
|
||||||
{
|
{
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue