Skip to content

Commit a24c437

Browse files
Migrate rustfmt to Edition 2024
Most of the suggestions from `cargo fix --edition` are accepted. - Effectfull destructors are almost exclusively from `ThinVec` and diagnostics handler. - We are not matching the new fragments covered by `expr` so instead of `expr_2021` we shall continue to use `expr` from Edition 2024. Signed-off-by: Xiangfei Ding <[email protected]>
1 parent ced5993 commit a24c437

File tree

18 files changed

+116
-117
lines changed

18 files changed

+116
-117
lines changed

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ readme = "README.md"
88
license = "Apache-2.0 OR MIT"
99
build = "build.rs"
1010
categories = ["development-tools"]
11-
edition = "2021"
11+
edition = "2024"
1212

1313
[[bin]]
1414
name = "rustfmt"
@@ -54,7 +54,9 @@ tracing = { version = "0.1.37", default-features = false, features = ["std"] }
5454
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
5555
unicode-segmentation = "1.9"
5656
unicode-width = "0.1"
57-
unicode-properties = { version = "0.1", default-features = false, features = ["general-category"] }
57+
unicode-properties = { version = "0.1", default-features = false, features = [
58+
"general-category",
59+
] }
5860

5961
rustfmt-config_proc_macro = { version = "0.3", path = "config_proc_macro" }
6062
semver = "1.0.21"

check_diff/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "check_diff"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55

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

config_proc_macro/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "rustfmt-config_proc_macro"
33
version = "0.3.0"
4-
edition = "2021"
4+
edition = "2024"
55
description = "A collection of procedural macros for rustfmt"
66
license = "Apache-2.0 OR MIT"
77
categories = ["development-tools::procedural-macro-helpers"]
@@ -13,7 +13,12 @@ proc-macro = true
1313
[dependencies]
1414
proc-macro2 = "1.0"
1515
quote = "1.0"
16-
syn = { version = "2.0", default-features = false, features = ["full", "parsing", "proc-macro", "printing"] }
16+
syn = { version = "2.0", default-features = false, features = [
17+
"full",
18+
"parsing",
19+
"proc-macro",
20+
"printing",
21+
] }
1722

1823
[dev-dependencies]
1924
serde = { version = "1.0.160", features = ["derive"] }

src/attr.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,8 @@ impl Rewrite for ast::MetaItemInner {
249249

250250
fn rewrite_result(&self, context: &RewriteContext<'_>, shape: Shape) -> RewriteResult {
251251
match self {
252-
ast::MetaItemInner::MetaItem(ref meta_item) => meta_item.rewrite_result(context, shape),
253-
ast::MetaItemInner::Lit(ref l) => {
254-
rewrite_literal(context, l.as_token_lit(), l.span, shape)
255-
}
252+
ast::MetaItemInner::MetaItem(meta_item) => meta_item.rewrite_result(context, shape),
253+
ast::MetaItemInner::Lit(l) => rewrite_literal(context, l.as_token_lit(), l.span, shape),
256254
}
257255
}
258256
}
@@ -342,7 +340,7 @@ impl Rewrite for ast::Attribute {
342340
return Ok(snippet.to_owned());
343341
}
344342

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

547545
fn visit_meta_item_inner(&mut self, nm: &'ast ast::MetaItemInner) {
548546
match nm {
549-
ast::MetaItemInner::MetaItem(ref meta_item) => self.visit_meta_item(meta_item),
550-
ast::MetaItemInner::Lit(ref lit) => self.visit_meta_item_lit(lit),
547+
ast::MetaItemInner::MetaItem(meta_item) => self.visit_meta_item(meta_item),
548+
ast::MetaItemInner::Lit(lit) => self.visit_meta_item_lit(lit),
551549
}
552550
}
553551

