Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readme = "README.md"
license = "Apache-2.0 OR MIT"
build = "build.rs"
categories = ["development-tools"]
edition = "2021"
edition = "2024"

[[bin]]
name = "rustfmt"
Expand Down Expand Up @@ -54,7 +54,9 @@ tracing = { version = "0.1.37", default-features = false, features = ["std"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
unicode-segmentation = "1.9"
unicode-width = "0.1"
unicode-properties = { version = "0.1", default-features = false, features = ["general-category"] }
unicode-properties = { version = "0.1", default-features = false, features = [
"general-category",
] }

rustfmt-config_proc_macro = { version = "0.3", path = "config_proc_macro" }
semver = "1.0.21"
Expand Down
2 changes: 1 addition & 1 deletion check_diff/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "check_diff"
version = "0.1.0"
edition = "2021"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
9 changes: 7 additions & 2 deletions config_proc_macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "rustfmt-config_proc_macro"
version = "0.3.0"
edition = "2021"
edition = "2024"
description = "A collection of procedural macros for rustfmt"
license = "Apache-2.0 OR MIT"
categories = ["development-tools::procedural-macro-helpers"]
Expand All @@ -13,7 +13,12 @@ proc-macro = true
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "2.0", default-features = false, features = ["full", "parsing", "proc-macro", "printing"] }
syn = { version = "2.0", default-features = false, features = [
"full",
"parsing",
"proc-macro",
"printing",
] }

[dev-dependencies]
serde = { version = "1.0.160", features = ["derive"] }
Expand Down
12 changes: 5 additions & 7 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,8 @@ impl Rewrite for ast::MetaItemInner {

fn rewrite_result(&self, context: &RewriteContext<'_>, shape: Shape) -> RewriteResult {
match self {
ast::MetaItemInner::MetaItem(ref meta_item) => meta_item.rewrite_result(context, shape),
ast::MetaItemInner::Lit(ref l) => {
rewrite_literal(context, l.as_token_lit(), l.span, shape)
}
ast::MetaItemInner::MetaItem(meta_item) => meta_item.rewrite_result(context, shape),
ast::MetaItemInner::Lit(l) => rewrite_literal(context, l.as_token_lit(), l.span, shape),
}
}
}
Expand Down Expand Up @@ -342,7 +340,7 @@ impl Rewrite for ast::Attribute {
return Ok(snippet.to_owned());
}

if let Some(ref meta) = self.meta() {
if let Some(meta) = self.meta() {
// This attribute is possibly a doc attribute needing normalization to a doc comment
if context.config.normalize_doc_attributes() && meta.has_name(sym::doc) {
if let Some(ref literal) = meta.value_str() {
Expand Down Expand Up @@ -546,8 +544,8 @@ pub(crate) trait MetaVisitor<'ast> {

fn visit_meta_item_inner(&mut self, nm: &'ast ast::MetaItemInner) {
match nm {
ast::MetaItemInner::MetaItem(ref meta_item) => self.visit_meta_item(meta_item),
ast::MetaItemInner::Lit(ref lit) => self.visit_meta_item_lit(lit),
ast::MetaItemInner::MetaItem(meta_item) => self.visit_meta_item(meta_item),
ast::MetaItemInner::Lit(lit) => self.visit_meta_item_lit(lit),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl ChainItemKind {
data.args
.iter()
.filter_map(|x| match x {
ast::AngleBracketedArg::Arg(ref generic_arg) => {
ast::AngleBracketedArg::Arg(generic_arg) => {
Some(generic_arg.clone())
}
_ => None,
Expand Down
16 changes: 7 additions & 9 deletions src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ impl UseSegment {
// Check if self == other with their aliases removed.
fn equal_except_alias(&self, other: &Self) -> bool {
match (&self.kind, &other.kind) {
(UseSegmentKind::Ident(ref s1, _), UseSegmentKind::Ident(ref s2, _)) => s1 == s2,
(UseSegmentKind::Ident(s1, _), UseSegmentKind::Ident(s2, _)) => s1 == s2,
(UseSegmentKind::Slf(_), UseSegmentKind::Slf(_))
| (UseSegmentKind::Super(_), UseSegmentKind::Super(_))
| (UseSegmentKind::Crate(_), UseSegmentKind::Crate(_))
| (UseSegmentKind::Glob, UseSegmentKind::Glob) => true,
(UseSegmentKind::List(ref list1), UseSegmentKind::List(ref list2)) => list1 == list2,
(UseSegmentKind::List(list1), UseSegmentKind::List(list2)) => list1 == list2,
_ => false,
}
}
Expand Down Expand Up @@ -591,7 +591,7 @@ impl UseTree {
if aliased_self {
match self.path.last_mut() {
Some(UseSegment {
kind: UseSegmentKind::Ident(_, ref mut old_rename),
kind: UseSegmentKind::Ident(_, old_rename),
..
}) => {
assert!(old_rename.is_none());
Expand Down Expand Up @@ -667,7 +667,7 @@ impl UseTree {
}),
)
| (None, None) => true,
(Some(ref a), Some(ref b)) => is_same_visibility(a, b),
(Some(a), Some(b)) => is_same_visibility(a, b),
_ => false,
}
}
Expand Down Expand Up @@ -922,9 +922,7 @@ impl Ord for UseSegment {
}

match (&self.kind, &other.kind) {
(Slf(ref a), Slf(ref b))
| (Super(ref a), Super(ref b))
| (Crate(ref a), Crate(ref b)) => match (a, b) {
(Slf(a), Slf(b)) | (Super(a), Super(b)) | (Crate(a), Crate(b)) => match (a, b) {
(Some(sa), Some(sb)) => {
if self.style_edition >= StyleEdition::Edition2024 {
version_sort(sa.trim_start_matches("r#"), sb.trim_start_matches("r#"))
Expand All @@ -935,7 +933,7 @@ impl Ord for UseSegment {
(_, _) => a.cmp(b),
},
(Glob, Glob) => Ordering::Equal,
(Ident(ref pia, ref aa), Ident(ref pib, ref ab)) => {
(Ident(pia, aa), Ident(pib, ab)) => {
let (ia, ib) = if self.style_edition >= StyleEdition::Edition2024 {
(pia.trim_start_matches("r#"), pib.trim_start_matches("r#"))
} else {
Expand Down Expand Up @@ -977,7 +975,7 @@ impl Ord for UseSegment {
(None, None) => Ordering::Equal,
}
}
(List(ref a), List(ref b)) => {
(List(a), List(b)) => {
for (a, b) in a.iter().zip(b.iter()) {
let ord = a.cmp(b);
if ord != Ordering::Equal {
Expand Down
106 changes: 53 additions & 53 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2273,30 +2273,61 @@ impl Rewrite for ast::Param {
};

if let Some(ref explicit_self) = self.to_self() {
rewrite_explicit_self(
return rewrite_explicit_self(
context,
explicit_self,
&param_attrs_result,
span,
shape,
has_multiple_attr_lines,
)
} else if is_named_param(self) {
let param_name = &self
.pat
.rewrite_result(context, Shape::legacy(shape.width, shape.indent))?;
let mut result = combine_strs_with_missing_comments(
context,
&param_attrs_result,
param_name,
span,
shape,
!has_multiple_attr_lines && !has_doc_comments,
)?;
);
}
if !is_named_param(self) {
return self.ty.rewrite_result(context, shape);
}
let param_name = &self
.pat
.rewrite_result(context, Shape::legacy(shape.width, shape.indent))?;
let mut result = combine_strs_with_missing_comments(
context,
&param_attrs_result,
param_name,
span,
shape,
!has_multiple_attr_lines && !has_doc_comments,
)?;

if !is_empty_infer(&*self.ty, self.pat.span) {
let (before_comment, after_comment) =
get_missing_param_comments(context, self.pat.span, self.ty.span, shape);
if !is_empty_infer(&*self.ty, self.pat.span) {
let (before_comment, after_comment) =
get_missing_param_comments(context, self.pat.span, self.ty.span, shape);
result.push_str(&before_comment);
result.push_str(colon_spaces(context.config));
result.push_str(&after_comment);
let overhead = last_line_width(&result);
let max_width = shape
.width
.checked_sub(overhead)
.max_width_error(shape.width, self.span())?;
if let Ok(ty_str) = self
.ty
.rewrite_result(context, Shape::legacy(max_width, shape.indent))
{
result.push_str(&ty_str);
} else {
let prev_str = if param_attrs_result.is_empty() {
param_attrs_result
} else {
param_attrs_result + &shape.to_string_with_newline(context.config)
};

result = combine_strs_with_missing_comments(
context,
&prev_str,
param_name,
span,
shape,
!has_multiple_attr_lines,
)?;
result.push_str(&before_comment);
result.push_str(colon_spaces(context.config));
result.push_str(&after_comment);
Expand All @@ -2305,45 +2336,14 @@ impl Rewrite for ast::Param {
.width
.checked_sub(overhead)
.max_width_error(shape.width, self.span())?;
if let Ok(ty_str) = self
let ty_str = self
.ty
.rewrite_result(context, Shape::legacy(max_width, shape.indent))
{
result.push_str(&ty_str);
} else {
let prev_str = if param_attrs_result.is_empty() {
param_attrs_result
} else {
param_attrs_result + &shape.to_string_with_newline(context.config)
};

result = combine_strs_with_missing_comments(
context,
&prev_str,
param_name,
span,
shape,
!has_multiple_attr_lines,
)?;
result.push_str(&before_comment);
result.push_str(colon_spaces(context.config));
result.push_str(&after_comment);
let overhead = last_line_width(&result);
let max_width = shape
.width
.checked_sub(overhead)
.max_width_error(shape.width, self.span())?;
let ty_str = self
.ty
.rewrite_result(context, Shape::legacy(max_width, shape.indent))?;
result.push_str(&ty_str);
}
.rewrite_result(context, Shape::legacy(max_width, shape.indent))?;
result.push_str(&ty_str);
}

Ok(result)
} else {
self.ty.rewrite_result(context, shape)
}

Ok(result)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ impl Input {

fn to_directory_ownership(&self) -> Option<DirectoryOwnership> {
match self {
Input::File(ref file) => {
Input::File(file) => {
// If there exists a directory with the same name as an input,
// then the input should be parsed as a sub module.
let file_stem = file.file_stem()?;
Expand Down
4 changes: 2 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ impl MacroArgParser {
) => {
break;
}
TokenTree::Token(ref t, _) => {
TokenTree::Token(t, _) => {
buffer.push_str(&pprust::token_to_string(t));
}
_ => return None,
Expand Down Expand Up @@ -939,7 +939,7 @@ impl MacroArgParser {
) if self.is_meta_var => {
self.add_meta_variable(&mut iter)?;
}
TokenTree::Token(ref t, _) => self.update_buffer(t),
TokenTree::Token(t, _) => self.update_buffer(t),
&TokenTree::Delimited(_dspan, _spacing, delimited, ref tts) => {
if !self.buf.is_empty() {
if next_space(&self.last_tok.kind) == SpaceState::Always {
Expand Down
13 changes: 8 additions & 5 deletions src/overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl<'a> OverflowableItem<'a> {
OverflowableItem::MacroArg(MacroArg::Expr(expr)) => is_simple_expr(expr),
OverflowableItem::MetaItemInner(meta_item_inner) => match meta_item_inner {
ast::MetaItemInner::Lit(..) => true,
ast::MetaItemInner::MetaItem(ref meta_item) => {
ast::MetaItemInner::MetaItem(meta_item) => {
matches!(meta_item.kind, ast::MetaItemKind::Word)
}
},
Expand Down Expand Up @@ -169,7 +169,7 @@ impl<'a> OverflowableItem<'a> {
pub(crate) fn to_expr(&self) -> Option<&'a ast::Expr> {
match self {
OverflowableItem::Expr(expr) => Some(expr),
OverflowableItem::MacroArg(MacroArg::Expr(ref expr)) => Some(expr),
OverflowableItem::MacroArg(MacroArg::Expr(expr)) => Some(expr),
_ => None,
}
}
Expand All @@ -178,8 +178,8 @@ impl<'a> OverflowableItem<'a> {
match self {
OverflowableItem::Expr(expr) => can_be_overflowed_expr(context, expr, len),
OverflowableItem::MacroArg(macro_arg) => match macro_arg {
MacroArg::Expr(ref expr) => can_be_overflowed_expr(context, expr, len),
MacroArg::Ty(ref ty) => can_be_overflowed_type(context, ty, len),
MacroArg::Expr(expr) => can_be_overflowed_expr(context, expr, len),
MacroArg::Ty(ty) => can_be_overflowed_type(context, ty, len),
MacroArg::Pat(..) => false,
MacroArg::Item(..) => len == 1,
MacroArg::Keyword(..) => false,
Expand All @@ -197,7 +197,10 @@ impl<'a> OverflowableItem<'a> {
}
}

fn special_cases(&self, config: &Config) -> impl Iterator<Item = &(&'static str, usize)> {
fn special_cases(
&self,
config: &Config,
) -> impl Iterator<Item = &(&'static str, usize)> + use<'_> {
let base_cases = match self {
OverflowableItem::MacroArg(..) => SPECIAL_CASE_MACROS,
OverflowableItem::MetaItemInner(..) => SPECIAL_CASE_ATTR,
Expand Down
5 changes: 2 additions & 3 deletions src/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,13 @@ impl<'a> Parser<'a> {

fn parse_crate_mod(&mut self) -> Result<ast::Crate, ParserError> {
let mut parser = AssertUnwindSafe(&mut self.parser);
let err = Err(ParserError::ParsePanicError);
match catch_unwind(move || parser.parse_crate_mod()) {
Ok(Ok(k)) => Ok(k),
Ok(Err(db)) => {
db.emit();
err
Err(ParserError::ParsePanicError)
}
Err(_) => err,
Err(_) => Err(ParserError::ParsePanicError),
}
}
}
Loading
Loading