Skip to content

arbitrary_source_item_ordering should allow sorting constructors first #14739

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

Open
pv42 opened this issue May 6, 2025 · 1 comment · May be fixed by #14782
Open

arbitrary_source_item_ordering should allow sorting constructors first #14739

pv42 opened this issue May 6, 2025 · 1 comment · May be fixed by #14782
Assignees

Comments

@pv42
Copy link

pv42 commented May 6, 2025

Summary

Add option to expect constructor (new) functions first in impl blocks.

Lint Name

arbitrary_source_item_ordering

Reproducer

I tried this code:

pub struct Foo {
    bar: i32,
}

impl Foo {
    pub fn new(bar: i32) -> Self {
        Self { bar }
    }
    pub fn bar(&self) -> i32 {
        self.bar
    }
}

I saw this happen:

warning: incorrect ordering of items (must be alphabetically ordered)
 --> src/foo.rs:9:12
  |
9 |     pub fn bar(&self) -> i32 {
  |            ^^^
  |
note: should be placed before `new`
 --> src/foo.rs:6:12
  |
6 |     pub fn new(bar: i32) -> Self {
  |            ^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arbitrary_source_item_ordering

I expected to see this happen:
Nothing.
Static functions called new should be either ignored or expected to be the first item.

Version

rustc 1.88.0-nightly (2e6882ac5 2025-05-05)
binary: rustc
commit-hash: 2e6882ac5be27a73293d6f7ae56397fdf32848de
commit-date: 2025-05-05
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.4

Additional Labels

No response

@pv42 pv42 added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels May 6, 2025
@samueltardieu samueltardieu added C-feature-request and removed C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels May 6, 2025
@relaxcn
Copy link
Contributor

relaxcn commented May 11, 2025

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants