Skip to content

Commit 67d85bc

Browse files
authored
Merge pull request #3224 from matthiaskrgr/clippy_self__use_self
fix some clippy::pedantic warnings found in the codebase.
2 parents 8e80866 + 9fae469 commit 67d85bc

File tree

6 files changed

+19
-21
lines changed

6 files changed

+19
-21
lines changed

clippy_dev/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ pub struct Lint {
3535
}
3636

3737
impl Lint {
38-
pub fn new(name: &str, group: &str, desc: &str, deprecation: Option<&str>, module: &str) -> Lint {
39-
Lint {
38+
pub fn new(name: &str, group: &str, desc: &str, deprecation: Option<&str>, module: &str) -> Self {
39+
Self {
4040
name: name.to_lowercase(),
4141
group: group.to_string(),
4242
desc: NL_ESCAPE_RE.replace(&desc.replace("\\\"", "\""), "").to_string(),
@@ -46,12 +46,12 @@ impl Lint {
4646
}
4747

4848
/// Returns all non-deprecated lints
49-
pub fn active_lints(lints: &[Lint]) -> impl Iterator<Item=&Lint> {
49+
pub fn active_lints(lints: &[Self]) -> impl Iterator<Item=&Self> {
5050
lints.iter().filter(|l| l.deprecation.is_none())
5151
}
5252

5353
/// Returns the lints in a HashMap, grouped by the different lint groups
54-
pub fn by_lint_group(lints: &[Lint]) -> HashMap<String, Vec<Lint>> {
54+
pub fn by_lint_group(lints: &[Self]) -> HashMap<String, Vec<Self>> {
5555
lints.iter().map(|lint| (lint.group.to_string(), lint.clone())).into_group_map()
5656
}
5757
}

clippy_lints/src/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ impl Constant {
123123
(&Constant::Tuple(ref l), &Constant::Tuple(ref r)) | (&Constant::Vec(ref l), &Constant::Vec(ref r)) => l
124124
.iter()
125125
.zip(r.iter())
126-
.map(|(li, ri)| Constant::partial_cmp(tcx, cmp_type, li, ri))
126+
.map(|(li, ri)| Self::partial_cmp(tcx, cmp_type, li, ri))
127127
.find(|r| r.map_or(true, |o| o != Ordering::Equal))
128128
.unwrap_or_else(|| Some(l.len().cmp(&r.len()))),
129129
(&Constant::Repeat(ref lv, ref ls), &Constant::Repeat(ref rv, ref rs)) => {
130-
match Constant::partial_cmp(tcx, cmp_type, lv, rv) {
130+
match Self::partial_cmp(tcx, cmp_type, lv, rv) {
131131
Some(Equal) => Some(ls.cmp(rs)),
132132
x => x,
133133
}

clippy_lints/src/duration_subsec.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DurationSubsec {
4646
if let Some((Constant::Int(divisor), _)) = constant(cx, cx.tables, right);
4747
then {
4848
let suggested_fn = match (method_path.ident.as_str().as_ref(), divisor) {
49-
("subsec_micros", 1_000) => "subsec_millis",
49+
("subsec_micros", 1_000) | ("subsec_nanos", 1_000_000) => "subsec_millis",
5050
("subsec_nanos", 1_000) => "subsec_micros",
51-
("subsec_nanos", 1_000_000) => "subsec_millis",
5251
_ => return,
5352
};
5453
span_lint_and_sugg(

clippy_lints/src/inherent_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub struct Pass {
4646

4747
impl Default for Pass {
4848
fn default() -> Self {
49-
Pass { impls: FxHashMap::default() }
49+
Self { impls: FxHashMap::default() }
5050
}
5151
}
5252

clippy_lints/src/multiple_crate_versions.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,17 @@ impl LintPass for Pass {
4141

4242
impl EarlyLintPass for Pass {
4343
fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &Crate) {
44-
let metadata = match cargo_metadata::metadata_deps(None, true) {
45-
Ok(metadata) => metadata,
46-
Err(_) => {
47-
span_lint(
48-
cx,
49-
MULTIPLE_CRATE_VERSIONS,
50-
krate.span,
51-
"could not read cargo metadata"
52-
);
44+
let metadata = if let Ok(metadata) = cargo_metadata::metadata_deps(None, true) {
45+
metadata
46+
} else {
47+
span_lint(
48+
cx,
49+
MULTIPLE_CRATE_VERSIONS,
50+
krate.span,
51+
"could not read cargo metadata"
52+
);
5353

54-
return;
55-
}
54+
return;
5655
};
5756

5857
let mut packages = metadata.packages;

clippy_lints/src/utils/conf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ define_Conf! {
148148
}
149149

150150
impl Default for Conf {
151-
fn default() -> Conf {
151+
fn default() -> Self {
152152
toml::from_str("").expect("we never error on empty config files")
153153
}
154154
}

0 commit comments

Comments
 (0)