Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024 edition formats logically similar elements non-uniformly #6452

Closed
TomFryersMidsummer opened this issue Jan 23, 2025 · 1 comment
Closed
Labels
a-2024-edition Style Edition 2024

Comments

@TomFryersMidsummer
Copy link

I've just tried Rustfmt 2024 across our 20 000 line codebase. There are plenty of improvements, but there also look to be lots of cases where it's making formatting worse, by making things that are logically similar appear differently. This makes the code much more difficult to scan.

‘Things that are logically equivalent’ includes the values in arrays, vec!s or similar, as well as the arguments to functions or macros that take equivalent arguments, such as assert_eq! or, here, crate::intersect_polygons.

I think it's easiest to illustrate what I mean with a few examples of real code.

// 2021
    let equilateral = [
        v![1.0, 0.0],
        v![-0.5, f64::sqrt(3.0) / 2.0],
        v![-0.5, -f64::sqrt(3.0) / 2.0],
    ];
// 2024
    let equilateral = [v![1.0, 0.0], v![-0.5, f64::sqrt(3.0) / 2.0], v![
        -0.5,
        -f64::sqrt(3.0) / 2.0
    ]];

// 2021
    assert_eq!(
        lines,
        [[0, 1, 4, 5], [0, 5, 4, 3], [1, 2, 5, 4], [2, 3, 4, 5]],
    );

// 2024
    assert_eq!(lines, [[0, 1, 4, 5], [0, 5, 4, 3], [1, 2, 5, 4], [
        2, 3, 4, 5
    ]],);

// 2021
    assert_eq!(
        lines,
        [
            vec![2, 3, 5, 7],
            vec![2, 7, 6, 4, 5, 3],
            vec![4, 4, 4, 8, 10, 9],
        ],
    );
// 2024
    assert_eq!(lines, [vec![2, 3, 5, 7], vec![2, 7, 6, 4, 5, 3], vec![
        4, 4, 4, 8, 10, 9
    ],],);

// 2021
    let region = [
        [123.66409, -146.59903],
        [123.623795, -146.55176],
        [123.57245, -146.6],
    ]
    .map(NPoint::from_xy);
// 2024
    let region = [[123.66409, -146.59903], [123.623795, -146.55176], [
        123.57245, -146.6,
    ]]
    .map(NPoint::from_xy);

// 2021
    let out = crate::intersect_polygons(
        &U,
        &[v![-0.1, 0.4], v![1.1, 0.4], v![1.1, 0.6], v![-0.1, 0.6]],
    )
    .collect::<Vec<_>>();
// 2024
    let out = crate::intersect_polygons(&U, &[v![-0.1, 0.4], v![1.1, 0.4], v![1.1, 0.6], v![
        -0.1, 0.6
    ]])
    .collect::<Vec<_>>();

// 2021
    let expected = [
        [v![0.0, 0.4], v![0.2, 0.4], v![0.2, 0.6], v![0.0, 0.6]],
        [v![0.8, 0.4], v![1.0, 0.4], v![1.0, 0.6], v![0.8, 0.6]],
    ];
// 2024
    let expected = [[v![0.0, 0.4], v![0.2, 0.4], v![0.2, 0.6], v![0.0, 0.6]], [
        v![0.8, 0.4],
        v![1.0, 0.4],
        v![1.0, 0.6],
        v![0.8, 0.6],
    ]];

// 2021
    let inner = [
        v![0.0, 0.0],
        v![1.0, 0.0],
        v![0.5, 0.5],
        v![1.0, 1.0],
        v![0.0, 1.0],
    ];
// 2024
    let inner = [v![0.0, 0.0], v![1.0, 0.0], v![0.5, 0.5], v![1.0, 1.0], v![
        0.0, 1.0
    ]];

// 2021
    assert_eq!(
        array::from_fn(|i| (2u8 + i as u8).try_into().unwrap()),
        [T::two(), T::three(), T::four(), T::five(), T::six()],
    );
// 2024
    assert_eq!(array::from_fn(|i| (2u8 + i as u8).try_into().unwrap()), [
        T::two(),
        T::three(),
        T::four(),
        T::five(),
        T::six()
    ],);
    

This seems to happen most often in test code.

@ytmimi ytmimi added the a-2024-edition Style Edition 2024 label Jan 23, 2025
@ytmimi
Copy link
Contributor

ytmimi commented Jan 23, 2025

This is a result of rust-lang/rust#123751, and changing the default for overflow_delimited_expr to true instead of false when using style_edition=2024. If you're on nightly you can set overflow_delimited_expr=false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-2024-edition Style Edition 2024
Projects
None yet
Development

No branches or pull requests

2 participants