Skip to content

Lint against Self as an arbitrary self type #5861

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

Closed
Luro02 opened this issue Aug 3, 2020 · 0 comments · Fixed by #5869
Closed

Lint against Self as an arbitrary self type #5861

Luro02 opened this issue Aug 3, 2020 · 0 comments · Fixed by #5869
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-complexity Lint: Belongs in the complexity lint group

Comments

@Luro02
Copy link

Luro02 commented Aug 3, 2020

What it does

Suggest replacing self: Self with self, because as far as I know self is the same as self: Self.

Categories (optional)

  • Kind: clippy::style

What is the advantage of the recommended code over the original code?

  • reduces the amount of code
  • improves the readability of the code

Drawbacks

None.

Example

#![forbid(unsafe_code)]
#![warn(rust_2018_idioms)]
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]

pub enum ValType {
    I32,
    I64,
    F32,
    F64,
}

impl ValType {
    #[must_use]
    pub fn bytes(self: Self) -> usize {
        match self {
            Self::I32 | Self::F32 => 4,
            Self::I64 | Self::F64 => 8,
        }
    }
}

fn main() {
    assert_eq!(ValType::I32.bytes(), 4);
    assert_eq!(ValType::bytes(ValType::I32), 4);
}

Could be written as:

#![forbid(unsafe_code)]
#![warn(rust_2018_idioms)]
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]

pub enum ValType {
    I32,
    I64,
    F32,
    F64,
}

impl ValType {
    #[must_use]
    pub fn bytes(self) -> usize {
        match self {
            Self::I32 | Self::F32 => 4,
            Self::I64 | Self::F64 => 8,
        }
    }
}

fn main() {
    assert_eq!(ValType::I32.bytes(), 4);
    assert_eq!(ValType::bytes(ValType::I32), 4);
}

Relevant issue for the feature: rust-lang/rust#44874

@Luro02 Luro02 added the A-lint Area: New lints label Aug 3, 2020
wiomoc added a commit to wiomoc/rust-clippy that referenced this issue Aug 4, 2020
wiomoc added a commit to wiomoc/rust-clippy that referenced this issue Aug 4, 2020
wiomoc added a commit to wiomoc/rust-clippy that referenced this issue Aug 4, 2020
@flip1995 flip1995 added L-complexity Lint: Belongs in the complexity lint group good-first-issue These issues are a good way to get started with Clippy labels Aug 4, 2020
flip1995 added a commit to flip1995/rust-clippy that referenced this issue Aug 10, 2020
…to,flip1995

New lint against `Self` as an arbitrary self type

Fixes rust-lang#5861

changelog: * [`needless_arbitrary_self_type`] [rust-lang#5869](rust-lang#5869)
@bors bors closed this as completed in e0a4988 Aug 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-complexity Lint: Belongs in the complexity lint group
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants