diff --git a/src/config/options.rs b/src/config/options.rs index c0f4bdc135c..14ffdd21707 100644 --- a/src/config/options.rs +++ b/src/config/options.rs @@ -536,7 +536,16 @@ impl From for rustc_span::edition::Edition { impl PartialOrd for StyleEdition { fn partial_cmp(&self, other: &StyleEdition) -> Option { - rustc_span::edition::Edition::partial_cmp(&(*self).into(), &(*other).into()) + // 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), + (Self::Edition2027, _) => Some(std::cmp::Ordering::Greater), + (Self::Edition2015 | Self::Edition2018 | Self::Edition2021 | Self::Edition2024, _) => { + rustc_span::edition::Edition::partial_cmp(&(*self).into(), &(*other).into()) + } + } } } @@ -684,3 +693,41 @@ config_option_with_style_edition_default!( MakeBackup, bool, _ => false; PrintMisformattedFileNames, bool, _ => false; ); + +#[test] +fn style_edition_comparisons() { + // Style Edition 2015 + assert!(StyleEdition::Edition2015 == StyleEdition::Edition2015); + assert!(StyleEdition::Edition2015 < StyleEdition::Edition2018); + assert!(StyleEdition::Edition2015 < StyleEdition::Edition2021); + assert!(StyleEdition::Edition2015 < StyleEdition::Edition2024); + assert!(StyleEdition::Edition2015 < StyleEdition::Edition2027); + + // Style Edition 2018 + assert!(StyleEdition::Edition2018 > StyleEdition::Edition2015); + assert!(StyleEdition::Edition2018 == StyleEdition::Edition2018); + assert!(StyleEdition::Edition2018 < StyleEdition::Edition2021); + assert!(StyleEdition::Edition2018 < StyleEdition::Edition2024); + assert!(StyleEdition::Edition2018 < StyleEdition::Edition2027); + + // Style Edition 2021 + assert!(StyleEdition::Edition2021 > StyleEdition::Edition2015); + assert!(StyleEdition::Edition2021 > StyleEdition::Edition2018); + assert!(StyleEdition::Edition2021 == StyleEdition::Edition2021); + assert!(StyleEdition::Edition2021 < StyleEdition::Edition2024); + assert!(StyleEdition::Edition2021 < StyleEdition::Edition2027); + + // Style Edition 2024 + assert!(StyleEdition::Edition2024 > StyleEdition::Edition2015); + assert!(StyleEdition::Edition2024 > StyleEdition::Edition2018); + assert!(StyleEdition::Edition2024 > StyleEdition::Edition2021); + assert!(StyleEdition::Edition2024 == StyleEdition::Edition2024); + assert!(StyleEdition::Edition2024 < StyleEdition::Edition2027); + + // Style Edition 2024 + assert!(StyleEdition::Edition2027 > StyleEdition::Edition2015); + assert!(StyleEdition::Edition2027 > StyleEdition::Edition2018); + assert!(StyleEdition::Edition2027 > StyleEdition::Edition2021); + assert!(StyleEdition::Edition2027 > StyleEdition::Edition2024); + assert!(StyleEdition::Edition2027 == StyleEdition::Edition2027); +} 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.