Skip to content

Stop suggesting alphabetic arrangement between different types of items (structs vs funcs vs mods etc) #14875

Open
@amab8901

Description

@amab8901

Summary

I think that arbitrary_source_item_ordering should stop comparing names that belong to different types of items.

For example I want main() to always be at the top, and I want mod tests {} to always be at the bottom. But if I have an function called send_to_database(), this lint will send me an annoying suggestion to "put mod tests {} before send_to_database(). Yet turning off this lint entirely isn't desirable either because it's valuable to have items of the same type arranged alphabetically (for example fields in a struct).

Lint Name

arbitrary_source_item_ordering

Reproducer

I tried this code:

fn main() {
    let structy = Structy::default();
    let _field1 = structy.field1();
    let _field_one = Structy::field1(&structy);
}

#[derive(Default)]
pub(crate) struct Structy {
    field1: String,
}

impl Structy {
    pub(crate) fn field1(&self) -> &String {
        &self.field1
    }
}

I saw this happen:

incorrect ordering of items (module item groupings specify another order)

I expected to see this happen:
silence

Version

rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-unknown-linux-gnu
release: 1.87.0
LLVM version: 20.1.1

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions