Skip to content

Commit ec8a4d4

Browse files
Merge pull request #5788 from calebcartwright/subtree-sync-2023-06-19
sync subtree in prep for next release
2 parents f4201ef + 0b17d7e commit ec8a4d4

File tree

29 files changed

+126
-157
lines changed

29 files changed

+126
-157
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,32 @@
3737
- Prevent ICE when parsing invalid attributes in `cfg_if!` macros [#5728](https://github.com/rust-lang/rustfmt/issues/5728)
3838

3939

40+
## [1.5.2] 2023-01-24
41+
42+
### Fixed
43+
44+
- Resolve issue when comments are found within const generic defaults in unit structs [#5668](https://github.com/rust-lang/rustfmt/issues/5668)
45+
- Resolve issue when block comments are found within trait generics [#5358](https://github.com/rust-lang/rustfmt/issues/5358)
46+
- Correctly handle alignment of comments containing unicode characters [#5504](https://github.com/rust-lang/rustfmt/issues/5504)
47+
- Properly indent a single generic bound that requires being written across multiple lines [#4689](https://github.com/rust-lang/rustfmt/issues/4689) (n.b. this change is version gated and will only appear when the `version` configuration option is set to `Two`)
48+
49+
### Changed
50+
51+
- Renamed `fn_args_layout` configuration option to `fn_params_layout` [#4149](https://github.com/rust-lang/rustfmt/issues/4149). Note that `fn_args_layout` has only been soft deprecated: `fn_args_layout` will continue to work without issue, but rustfmt will display a warning to encourage users to switch to the new name
52+
53+
### Added
54+
55+
- New configuration option (`skip_macro_invocations`)[https://rust-lang.github.io/rustfmt/?version=master&search=#skip_macro_invocations] [#5347](https://github.com/rust-lang/rustfmt/pull/5347) that can be used to globally define a single enumerated list of macro calls that rustfmt should skip formatting. rustfmt [currently also supports this via a custom tool attribute](https://github.com/rust-lang/rustfmt#tips), however, these cannot be used in all contexts because [custom inner attributes are unstable](https://github.com/rust-lang/rust/issues/54726)
56+
57+
### Misc
58+
59+
- rustfmt now internally supports the ability to have both stable and unstable variants of a configuration option [#5378](https://github.com/rust-lang/rustfmt/issues/5378). This ability will allow the rustfmt team to make certain configuration options available on stable toolchains more quickly because we no longer have to wait for _every_ variant to be stable-ready before stabilizing _any_ variant.
60+
61+
### Install/Download Options
62+
- **rustup (nightly)** - nightly-2023-01-24
63+
- **GitHub Release Binaries** - [Release v1.5.2](https://github.com/rust-lang/rustfmt/releases/tag/v1.5.2)
64+
- **Build from source** - [Tag v1.5.2](https://github.com/rust-lang/rustfmt/tree/v1.5.2), see instructions for how to [install rustfmt from source][install-from-source]
65+
4066
## [1.5.2] 2023-01-24
4167

4268
### Fixed

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-01-24"
2+
channel = "nightly-2023-06-19"
33
components = ["llvm-tools", "rustc-dev"]

src/attr.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use rustc_ast::ast;
44
use rustc_ast::HasAttrs;
5-
use rustc_span::{symbol::sym, Span, Symbol};
5+
use rustc_span::{symbol::sym, Span};
66

77
use self::doc_comment::DocCommentFormatter;
88
use crate::comment::{contains_comment, rewrite_doc_comment, CommentStyle};
@@ -19,20 +19,6 @@ use crate::utils::{count_newlines, mk_sp};
1919

2020
mod doc_comment;
2121

22-
pub(crate) fn contains_name(attrs: &[ast::Attribute], name: Symbol) -> bool {
23-
attrs.iter().any(|attr| attr.has_name(name))
24-
}
25-
26-
pub(crate) fn first_attr_value_str_by_name(
27-
attrs: &[ast::Attribute],
28-
name: Symbol,
29-
) -> Option<Symbol> {
30-
attrs
31-
.iter()
32-
.find(|attr| attr.has_name(name))
33-
.and_then(|attr| attr.value_str())
34-
}
35-
3622
/// Returns attributes on the given statement.
3723
pub(crate) fn get_attrs_from_stmt(stmt: &ast::Stmt) -> &[ast::Attribute] {
3824
stmt.attrs()

src/bin/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![feature(rustc_private)]
2+
13
use anyhow::{format_err, Result};
24

35
use io::Error as IoError;
@@ -19,7 +21,14 @@ use crate::rustfmt::{
1921
FormatReportFormatterBuilder, Input, Session, Verbosity,
2022
};
2123

24+
const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rustfmt/issues/new?labels=bug";
25+
26+
// N.B. these crates are loaded from the sysroot, so they need extern crate.
27+
extern crate rustc_driver;
28+
2229
fn main() {
30+
rustc_driver::install_ice_hook(BUG_REPORT_URL, |_| ());
31+
2332
env_logger::Builder::from_env("RUSTFMT_LOG").init();
2433
let opts = make_opts();
2534

src/chains.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ use crate::utils::{
7474
rewrite_ident, trimmed_last_line_width, wrap_str,
7575
};
7676

77+
use thin_vec::ThinVec;
78+
7779
/// Provides the original input contents from the span
7880
/// of a chain element with trailing spaces trimmed.
7981
fn format_overflow_style(span: Span, context: &RewriteContext<'_>) -> Option<String> {
@@ -168,7 +170,7 @@ enum ChainItemKind {
168170
MethodCall(
169171
ast::PathSegment,
170172
Vec<ast::GenericArg>,
171-
Vec<ptr::P<ast::Expr>>,
173+
ThinVec<ptr::P<ast::Expr>>,
172174
),
173175
StructField(symbol::Ident),
174176
TupleField(symbol::Ident, bool),
@@ -230,7 +232,7 @@ impl ChainItemKind {
230232
let span = mk_sp(nested.span.hi(), field.span.hi());
231233
(kind, span)
232234
}
233-
ast::ExprKind::Await(ref nested) => {
235+
ast::ExprKind::Await(ref nested, _) => {
234236
let span = mk_sp(nested.span.hi(), expr.span.hi());
235237
(ChainItemKind::Await, span)
236238
}
@@ -457,7 +459,7 @@ impl Chain {
457459
ast::ExprKind::MethodCall(ref call) => Some(Self::convert_try(&call.receiver, context)),
458460
ast::ExprKind::Field(ref subexpr, _)
459461
| ast::ExprKind::Try(ref subexpr)
460-
| ast::ExprKind::Await(ref subexpr) => Some(Self::convert_try(subexpr, context)),
462+
| ast::ExprKind::Await(ref subexpr, _) => Some(Self::convert_try(subexpr, context)),
461463
_ => None,
462464
}
463465
}

src/closures.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rustc_ast::{ast, ptr};
22
use rustc_span::Span;
3+
use thin_vec::thin_vec;
34

45
use crate::attr::get_attrs_from_stmt;
56
use crate::config::lists::*;
@@ -150,7 +151,7 @@ fn rewrite_closure_with_block(
150151
}
151152

152153
let block = ast::Block {
153-
stmts: vec![ast::Stmt {
154+
stmts: thin_vec![ast::Stmt {
154155
id: ast::NodeId::root(),
155156
kind: ast::StmtKind::Expr(ptr::P(body.clone())),
156157
span: body.span,
@@ -194,7 +195,6 @@ fn rewrite_closure_expr(
194195
| ast::ExprKind::Struct(..) => true,
195196

196197
ast::ExprKind::AddrOf(_, _, ref expr)
197-
| ast::ExprKind::Box(ref expr)
198198
| ast::ExprKind::Try(ref expr)
199199
| ast::ExprKind::Unary(_, ref expr)
200200
| ast::ExprKind::Cast(ref expr, _) => allow_multi_line(expr),
@@ -440,7 +440,6 @@ fn is_block_closure_forced_inner(expr: &ast::Expr, version: Version) -> bool {
440440
ast::ExprKind::If(..) | ast::ExprKind::While(..) | ast::ExprKind::ForLoop(..) => true,
441441
ast::ExprKind::Loop(..) if version == Version::Two => true,
442442
ast::ExprKind::AddrOf(_, _, ref expr)
443-
| ast::ExprKind::Box(ref expr)
444443
| ast::ExprKind::Try(ref expr)
445444
| ast::ExprKind::Unary(_, ref expr)
446445
| ast::ExprKind::Cast(ref expr, _) => is_block_closure_forced_inner(expr, version),

src/expr.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ pub(crate) fn format_expr(
218218
ast::ExprKind::Try(..)
219219
| ast::ExprKind::Field(..)
220220
| ast::ExprKind::MethodCall(..)
221-
| ast::ExprKind::Await(_) => rewrite_chain(expr, context, shape),
221+
| ast::ExprKind::Await(_, _) => rewrite_chain(expr, context, shape),
222222
ast::ExprKind::MacCall(ref mac) => {
223223
rewrite_macro(mac, None, context, shape, MacroPosition::Expression).or_else(|| {
224224
wrap_str(
@@ -236,7 +236,6 @@ pub(crate) fn format_expr(
236236
ast::ExprKind::Yeet(Some(ref expr)) => {
237237
rewrite_unary_prefix(context, "do yeet ", &**expr, shape)
238238
}
239-
ast::ExprKind::Box(ref expr) => rewrite_unary_prefix(context, "box ", &**expr, shape),
240239
ast::ExprKind::AddrOf(borrow_kind, mutability, ref expr) => {
241240
rewrite_expr_addrof(context, borrow_kind, mutability, expr, shape)
242241
}
@@ -367,7 +366,7 @@ pub(crate) fn format_expr(
367366
))
368367
}
369368
}
370-
ast::ExprKind::Async(capture_by, _node_id, ref block) => {
369+
ast::ExprKind::Async(capture_by, ref block) => {
371370
let mover = if capture_by == ast::CaptureBy::Value {
372371
"move "
373372
} else {
@@ -400,7 +399,12 @@ pub(crate) fn format_expr(
400399
}
401400
}
402401
ast::ExprKind::Underscore => Some("_".to_owned()),
403-
ast::ExprKind::IncludedBytes(..) => unreachable!(),
402+
ast::ExprKind::FormatArgs(..)
403+
| ast::ExprKind::IncludedBytes(..)
404+
| ast::ExprKind::OffsetOf(..) => {
405+
// These do not occur in the AST because macros aren't expanded.
406+
unreachable!()
407+
}
404408
ast::ExprKind::Err => None,
405409
};
406410

@@ -1296,7 +1300,6 @@ pub(crate) fn is_simple_expr(expr: &ast::Expr) -> bool {
12961300
ast::ExprKind::Lit(..) => true,
12971301
ast::ExprKind::Path(ref qself, ref path) => qself.is_none() && path.segments.len() <= 1,
12981302
ast::ExprKind::AddrOf(_, _, ref expr)
1299-
| ast::ExprKind::Box(ref expr)
13001303
| ast::ExprKind::Cast(ref expr, _)
13011304
| ast::ExprKind::Field(ref expr, _)
13021305
| ast::ExprKind::Try(ref expr)
@@ -1358,7 +1361,6 @@ pub(crate) fn can_be_overflowed_expr(
13581361

13591362
// Handle unary-like expressions
13601363
ast::ExprKind::AddrOf(_, _, ref expr)
1361-
| ast::ExprKind::Box(ref expr)
13621364
| ast::ExprKind::Try(ref expr)
13631365
| ast::ExprKind::Unary(_, ref expr)
13641366
| ast::ExprKind::Cast(ref expr, _) => can_be_overflowed_expr(context, expr, args_len),
@@ -1370,7 +1372,6 @@ pub(crate) fn is_nested_call(expr: &ast::Expr) -> bool {
13701372
match expr.kind {
13711373
ast::ExprKind::Call(..) | ast::ExprKind::MacCall(..) => true,
13721374
ast::ExprKind::AddrOf(_, _, ref expr)
1373-
| ast::ExprKind::Box(ref expr)
13741375
| ast::ExprKind::Try(ref expr)
13751376
| ast::ExprKind::Unary(_, ref expr)
13761377
| ast::ExprKind::Cast(ref expr, _) => is_nested_call(expr),
@@ -1890,7 +1891,7 @@ impl<'ast> RhsAssignKind<'ast> {
18901891
ast::ExprKind::Try(..)
18911892
| ast::ExprKind::Field(..)
18921893
| ast::ExprKind::MethodCall(..)
1893-
| ast::ExprKind::Await(_)
1894+
| ast::ExprKind::Await(_, _)
18941895
)
18951896
}
18961897
_ => false,
@@ -2132,7 +2133,6 @@ pub(crate) fn is_method_call(expr: &ast::Expr) -> bool {
21322133
match expr.kind {
21332134
ast::ExprKind::MethodCall(..) => true,
21342135
ast::ExprKind::AddrOf(_, _, ref expr)
2135-
| ast::ExprKind::Box(ref expr)
21362136
| ast::ExprKind::Cast(ref expr, _)
21372137
| ast::ExprKind::Try(ref expr)
21382138
| ast::ExprKind::Unary(_, ref expr) => is_method_call(expr),

src/items.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,13 +1823,15 @@ pub(crate) struct StaticParts<'a> {
18231823

18241824
impl<'a> StaticParts<'a> {
18251825
pub(crate) fn from_item(item: &'a ast::Item) -> Self {
1826-
let (defaultness, prefix, ty, mutability, expr) = match item.kind {
1827-
ast::ItemKind::Static(ref ty, mutability, ref expr) => {
1828-
(None, "static", ty, mutability, expr)
1829-
}
1830-
ast::ItemKind::Const(defaultness, ref ty, ref expr) => {
1831-
(Some(defaultness), "const", ty, ast::Mutability::Not, expr)
1832-
}
1826+
let (defaultness, prefix, ty, mutability, expr) = match &item.kind {
1827+
ast::ItemKind::Static(s) => (None, "static", &s.ty, s.mutability, &s.expr),
1828+
ast::ItemKind::Const(c) => (
1829+
Some(c.defaultness),
1830+
"const",
1831+
&c.ty,
1832+
ast::Mutability::Not,
1833+
&c.expr,
1834+
),
18331835
_ => unreachable!(),
18341836
};
18351837
StaticParts {
@@ -1845,10 +1847,8 @@ impl<'a> StaticParts<'a> {
18451847
}
18461848

18471849
pub(crate) fn from_trait_item(ti: &'a ast::AssocItem) -> Self {
1848-
let (defaultness, ty, expr_opt) = match ti.kind {
1849-
ast::AssocItemKind::Const(defaultness, ref ty, ref expr_opt) => {
1850-
(defaultness, ty, expr_opt)
1851-
}
1850+
let (defaultness, ty, expr_opt) = match &ti.kind {
1851+
ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr),
18521852
_ => unreachable!(),
18531853
};
18541854
StaticParts {
@@ -1864,8 +1864,8 @@ impl<'a> StaticParts<'a> {
18641864
}
18651865

18661866
pub(crate) fn from_impl_item(ii: &'a ast::AssocItem) -> Self {
1867-
let (defaultness, ty, expr) = match ii.kind {
1868-
ast::AssocItemKind::Const(defaultness, ref ty, ref expr) => (defaultness, ty, expr),
1867+
let (defaultness, ty, expr) = match &ii.kind {
1868+
ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr),
18691869
_ => unreachable!(),
18701870
};
18711871
StaticParts {

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extern crate rustc_expand;
2020
extern crate rustc_parse;
2121
extern crate rustc_session;
2222
extern crate rustc_span;
23+
extern crate thin_vec;
2324

2425
// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
2526
// files.

src/macros.rs

Lines changed: 5 additions & 5 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::{Cursor, TokenStream, TokenTree};
16+
use rustc_ast::tokenstream::{TokenStream, TokenTree, TokenTreeCursor};
1717
use rustc_ast::{ast, ptr};
1818
use rustc_ast_pretty::pprust;
1919
use rustc_span::{
@@ -736,7 +736,7 @@ impl MacroArgParser {
736736
self.buf.clear();
737737
}
738738

739-
fn add_meta_variable(&mut self, iter: &mut Cursor) -> Option<()> {
739+
fn add_meta_variable(&mut self, iter: &mut TokenTreeCursor) -> Option<()> {
740740
match iter.next() {
741741
Some(TokenTree::Token(
742742
Token {
@@ -768,7 +768,7 @@ impl MacroArgParser {
768768
&mut self,
769769
inner: Vec<ParsedMacroArg>,
770770
delim: Delimiter,
771-
iter: &mut Cursor,
771+
iter: &mut TokenTreeCursor,
772772
) -> Option<()> {
773773
let mut buffer = String::new();
774774
let mut first = true;
@@ -1120,11 +1120,11 @@ pub(crate) fn macro_style(mac: &ast::MacCall, context: &RewriteContext<'_>) -> D
11201120
// A very simple parser that just parses a macros 2.0 definition into its branches.
11211121
// Currently we do not attempt to parse any further than that.
11221122
struct MacroParser {
1123-
toks: Cursor,
1123+
toks: TokenTreeCursor,
11241124
}
11251125

11261126
impl MacroParser {
1127-
const fn new(toks: Cursor) -> Self {
1127+
const fn new(toks: TokenTreeCursor) -> Self {
11281128
Self { toks }
11291129
}
11301130

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy