From 4a007a6cd30b6381b9026f8590021a3792ce6813 Mon Sep 17 00:00:00 2001 From: Yacin Tmimi Date: Tue, 8 Oct 2024 23:24:32 -0400 Subject: [PATCH] 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`. --- src/config/options.rs | 4 +-- src/items.rs | 2 +- .../{version_one.rs => style_edition_2015.rs} | 0 .../{version_two.rs => style_edition_2024.rs} | 0 .../issue-3278/style_edition_2027.rs} | 2 +- .../{version_one.rs => style_edition_2015.rs} | 0 .../{version_two.rs => style_edition_2024.rs} | 0 tests/source/long-fn-1/style_edition_2027.rs | 21 ++++++++++++++ .../{version_one.rs => style_edition_2015.rs} | 0 tests/target/issue-3278/style_edition_2024.rs | 8 +++++ tests/target/issue-3278/style_edition_2027.rs | 8 +++++ .../{version_one.rs => style_edition_2015.rs} | 0 tests/target/long-fn-1/style_edition_2024.rs | 29 +++++++++++++++++++ .../{version_two.rs => style_edition_2027.rs} | 2 +- 14 files changed, 71 insertions(+), 5 deletions(-) rename tests/source/issue-3278/{version_one.rs => style_edition_2015.rs} (100%) rename tests/source/issue-3278/{version_two.rs => style_edition_2024.rs} (100%) rename tests/{target/issue-3278/version_two.rs => source/issue-3278/style_edition_2027.rs} (82%) rename tests/source/long-fn-1/{version_one.rs => style_edition_2015.rs} (100%) rename tests/source/long-fn-1/{version_two.rs => style_edition_2024.rs} (100%) create mode 100644 tests/source/long-fn-1/style_edition_2027.rs rename tests/target/issue-3278/{version_one.rs => style_edition_2015.rs} (100%) create mode 100644 tests/target/issue-3278/style_edition_2024.rs create mode 100644 tests/target/issue-3278/style_edition_2027.rs rename tests/target/long-fn-1/{version_one.rs => style_edition_2015.rs} (100%) create mode 100644 tests/target/long-fn-1/style_edition_2024.rs rename tests/target/long-fn-1/{version_two.rs => style_edition_2027.rs} (95%) diff --git a/src/config/options.rs b/src/config/options.rs index 3cb836dbf20..baaa6375d0a 100644 --- a/src/config/options.rs +++ b/src/config/options.rs @@ -536,8 +536,8 @@ impl From for rustc_span::edition::Edition { impl PartialOrd for StyleEdition { fn partial_cmp(&self, other: &StyleEdition) -> Option { - // FIXME(ytmimi): Update the `StyleEdition::Edition2027` logic when the - // `Edition::Edition2027` becomes available in the compiler + // FIXME(ytmimi): Update `StyleEdition::Edition2027` logic when + // `rustc_span::edition::Edition::Edition2027` becomes available in the compiler match (self, other) { (Self::Edition2027, Self::Edition2027) => Some(std::cmp::Ordering::Equal), (_, Self::Edition2027) => Some(std::cmp::Ordering::Less), diff --git a/src/items.rs b/src/items.rs index fc043a697e0..cf4c40c3c7a 100644 --- a/src/items.rs +++ b/src/items.rs @@ -2570,7 +2570,7 @@ fn rewrite_fn_base( .last() .map_or(false, |last_line| last_line.contains("//")); - if context.config.style_edition() >= StyleEdition::Edition2024 { + if context.config.style_edition() >= StyleEdition::Edition2027 { if closing_paren_overflow_max_width { result.push(')'); result.push_str(&indent.to_string_with_newline(context.config)); diff --git a/tests/source/issue-3278/version_one.rs b/tests/source/issue-3278/style_edition_2015.rs similarity index 100% rename from tests/source/issue-3278/version_one.rs rename to tests/source/issue-3278/style_edition_2015.rs diff --git a/tests/source/issue-3278/version_two.rs b/tests/source/issue-3278/style_edition_2024.rs similarity index 100% rename from tests/source/issue-3278/version_two.rs rename to tests/source/issue-3278/style_edition_2024.rs diff --git a/tests/target/issue-3278/version_two.rs b/tests/source/issue-3278/style_edition_2027.rs similarity index 82% rename from tests/target/issue-3278/version_two.rs rename to tests/source/issue-3278/style_edition_2027.rs index eb605e509f9..f33dffeb7f5 100644 --- a/tests/target/issue-3278/version_two.rs +++ b/tests/source/issue-3278/style_edition_2027.rs @@ -1,4 +1,4 @@ -// rustfmt-style_edition: 2024 +// rustfmt-style_edition: 2027 pub fn parse_conditional<'a, I: 'a>() -> impl Parser + 'a diff --git a/tests/source/long-fn-1/version_one.rs b/tests/source/long-fn-1/style_edition_2015.rs similarity index 100% rename from tests/source/long-fn-1/version_one.rs rename to tests/source/long-fn-1/style_edition_2015.rs diff --git a/tests/source/long-fn-1/version_two.rs b/tests/source/long-fn-1/style_edition_2024.rs similarity index 100% rename from tests/source/long-fn-1/version_two.rs rename to tests/source/long-fn-1/style_edition_2024.rs diff --git a/tests/source/long-fn-1/style_edition_2027.rs b/tests/source/long-fn-1/style_edition_2027.rs new file mode 100644 index 00000000000..ded5a38d179 --- /dev/null +++ b/tests/source/long-fn-1/style_edition_2027.rs @@ -0,0 +1,21 @@ +// rustfmt-style_edition: 2027 +// Tests that a function which is almost short enough, but not quite, gets +// formatted correctly. + +impl Foo { + fn some_input(&mut self, input: Input, input_path: Option, ) -> (Input, Option) {} + + fn some_inpu(&mut self, input: Input, input_path: Option) -> (Input, Option) {} +} + +// #1843 +#[allow(non_snake_case)] +pub extern "C" fn Java_com_exonum_binding_storage_indices_ValueSetIndexProxy_nativeContainsByHash() -> bool { + false +} + +// #3009 +impl Something { + fn my_function_name_is_way_to_long_but_used_as_a_case_study_or_an_example_its_fine( +) -> Result< (), String > {} +} diff --git a/tests/target/issue-3278/version_one.rs b/tests/target/issue-3278/style_edition_2015.rs similarity index 100% rename from tests/target/issue-3278/version_one.rs rename to tests/target/issue-3278/style_edition_2015.rs diff --git a/tests/target/issue-3278/style_edition_2024.rs b/tests/target/issue-3278/style_edition_2024.rs new file mode 100644 index 00000000000..676db3b20f8 --- /dev/null +++ b/tests/target/issue-3278/style_edition_2024.rs @@ -0,0 +1,8 @@ +// rustfmt-style_edition: 2024 + +pub fn parse_conditional<'a, I: 'a>( +) -> impl Parser + 'a +where + I: Stream, +{ +} diff --git a/tests/target/issue-3278/style_edition_2027.rs b/tests/target/issue-3278/style_edition_2027.rs new file mode 100644 index 00000000000..f33dffeb7f5 --- /dev/null +++ b/tests/target/issue-3278/style_edition_2027.rs @@ -0,0 +1,8 @@ +// rustfmt-style_edition: 2027 + +pub fn parse_conditional<'a, I: 'a>() +-> impl Parser + 'a +where + I: Stream, +{ +} diff --git a/tests/target/long-fn-1/version_one.rs b/tests/target/long-fn-1/style_edition_2015.rs similarity index 100% rename from tests/target/long-fn-1/version_one.rs rename to tests/target/long-fn-1/style_edition_2015.rs diff --git a/tests/target/long-fn-1/style_edition_2024.rs b/tests/target/long-fn-1/style_edition_2024.rs new file mode 100644 index 00000000000..f5edca5ee7d --- /dev/null +++ b/tests/target/long-fn-1/style_edition_2024.rs @@ -0,0 +1,29 @@ +// rustfmt-style_edition: 2024 +// Tests that a function which is almost short enough, but not quite, gets +// formatted correctly. + +impl Foo { + fn some_input( + &mut self, + input: Input, + input_path: Option, + ) -> (Input, Option) { + } + + fn some_inpu(&mut self, input: Input, input_path: Option) -> (Input, Option) { + } +} + +// #1843 +#[allow(non_snake_case)] +pub extern "C" fn Java_com_exonum_binding_storage_indices_ValueSetIndexProxy_nativeContainsByHash( +) -> bool { + false +} + +// #3009 +impl Something { + fn my_function_name_is_way_to_long_but_used_as_a_case_study_or_an_example_its_fine( + ) -> Result<(), String> { + } +} diff --git a/tests/target/long-fn-1/version_two.rs b/tests/target/long-fn-1/style_edition_2027.rs similarity index 95% rename from tests/target/long-fn-1/version_two.rs rename to tests/target/long-fn-1/style_edition_2027.rs index f6007398bcc..87361f0b96b 100644 --- a/tests/target/long-fn-1/version_two.rs +++ b/tests/target/long-fn-1/style_edition_2027.rs @@ -1,4 +1,4 @@ -// rustfmt-style_edition: 2024 +// rustfmt-style_edition: 2027 // Tests that a function which is almost short enough, but not quite, gets // formatted correctly.