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 triggers in trait method implementations #7123

Closed
kangalio opened this issue Apr 22, 2021 · 1 comment
Closed

wrong_self_convention triggers in trait method implementations #7123

kangalio opened this issue Apr 22, 2021 · 1 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

Comments

@kangalio
Copy link

kangalio commented Apr 22, 2021

Lint name: wrong_self_convention

I tried this code:

struct Error {}

trait FromMeta: Sized {
    fn from_char(_value: char) -> Result<Self, Error> { Err(Error {}) }
    fn from_bool(_value: bool) -> Result<Self, Error> { Err(Error {}) }
}

impl FromMeta for char {
    fn from_char(value: Self) -> Result<Self, Error> { Ok(value) }
}

impl FromMeta for bool {
    fn from_bool(value: Self) -> Result<Self, Error> { Ok(value) }
}

I expected to see this happen: nothing is linted

Instead, this happened: the from_char implementation for char and from_bool implementation for bool were linted because Clippy thinks the value: Self parameter is a self parameter and from_* methods shouldn't take self parameters.

However, FromMeta is a trait and will be implemented by lots of different types. On some types, the trait names may seem slightly awkward, but I think there is not much the programmer can realistically do about that. I think it would be beneficial if this lint weren't triggered in trait implementations.

Context: the FromMeta trait is similar in spirit to serde's Deserialize. It comes from the darling crate, a proc-macro attribute parser. Links for the offending trait implementations: bool and char.

Meta

  • cargo clippy -V: clippy 0.1.53 (b849326 2021-04-21)
  • rustc -Vv:
rustc 1.53.0-nightly (b84932674 2021-04-21)
binary: rustc
commit-hash: b849326744a8eec939e592f0ab13bff85cc865d3
commit-date: 2021-04-21
host: x86_64-unknown-linux-gnu
release: 1.53.0-nightly
LLVM version: 12.0.0
@kangalio kangalio 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 Apr 22, 2021
@kangalio
Copy link
Author

This seems to be a duplicate of #7032. Sorry for not searching for duplicates before posting

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

No branches or pull requests

1 participant