-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
A-lintArea: New lintsArea: New lintsL-complexityLint: Belongs in the complexity lint groupLint: Belongs in the complexity lint groupgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
Description
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
dima74
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lintsL-complexityLint: Belongs in the complexity lint groupLint: Belongs in the complexity lint groupgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy