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

wrong_self_convention wrongly detects s: Self as self #7179

Closed
tspiteri opened this issue May 6, 2021 · 2 comments · Fixed by #7215
Closed

wrong_self_convention wrongly detects s: Self as self #7179

tspiteri opened this issue May 6, 2021 · 2 comments · Fixed by #7215
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@tspiteri
Copy link
Contributor

tspiteri commented May 6, 2021

pub struct S(i32);

impl S {
    pub fn from_be(s: Self) -> Self {
        S(i32::from_be(s.0))
    }
}

Clippy says:

    Checking playground v0.0.1 (/playground)
warning: methods called `from_*` usually take no `self`
 --> src/lib.rs:4:20
  |
4 |     pub fn from_be(s: Self) -> Self {
  |                    ^
  |
  = note: `#[warn(clippy::wrong_self_convention)]` on by default
  = help: consider choosing a less ambiguous name
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention

warning: 1 warning emitted

    Finished dev [unoptimized + debuginfo] target(s) in 0.57s

Meta

  • cargo clippy -V: 0.1.53 (2021-05-05 bacf770)
@tspiteri tspiteri 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, 2021
@llogiq
Copy link
Contributor

llogiq commented May 8, 2021

Well, apart from the name, those are equivalent, and you could use self instead of s.

However, we could fix this by checking the pattern and use that name.

@tspiteri
Copy link
Contributor Author

tspiteri commented May 9, 2021

Well, apart from the name, those are equivalent, and you could use self instead of s.

They are equivalent in the implementation of the method, but not in calling the method. You cannot call 12i32.from_be() (which is what the lint is protecting against) but you can call i32::from_be(12i32) (which should be allowed by the lint). As is the lint would not like the standard library from_be function for example.

bors added a commit that referenced this issue May 13, 2021
Trigger [`wrong_self_convention`] only if it has implicit self

Lint [`wrong_self_convention`] only if the impl or trait has `self` _per sé_.

Fixes: #7179

changelog: trigger [`wrong_self_convention`] only if it has implicit self
@bors bors closed this as completed in 08ce8bb May 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants