Skip to content

Commit

Permalink
defer changes for zero argument functions until style_edition=2027
Browse files Browse the repository at this point in the history
This moves changes that were originally gated by `version=Two` to
`style_edition=2027` instead of releasing them with
`style_edition=2024`.
  • Loading branch information
ytmimi committed Oct 10, 2024
1 parent ac8212c commit 00e64f0
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/config/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,15 @@ impl From<StyleEdition> for rustc_span::edition::Edition {

impl PartialOrd for StyleEdition {
fn partial_cmp(&self, other: &StyleEdition) -> Option<std::cmp::Ordering> {
// 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),
(Self::Edition2027, _) => Some(std::cmp::Ordering::Greater),
_ => rustc_span::edition::Edition::partial_cmp(&(*self).into(), &(*other).into()),
(Self::Edition2015 | Self::Edition2018 | Self::Edition2021 | Self::Edition2024, _) => {
rustc_span::edition::Edition::partial_cmp(&(*self).into(), &(*other).into())
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-style_edition: 2024
// rustfmt-style_edition: 2027

pub fn parse_conditional<'a, I: 'a>()
-> impl Parser<Input = I, Output = Expr, PartialState = ()> + 'a
Expand Down
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions tests/source/long-fn-1/style_edition_2027.rs
Original file line number Diff line number Diff line change
@@ -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<PathBuf>, ) -> (Input, Option<PathBuf>) {}

fn some_inpu(&mut self, input: Input, input_path: Option<PathBuf>) -> (Input, Option<PathBuf>) {}
}

// #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 > {}
}
File renamed without changes.
8 changes: 8 additions & 0 deletions tests/target/issue-3278/style_edition_2024.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// rustfmt-style_edition: 2024

pub fn parse_conditional<'a, I: 'a>(
) -> impl Parser<Input = I, Output = Expr, PartialState = ()> + 'a
where
I: Stream<Item = char>,
{
}
8 changes: 8 additions & 0 deletions tests/target/issue-3278/style_edition_2027.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// rustfmt-style_edition: 2027

pub fn parse_conditional<'a, I: 'a>()
-> impl Parser<Input = I, Output = Expr, PartialState = ()> + 'a
where
I: Stream<Item = char>,
{
}
File renamed without changes.
29 changes: 29 additions & 0 deletions tests/target/long-fn-1/style_edition_2024.rs
Original file line number Diff line number Diff line change
@@ -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<PathBuf>,
) -> (Input, Option<PathBuf>) {
}

fn some_inpu(&mut self, input: Input, input_path: Option<PathBuf>) -> (Input, Option<PathBuf>) {
}
}

// #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> {
}
}
Original file line number Diff line number Diff line change
@@ -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.

Expand Down

0 comments on commit 00e64f0

Please sign in to comment.