Skip to content

2024 edition formats logically similar elements non-uniformly #6452

Closed as not planned
@TomFryersMidsummer

Description

@TomFryersMidsummer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions