Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
80d196d
Update rustfmt for ast::ExprKind::FormatArgs.
m-ou-se Jan 11, 2023
2791cc3
Teach parser to understand fake anonymous enum syntax
estebank Jan 15, 2023
4e3ed18
review comment: Remove AST AnonTy
estebank Jan 23, 2023
094b7f5
Merge commit '1d8491b120223272b13451fc81265aa64f7f4d5b' into sync-fro…
calebcartwright Jan 24, 2023
1d9afb2
Rollup merge of #106960 - estebank:parse-anon-enums, r=cjgillot
matthiaskrgr Jan 26, 2023
6d13315
Auto merge of #106745 - m-ou-se:format-args-ast, r=oli-obk
bors Jan 26, 2023
c6b822d
Rename `Cursor`/`CursorRef` as `TokenTreeCursor`/`RefTokenTreeCursor`.
nnethercote Feb 1, 2023
24f4ece
Introduce `-Zterminal-urls` to use OSC8 for error codes
estebank Feb 9, 2023
af75a2f
Use `ThinVec` in various AST types.
nnethercote Nov 23, 2022
23007fc
Use `ThinVec` in `ast::Block`.
nnethercote Jan 30, 2023
01ed9dd
Use `ThinVec` in a few more AST types.
nnethercote Jan 30, 2023
8b7f811
errors: generate typed identifiers in each crate
davidtwco Oct 13, 2022
386ea37
various: translation resources from cg backend
davidtwco Oct 17, 2022
a5ba6e0
Remove uses of `box_syntax` in rustc and tools
clubby789 Feb 27, 2023
4e658cc
Remove `box_syntax` from AST and use in tools
clubby789 Feb 27, 2023
3ef194c
Remove the `NodeId` of `ast::ExprKind::Async`
Swatinem Jan 31, 2023
809dd77
rustc: Remove unused `Session` argument from some attribute functions
petrochenkov Mar 19, 2023
9510f7e
Merge from rustc
oli-obk Mar 23, 2023
5cbb08d
Rollup merge of #109354 - Swatinem:rm-closureid, r=compiler-errors
GuillaumeGomez Mar 27, 2023
5effe61
Merge from rustc
oli-obk Apr 4, 2023
c2890ec
rust-analyzer guided enum variant structification
oli-obk Mar 29, 2023
ced3cd8
rust-analyzer guided tuple field to named field
oli-obk Mar 29, 2023
3ecb9ed
Split out ast::ItemKind::Const into its own struct
oli-obk Mar 29, 2023
f178139
box a bunch of large types
oli-obk Mar 29, 2023
f533800
Merge from rustc
saethlin Apr 10, 2023
84385bf
offset_of
beepster4096 Sep 11, 2022
ecfdec4
minor tweaks
beepster4096 Apr 21, 2023
f4c9b4c
rustfmt fmt
beepster4096 Apr 21, 2023
afe34c8
Merge from rustc
RalfJung Apr 22, 2023
6b9c151
Tweak await span
compiler-errors Apr 25, 2023
4eb1b52
Merge from rustc
RalfJung Apr 30, 2023
a74d2d7
fix tests
chenyukang Mar 14, 2023
9d20134
remove rustfmt testcase for type ascription
chenyukang Apr 4, 2023
4351e50
Auto merge of #111036 - RalfJung:miri, r=RalfJung
bors May 1, 2023
34a71f6
Make the BUG_REPORT_URL configurable by tools
jyn514 Apr 29, 2023
ae213e2
Auto merge of #109128 - chenyukang:yukang/remove-type-ascription, r=e…
bors May 2, 2023
8e330f9
Make tools happy
compiler-errors Apr 25, 2023
8ed5d5d
Rustfmt support for negative bounds, test
compiler-errors Apr 26, 2023
48e380f
Rollup merge of #110989 - jyn514:bug-report-url, r=WaffleLapkin
matthiaskrgr May 6, 2023
312a86b
Merge remote-tracking branch 'upstream/master' into subtree-sync-2023…
calebcartwright Jun 20, 2023
0b17d7e
chore: address merge and bump toolchain
calebcartwright Jun 20, 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
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,32 @@
- Prevent ICE when parsing invalid attributes in `cfg_if!` macros [#5728](https://github.com/rust-lang/rustfmt/issues/5728)


## [1.5.2] 2023-01-24

### Fixed

- Resolve issue when comments are found within const generic defaults in unit structs [#5668](https://github.com/rust-lang/rustfmt/issues/5668)
- Resolve issue when block comments are found within trait generics [#5358](https://github.com/rust-lang/rustfmt/issues/5358)
- Correctly handle alignment of comments containing unicode characters [#5504](https://github.com/rust-lang/rustfmt/issues/5504)
- 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`)

### Changed

- 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

### Added

- 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)

### Misc

- 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.

### Install/Download Options
- **rustup (nightly)** - nightly-2023-01-24
- **GitHub Release Binaries** - [Release v1.5.2](https://github.com/rust-lang/rustfmt/releases/tag/v1.5.2)
- **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]

## [1.5.2] 2023-01-24

### Fixed
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-01-24"
channel = "nightly-2023-06-19"
components = ["llvm-tools", "rustc-dev"]
16 changes: 1 addition & 15 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use rustc_ast::ast;
use rustc_ast::HasAttrs;
use rustc_span::{symbol::sym, Span, Symbol};
use rustc_span::{symbol::sym, Span};

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

mod doc_comment;

pub(crate) fn contains_name(attrs: &[ast::Attribute], name: Symbol) -> bool {
attrs.iter().any(|attr| attr.has_name(name))
}

pub(crate) fn first_attr_value_str_by_name(
attrs: &[ast::Attribute],
name: Symbol,
) -> Option<Symbol> {
attrs
.iter()
.find(|attr| attr.has_name(name))
.and_then(|attr| attr.value_str())
}

/// Returns attributes on the given statement.
pub(crate) fn get_attrs_from_stmt(stmt: &ast::Stmt) -> &[ast::Attribute] {
stmt.attrs()
Expand Down
9 changes: 9 additions & 0 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(rustc_private)]

use anyhow::{format_err, Result};

use io::Error as IoError;
Expand All @@ -19,7 +21,14 @@ use crate::rustfmt::{
FormatReportFormatterBuilder, Input, Session, Verbosity,
};

const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rustfmt/issues/new?labels=bug";

// N.B. these crates are loaded from the sysroot, so they need extern crate.
extern crate rustc_driver;

fn main() {
rustc_driver::install_ice_hook(BUG_REPORT_URL, |_| ());

env_logger::Builder::from_env("RUSTFMT_LOG").init();
let opts = make_opts();

Expand Down
8 changes: 5 additions & 3 deletions src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ use crate::utils::{
rewrite_ident, trimmed_last_line_width, wrap_str,
};

use thin_vec::ThinVec;

/// Provides the original input contents from the span
/// of a chain element with trailing spaces trimmed.
fn format_overflow_style(span: Span, context: &RewriteContext<'_>) -> Option<String> {
Expand Down Expand Up @@ -168,7 +170,7 @@ enum ChainItemKind {
MethodCall(
ast::PathSegment,
Vec<ast::GenericArg>,
Vec<ptr::P<ast::Expr>>,
ThinVec<ptr::P<ast::Expr>>,
),
StructField(symbol::Ident),
TupleField(symbol::Ident, bool),
Expand Down Expand Up @@ -230,7 +232,7 @@ impl ChainItemKind {
let span = mk_sp(nested.span.hi(), field.span.hi());
(kind, span)
}
ast::ExprKind::Await(ref nested) => {
ast::ExprKind::Await(ref nested, _) => {
let span = mk_sp(nested.span.hi(), expr.span.hi());
(ChainItemKind::Await, span)
}
Expand Down Expand Up @@ -457,7 +459,7 @@ impl Chain {
ast::ExprKind::MethodCall(ref call) => Some(Self::convert_try(&call.receiver, context)),
ast::ExprKind::Field(ref subexpr, _)
| ast::ExprKind::Try(ref subexpr)
| ast::ExprKind::Await(ref subexpr) => Some(Self::convert_try(subexpr, context)),
| ast::ExprKind::Await(ref subexpr, _) => Some(Self::convert_try(subexpr, context)),
_ => None,
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/closures.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use rustc_ast::{ast, ptr};
use rustc_span::Span;
use thin_vec::thin_vec;

use crate::attr::get_attrs_from_stmt;
use crate::config::lists::*;
Expand Down Expand Up @@ -150,7 +151,7 @@ fn rewrite_closure_with_block(
}

let block = ast::Block {
stmts: vec![ast::Stmt {
stmts: thin_vec![ast::Stmt {
id: ast::NodeId::root(),
kind: ast::StmtKind::Expr(ptr::P(body.clone())),
span: body.span,
Expand Down Expand Up @@ -194,7 +195,6 @@ fn rewrite_closure_expr(
| ast::ExprKind::Struct(..) => true,

ast::ExprKind::AddrOf(_, _, ref expr)
| ast::ExprKind::Box(ref expr)
| ast::ExprKind::Try(ref expr)
| ast::ExprKind::Unary(_, ref expr)
| ast::ExprKind::Cast(ref expr, _) => allow_multi_line(expr),
Expand Down Expand Up @@ -440,7 +440,6 @@ fn is_block_closure_forced_inner(expr: &ast::Expr, version: Version) -> bool {
ast::ExprKind::If(..) | ast::ExprKind::While(..) | ast::ExprKind::ForLoop(..) => true,
ast::ExprKind::Loop(..) if version == Version::Two => true,
ast::ExprKind::AddrOf(_, _, ref expr)
| ast::ExprKind::Box(ref expr)
| ast::ExprKind::Try(ref expr)
| ast::ExprKind::Unary(_, ref expr)
| ast::ExprKind::Cast(ref expr, _) => is_block_closure_forced_inner(expr, version),
Expand Down
18 changes: 9 additions & 9 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub(crate) fn format_expr(
ast::ExprKind::Try(..)
| ast::ExprKind::Field(..)
| ast::ExprKind::MethodCall(..)
| ast::ExprKind::Await(_) => rewrite_chain(expr, context, shape),
| ast::ExprKind::Await(_, _) => rewrite_chain(expr, context, shape),
ast::ExprKind::MacCall(ref mac) => {
rewrite_macro(mac, None, context, shape, MacroPosition::Expression).or_else(|| {
wrap_str(
Expand All @@ -236,7 +236,6 @@ pub(crate) fn format_expr(
ast::ExprKind::Yeet(Some(ref expr)) => {
rewrite_unary_prefix(context, "do yeet ", &**expr, shape)
}
ast::ExprKind::Box(ref expr) => rewrite_unary_prefix(context, "box ", &**expr, shape),
ast::ExprKind::AddrOf(borrow_kind, mutability, ref expr) => {
rewrite_expr_addrof(context, borrow_kind, mutability, expr, shape)
}
Expand Down Expand Up @@ -367,7 +366,7 @@ pub(crate) fn format_expr(
))
}
}
ast::ExprKind::Async(capture_by, _node_id, ref block) => {
ast::ExprKind::Async(capture_by, ref block) => {
let mover = if capture_by == ast::CaptureBy::Value {
"move "
} else {
Expand Down Expand Up @@ -400,7 +399,12 @@ pub(crate) fn format_expr(
}
}
ast::ExprKind::Underscore => Some("_".to_owned()),
ast::ExprKind::IncludedBytes(..) => unreachable!(),
ast::ExprKind::FormatArgs(..)
| ast::ExprKind::IncludedBytes(..)
| ast::ExprKind::OffsetOf(..) => {
// These do not occur in the AST because macros aren't expanded.
unreachable!()
}
ast::ExprKind::Err => None,
};

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

// Handle unary-like expressions
ast::ExprKind::AddrOf(_, _, ref expr)
| ast::ExprKind::Box(ref expr)
| ast::ExprKind::Try(ref expr)
| ast::ExprKind::Unary(_, ref expr)
| ast::ExprKind::Cast(ref expr, _) => can_be_overflowed_expr(context, expr, args_len),
Expand All @@ -1370,7 +1372,6 @@ pub(crate) fn is_nested_call(expr: &ast::Expr) -> bool {
match expr.kind {
ast::ExprKind::Call(..) | ast::ExprKind::MacCall(..) => true,
ast::ExprKind::AddrOf(_, _, ref expr)
| ast::ExprKind::Box(ref expr)
| ast::ExprKind::Try(ref expr)
| ast::ExprKind::Unary(_, ref expr)
| ast::ExprKind::Cast(ref expr, _) => is_nested_call(expr),
Expand Down Expand Up @@ -1890,7 +1891,7 @@ impl<'ast> RhsAssignKind<'ast> {
ast::ExprKind::Try(..)
| ast::ExprKind::Field(..)
| ast::ExprKind::MethodCall(..)
| ast::ExprKind::Await(_)
| ast::ExprKind::Await(_, _)
)
}
_ => false,
Expand Down Expand Up @@ -2132,7 +2133,6 @@ pub(crate) fn is_method_call(expr: &ast::Expr) -> bool {
match expr.kind {
ast::ExprKind::MethodCall(..) => true,
ast::ExprKind::AddrOf(_, _, ref expr)
| ast::ExprKind::Box(ref expr)
| ast::ExprKind::Cast(ref expr, _)
| ast::ExprKind::Try(ref expr)
| ast::ExprKind::Unary(_, ref expr) => is_method_call(expr),
Expand Down
26 changes: 13 additions & 13 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1823,13 +1823,15 @@ pub(crate) struct StaticParts<'a> {

impl<'a> StaticParts<'a> {
pub(crate) fn from_item(item: &'a ast::Item) -> Self {
let (defaultness, prefix, ty, mutability, expr) = match item.kind {
ast::ItemKind::Static(ref ty, mutability, ref expr) => {
(None, "static", ty, mutability, expr)
}
ast::ItemKind::Const(defaultness, ref ty, ref expr) => {
(Some(defaultness), "const", ty, ast::Mutability::Not, expr)
}
let (defaultness, prefix, ty, mutability, expr) = match &item.kind {
ast::ItemKind::Static(s) => (None, "static", &s.ty, s.mutability, &s.expr),
ast::ItemKind::Const(c) => (
Some(c.defaultness),
"const",
&c.ty,
ast::Mutability::Not,
&c.expr,
),
_ => unreachable!(),
};
StaticParts {
Expand All @@ -1845,10 +1847,8 @@ impl<'a> StaticParts<'a> {
}

pub(crate) fn from_trait_item(ti: &'a ast::AssocItem) -> Self {
let (defaultness, ty, expr_opt) = match ti.kind {
ast::AssocItemKind::Const(defaultness, ref ty, ref expr_opt) => {
(defaultness, ty, expr_opt)
}
let (defaultness, ty, expr_opt) = match &ti.kind {
ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr),
_ => unreachable!(),
};
StaticParts {
Expand All @@ -1864,8 +1864,8 @@ impl<'a> StaticParts<'a> {
}

pub(crate) fn from_impl_item(ii: &'a ast::AssocItem) -> Self {
let (defaultness, ty, expr) = match ii.kind {
ast::AssocItemKind::Const(defaultness, ref ty, ref expr) => (defaultness, ty, expr),
let (defaultness, ty, expr) = match &ii.kind {
ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr),
_ => unreachable!(),
};
StaticParts {
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extern crate rustc_expand;
extern crate rustc_parse;
extern crate rustc_session;
extern crate rustc_span;
extern crate thin_vec;

// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
// files.
Expand Down
10 changes: 5 additions & 5 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::{Cursor, TokenStream, TokenTree};
use rustc_ast::tokenstream::{TokenStream, TokenTree, TokenTreeCursor};
use rustc_ast::{ast, ptr};
use rustc_ast_pretty::pprust;
use rustc_span::{
Expand Down Expand Up @@ -736,7 +736,7 @@ impl MacroArgParser {
self.buf.clear();
}

fn add_meta_variable(&mut self, iter: &mut Cursor) -> Option<()> {
fn add_meta_variable(&mut self, iter: &mut TokenTreeCursor) -> Option<()> {
match iter.next() {
Some(TokenTree::Token(
Token {
Expand Down Expand Up @@ -768,7 +768,7 @@ impl MacroArgParser {
&mut self,
inner: Vec<ParsedMacroArg>,
delim: Delimiter,
iter: &mut Cursor,
iter: &mut TokenTreeCursor,
) -> Option<()> {
let mut buffer = String::new();
let mut first = true;
Expand Down Expand Up @@ -1120,11 +1120,11 @@ 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: Cursor,
toks: TokenTreeCursor,
}

impl MacroParser {
const fn new(toks: Cursor) -> Self {
const fn new(toks: TokenTreeCursor) -> Self {
Self { toks }
}

Expand Down
1 change: 0 additions & 1 deletion src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,6 @@ fn can_flatten_block_around_this(body: &ast::Expr) -> bool {
| ast::ExprKind::Struct(..)
| ast::ExprKind::Tup(..) => true,
ast::ExprKind::AddrOf(_, _, ref expr)
| ast::ExprKind::Box(ref expr)
| ast::ExprKind::Try(ref expr)
| ast::ExprKind::Unary(_, ref expr)
| ast::ExprKind::Index(ref expr, _)
Expand Down
Loading