Skip to content

Commit 268b4f0

Browse files
committed
defer changes for zero argument functions until style_edition=2027
This moves changes that were originally gated by `version=Two` to `style_edition=2027` instead of releasing them with `style_edition=2024`.
1 parent 304d28c commit 268b4f0

14 files changed

+74
-6
lines changed

src/config/options.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -536,13 +536,15 @@ impl From<StyleEdition> for rustc_span::edition::Edition {
536536

537537
impl PartialOrd for StyleEdition {
538538
fn partial_cmp(&self, other: &StyleEdition) -> Option<std::cmp::Ordering> {
539-
// FIXME(ytmimi): Update the `StyleEdition::Edition2027` logic when the
540-
// `Edition::Edition2027` becomes available in the compiler
539+
// FIXME(ytmimi): Update `StyleEdition::Edition2027` logic when
540+
// `rustc_span::edition::Edition::Edition2027` becomes available in the compiler
541541
match (self, other) {
542542
(Self::Edition2027, Self::Edition2027) => Some(std::cmp::Ordering::Equal),
543543
(_, Self::Edition2027) => Some(std::cmp::Ordering::Less),
544544
(Self::Edition2027, _) => Some(std::cmp::Ordering::Greater),
545-
_ => rustc_span::edition::Edition::partial_cmp(&(*self).into(), &(*other).into()),
545+
(Self::Edition2015 | Self::Edition2018 | Self::Edition2021 | Self::Edition2024, _) => {
546+
rustc_span::edition::Edition::partial_cmp(&(*self).into(), &(*other).into())
547+
}
546548
}
547549
}
548550
}

src/items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2570,7 +2570,7 @@ fn rewrite_fn_base(
25702570
.last()
25712571
.map_or(false, |last_line| last_line.contains("//"));
25722572

2573-
if context.config.style_edition() >= StyleEdition::Edition2024 {
2573+
if context.config.style_edition() >= StyleEdition::Edition2027 {
25742574
if closing_paren_overflow_max_width {
25752575
result.push(')');
25762576
result.push_str(&indent.to_string_with_newline(context.config));

tests/target/issue-3278/version_two.rs renamed to tests/source/issue-3278/style_edition_2027.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-style_edition: 2024
1+
// rustfmt-style_edition: 2027
22

33
pub fn parse_conditional<'a, I: 'a>()
44
-> impl Parser<Input = I, Output = Expr, PartialState = ()> + 'a
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// rustfmt-style_edition: 2027
2+
// Tests that a function which is almost short enough, but not quite, gets
3+
// formatted correctly.
4+
5+
impl Foo {
6+
fn some_input(&mut self, input: Input, input_path: Option<PathBuf>, ) -> (Input, Option<PathBuf>) {}
7+
8+
fn some_inpu(&mut self, input: Input, input_path: Option<PathBuf>) -> (Input, Option<PathBuf>) {}
9+
}
10+
11+
// #1843
12+
#[allow(non_snake_case)]
13+
pub extern "C" fn Java_com_exonum_binding_storage_indices_ValueSetIndexProxy_nativeContainsByHash() -> bool {
14+
false
15+
}
16+
17+
// #3009
18+
impl Something {
19+
fn my_function_name_is_way_to_long_but_used_as_a_case_study_or_an_example_its_fine(
20+
) -> Result< (), String > {}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// rustfmt-style_edition: 2024
2+
3+
pub fn parse_conditional<'a, I: 'a>(
4+
) -> impl Parser<Input = I, Output = Expr, PartialState = ()> + 'a
5+
where
6+
I: Stream<Item = char>,
7+
{
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// rustfmt-style_edition: 2027
2+
3+
pub fn parse_conditional<'a, I: 'a>()
4+
-> impl Parser<Input = I, Output = Expr, PartialState = ()> + 'a
5+
where
6+
I: Stream<Item = char>,
7+
{
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// rustfmt-style_edition: 2024
2+
// Tests that a function which is almost short enough, but not quite, gets
3+
// formatted correctly.
4+
5+
impl Foo {
6+
fn some_input(
7+
&mut self,
8+
input: Input,
9+
input_path: Option<PathBuf>,
10+
) -> (Input, Option<PathBuf>) {
11+
}
12+
13+
fn some_inpu(&mut self, input: Input, input_path: Option<PathBuf>) -> (Input, Option<PathBuf>) {
14+
}
15+
}
16+
17+
// #1843
18+
#[allow(non_snake_case)]
19+
pub extern "C" fn Java_com_exonum_binding_storage_indices_ValueSetIndexProxy_nativeContainsByHash(
20+
) -> bool {
21+
false
22+
}
23+
24+
// #3009
25+
impl Something {
26+
fn my_function_name_is_way_to_long_but_used_as_a_case_study_or_an_example_its_fine(
27+
) -> Result<(), String> {
28+
}
29+
}

tests/target/long-fn-1/version_two.rs renamed to tests/target/long-fn-1/style_edition_2027.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-style_edition: 2024
1+
// rustfmt-style_edition: 2027
22
// Tests that a function which is almost short enough, but not quite, gets
33
// formatted correctly.
44

0 commit comments

Comments
 (0)