src/chains.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl ChainItemKind {
235235
data.args
236236
.iter()
237237
.filter_map(|x| match x {
238-
ast::AngleBracketedArg::Arg(ref generic_arg) => {
238+
ast::AngleBracketedArg::Arg(generic_arg) => {
239239
Some(generic_arg.clone())
240240
}
241241
_ => None,

src/imports.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ impl UseSegment {
158158
// Check if self == other with their aliases removed.
159159
fn equal_except_alias(&self, other: &Self) -> bool {
160160
match (&self.kind, &other.kind) {
161-
(UseSegmentKind::Ident(ref s1, _), UseSegmentKind::Ident(ref s2, _)) => s1 == s2,
161+
(UseSegmentKind::Ident(s1, _), UseSegmentKind::Ident(s2, _)) => s1 == s2,
162162
(UseSegmentKind::Slf(_), UseSegmentKind::Slf(_))
163163
| (UseSegmentKind::Super(_), UseSegmentKind::Super(_))
164164
| (UseSegmentKind::Crate(_), UseSegmentKind::Crate(_))
165165
| (UseSegmentKind::Glob, UseSegmentKind::Glob) => true,
166-
(UseSegmentKind::List(ref list1), UseSegmentKind::List(ref list2)) => list1 == list2,
166+
(UseSegmentKind::List(list1), UseSegmentKind::List(list2)) => list1 == list2,
167167
_ => false,
168168
}
169169
}
@@ -591,7 +591,7 @@ impl UseTree {
591591
if aliased_self {
592592
match self.path.last_mut() {
593593
Some(UseSegment {
594-
kind: UseSegmentKind::Ident(_, ref mut old_rename),
594+
kind: UseSegmentKind::Ident(_, old_rename),
595595
..
596596
}) => {
597597
assert!(old_rename.is_none());
@@ -667,7 +667,7 @@ impl UseTree {
667667
}),
668668
)
669669
| (None, None) => true,
670-
(Some(ref a), Some(ref b)) => is_same_visibility(a, b),
670+
(Some(a), Some(b)) => is_same_visibility(a, b),
671671
_ => false,
672672
}
673673
}
@@ -922,9 +922,7 @@ impl Ord for UseSegment {
922922
}
923923

924924
match (&self.kind, &other.kind) {
925-
(Slf(ref a), Slf(ref b))
926-
| (Super(ref a), Super(ref b))
927-
| (Crate(ref a), Crate(ref b)) => match (a, b) {
925+
(Slf(a), Slf(b)) | (Super(a), Super(b)) | (Crate(a), Crate(b)) => match (a, b) {
928926
(Some(sa), Some(sb)) => {
929927
if self.style_edition >= StyleEdition::Edition2024 {
930928
version_sort(sa.trim_start_matches("r#"), sb.trim_start_matches("r#"))
@@ -935,7 +933,7 @@ impl Ord for UseSegment {
935933
(_, _) => a.cmp(b),
936934
},
937935
(Glob, Glob) => Ordering::Equal,
938-
(Ident(ref pia, ref aa), Ident(ref pib, ref ab)) => {
936+
(Ident(pia, aa), Ident(pib, ab)) => {
939937
let (ia, ib) = if self.style_edition >= StyleEdition::Edition2024 {
940938
(pia.trim_start_matches("r#"), pib.trim_start_matches("r#"))
941939
} else {
@@ -977,7 +975,7 @@ impl Ord for UseSegment {
977975
(None, None) => Ordering::Equal,
978976
}
979977
}
980-
(List(ref a), List(ref b)) => {
978+
(List(a), List(b)) => {
981979
for (a, b) in a.iter().zip(b.iter()) {
982980
let ord = a.cmp(b);
983981
if ord != Ordering::Equal {

src/items.rs

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,30 +2273,61 @@ impl Rewrite for ast::Param {
22732273
};
22742274

22752275
if let Some(ref explicit_self) = self.to_self() {
2276-
rewrite_explicit_self(
2276+
return rewrite_explicit_self(
22772277
context,
22782278
explicit_self,
22792279
&param_attrs_result,
22802280
span,
22812281
shape,
22822282
has_multiple_attr_lines,
2283-
)
2284-
} else if is_named_param(self) {
2285-
let param_name = &self
2286-
.pat
2287-
.rewrite_result(context, Shape::legacy(shape.width, shape.indent))?;
2288-
let mut result = combine_strs_with_missing_comments(
2289-
context,
2290-
&param_attrs_result,
2291-
param_name,
2292-
span,
2293-
shape,
2294-
!has_multiple_attr_lines && !has_doc_comments,
2295-
)?;
2283+
);
2284+
}
2285+
if !is_named_param(self) {
2286+
return self.ty.rewrite_result(context, shape);
2287+
}
2288+
let param_name = &self
2289+
.pat
2290+
.rewrite_result(context, Shape::legacy(shape.width, shape.indent))?;
2291+
let mut result = combine_strs_with_missing_comments(
2292+
context,
2293+
&param_attrs_result,
2294+
param_name,
2295+
span,
2296+
shape,
2297+
!has_multiple_attr_lines && !has_doc_comments,
2298+
)?;
22962299

2297-
if !is_empty_infer(&*self.ty, self.pat.span) {
2298-
let (before_comment, after_comment) =
2299-
get_missing_param_comments(context, self.pat.span, self.ty.span, shape);
2300+
if !is_empty_infer(&*self.ty, self.pat.span) {
2301+
let (before_comment, after_comment) =
2302+
get_missing_param_comments(context, self.pat.span, self.ty.span, shape);
2303+
result.push_str(&before_comment);
2304+
result.push_str(colon_spaces(context.config));
2305+
result.push_str(&after_comment);
2306+
let overhead = last_line_width(&result);
2307+
let max_width = shape
2308+
.width
2309+
.checked_sub(overhead)
2310+
.max_width_error(shape.width, self.span())?;
2311+
if let Ok(ty_str) = self
2312+
.ty
2313+
.rewrite_result(context, Shape::legacy(max_width, shape.indent))
2314+
{
2315+
result.push_str(&ty_str);
2316+
} else {
2317+
let prev_str = if param_attrs_result.is_empty() {
2318+
param_attrs_result
2319+
} else {
2320+
param_attrs_result + &shape.to_string_with_newline(context.config)
2321+
};
2322+
2323+
result = combine_strs_with_missing_comments(
2324+
context,
2325+
&prev_str,
2326+
param_name,
2327+
span,
2328+
shape,
2329+
!has_multiple_attr_lines,
2330+
)?;
23002331
result.push_str(&before_comment);
23012332
result.push_str(colon_spaces(context.config));
23022333
result.push_str(&after_comment);
@@ -2305,45 +2336,14 @@ impl Rewrite for ast::Param {
23052336
.width
23062337
.checked_sub(overhead)
23072338
.max_width_error(shape.width, self.span())?;
2308-
if let Ok(ty_str) = self
2339+
let ty_str = self
23092340
.ty
2310-
.rewrite_result(context, Shape::legacy(max_width, shape.indent))
2311-
{
2312-
result.push_str(&ty_str);
2313-
} else {
2314-
let prev_str = if param_attrs_result.is_empty() {
2315-
param_attrs_result
2316-
} else {
2317-
param_attrs_result + &shape.to_string_with_newline(context.config)
2318-
};
2319-
2320-
result = combine_strs_with_missing_comments(
2321-
context,
2322-
&prev_str,
2323-
param_name,
2324-
span,
2325-
shape,
2326-
!has_multiple_attr_lines,
2327-
)?;
2328-
result.push_str(&before_comment);
2329-
result.push_str(colon_spaces(context.config));
2330-
result.push_str(&after_comment);
2331-
let overhead = last_line_width(&result);
2332-
let max_width = shape
2333-
.width
2334-
.checked_sub(overhead)
2335-
.max_width_error(shape.width, self.span())?;
2336-
let ty_str = self
2337-
.ty
2338-
.rewrite_result(context, Shape::legacy(max_width, shape.indent))?;
2339-
result.push_str(&ty_str);
2340-
}
2341+
.rewrite_result(context, Shape::legacy(max_width, shape.indent))?;
2342+
result.push_str(&ty_str);
23412343
}
2342-
2343-
Ok(result)
2344-
} else {
2345-
self.ty.rewrite_result(context, shape)
23462344
}
2345+
2346+
Ok(result)
23472347
}
23482348
}
23492349

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ impl Input {
556556

557557
fn to_directory_ownership(&self) -> Option<DirectoryOwnership> {
558558
match self {
559-
Input::File(ref file) => {
559+
Input::File(file) => {
560560
// If there exists a directory with the same name as an input,
561561
// then the input should be parsed as a sub module.
562562
let file_stem = file.file_stem()?;

src/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ impl MacroArgParser {
843843
) => {
844844
break;
845845
}
846-
TokenTree::Token(ref t, _) => {
846+
TokenTree::Token(t, _) => {
847847
buffer.push_str(&pprust::token_to_string(t));
848848
}
849849
_ => return None,
@@ -939,7 +939,7 @@ impl MacroArgParser {
939939
) if self.is_meta_var => {
940940
self.add_meta_variable(&mut iter)?;
941941
}
942-
TokenTree::Token(ref t, _) => self.update_buffer(t),
942+
TokenTree::Token(t, _) => self.update_buffer(t),
943943
&TokenTree::Delimited(_dspan, _spacing, delimited, ref tts) => {
944944
if !self.buf.is_empty() {
945945
if next_space(&self.last_tok.kind) == SpaceState::Always {

src/overflow.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<'a> OverflowableItem<'a> {
140140
OverflowableItem::MacroArg(MacroArg::Expr(expr)) => is_simple_expr(expr),
141141
OverflowableItem::MetaItemInner(meta_item_inner) => match meta_item_inner {
142142
ast::MetaItemInner::Lit(..) => true,
143-
ast::MetaItemInner::MetaItem(ref meta_item) => {
143+
ast::MetaItemInner::MetaItem(meta_item) => {
144144
matches!(meta_item.kind, ast::MetaItemKind::Word)
145145
}
146146
},
@@ -169,7 +169,7 @@ impl<'a> OverflowableItem<'a> {
169169
pub(crate) fn to_expr(&self) -> Option<&'a ast::Expr> {
170170
match self {
171171
OverflowableItem::Expr(expr) => Some(expr),
172-
OverflowableItem::MacroArg(MacroArg::Expr(ref expr)) => Some(expr),
172+
OverflowableItem::MacroArg(MacroArg::Expr(expr)) => Some(expr),
173173
_ => None,
174174
}
175175
}
@@ -178,8 +178,8 @@ impl<'a> OverflowableItem<'a> {
178178
match self {
179179
OverflowableItem::Expr(expr) => can_be_overflowed_expr(context, expr, len),
180180
OverflowableItem::MacroArg(macro_arg) => match macro_arg {
181-
MacroArg::Expr(ref expr) => can_be_overflowed_expr(context, expr, len),
182-
MacroArg::Ty(ref ty) => can_be_overflowed_type(context, ty, len),
181+
MacroArg::Expr(expr) => can_be_overflowed_expr(context, expr, len),
182+
MacroArg::Ty(ty) => can_be_overflowed_type(context, ty, len),
183183
MacroArg::Pat(..) => false,
184184
MacroArg::Item(..) => len == 1,
185185
MacroArg::Keyword(..) => false,
@@ -197,7 +197,10 @@ impl<'a> OverflowableItem<'a> {
197197
}
198198
}
199199

200-
fn special_cases(&self, config: &Config) -> impl Iterator<Item = &(&'static str, usize)> {
200+
fn special_cases(
201+
&self,
202+
config: &Config,
203+
) -> impl Iterator<Item = &(&'static str, usize)> + use<'_> {
201204
let base_cases = match self {
202205
OverflowableItem::MacroArg(..) => SPECIAL_CASE_MACROS,
203206
OverflowableItem::MetaItemInner(..) => SPECIAL_CASE_ATTR,

0 commit comments

Comments
 (0)