From 2a31937cc997df21498e7649c1f170b5a145ae83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Wed, 26 Sep 2018 11:32:05 +0200 Subject: [PATCH 1/2] fix all clippy::use_self pedantic warnings found in the codebase. cc #3172 --- clippy_dev/src/lib.rs | 8 ++++---- clippy_lints/src/consts.rs | 4 ++-- clippy_lints/src/inherent_impl.rs | 2 +- clippy_lints/src/utils/conf.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs index e5ce8580fa170..2f91c987cb169 100644 --- a/clippy_dev/src/lib.rs +++ b/clippy_dev/src/lib.rs @@ -35,8 +35,8 @@ pub struct Lint { } impl Lint { - pub fn new(name: &str, group: &str, desc: &str, deprecation: Option<&str>, module: &str) -> Lint { - Lint { + pub fn new(name: &str, group: &str, desc: &str, deprecation: Option<&str>, module: &str) -> Self { + Self { name: name.to_lowercase(), group: group.to_string(), desc: NL_ESCAPE_RE.replace(&desc.replace("\\\"", "\""), "").to_string(), @@ -46,12 +46,12 @@ impl Lint { } /// Returns all non-deprecated lints - pub fn active_lints(lints: &[Lint]) -> impl Iterator { + pub fn active_lints(lints: &[Self]) -> impl Iterator { lints.iter().filter(|l| l.deprecation.is_none()) } /// Returns the lints in a HashMap, grouped by the different lint groups - pub fn by_lint_group(lints: &[Lint]) -> HashMap> { + pub fn by_lint_group(lints: &[Self]) -> HashMap> { lints.iter().map(|lint| (lint.group.to_string(), lint.clone())).into_group_map() } } diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 43796004d0e7f..0690d6934e51c 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -123,11 +123,11 @@ impl Constant { (&Constant::Tuple(ref l), &Constant::Tuple(ref r)) | (&Constant::Vec(ref l), &Constant::Vec(ref r)) => l .iter() .zip(r.iter()) - .map(|(li, ri)| Constant::partial_cmp(tcx, cmp_type, li, ri)) + .map(|(li, ri)| Self::partial_cmp(tcx, cmp_type, li, ri)) .find(|r| r.map_or(true, |o| o != Ordering::Equal)) .unwrap_or_else(|| Some(l.len().cmp(&r.len()))), (&Constant::Repeat(ref lv, ref ls), &Constant::Repeat(ref rv, ref rs)) => { - match Constant::partial_cmp(tcx, cmp_type, lv, rv) { + match Self::partial_cmp(tcx, cmp_type, lv, rv) { Some(Equal) => Some(ls.cmp(rs)), x => x, } diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index 36336b863988f..167259b73538d 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -46,7 +46,7 @@ pub struct Pass { impl Default for Pass { fn default() -> Self { - Pass { impls: FxHashMap::default() } + Self { impls: FxHashMap::default() } } } diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index 4a58ac2f760ce..d79a7743e0f82 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -148,7 +148,7 @@ define_Conf! { } impl Default for Conf { - fn default() -> Conf { + fn default() -> Self { toml::from_str("").expect("we never error on empty config files") } } From 9fae4693f9d3a7f4e5784b81f726d22c7cd5cb2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Wed, 26 Sep 2018 11:44:50 +0200 Subject: [PATCH 2/2] fix clippy::single-match-else and clippy::match_same_arms warnings in clippys codebase --- clippy_lints/src/duration_subsec.rs | 3 +-- clippy_lints/src/multiple_crate_versions.rs | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/duration_subsec.rs b/clippy_lints/src/duration_subsec.rs index 8ac34d9daa30f..709cbd277549a 100644 --- a/clippy_lints/src/duration_subsec.rs +++ b/clippy_lints/src/duration_subsec.rs @@ -46,9 +46,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DurationSubsec { if let Some((Constant::Int(divisor), _)) = constant(cx, cx.tables, right); then { let suggested_fn = match (method_path.ident.as_str().as_ref(), divisor) { - ("subsec_micros", 1_000) => "subsec_millis", + ("subsec_micros", 1_000) | ("subsec_nanos", 1_000_000) => "subsec_millis", ("subsec_nanos", 1_000) => "subsec_micros", - ("subsec_nanos", 1_000_000) => "subsec_millis", _ => return, }; span_lint_and_sugg( diff --git a/clippy_lints/src/multiple_crate_versions.rs b/clippy_lints/src/multiple_crate_versions.rs index 2f6b08c5151af..9c10a929d6f1d 100644 --- a/clippy_lints/src/multiple_crate_versions.rs +++ b/clippy_lints/src/multiple_crate_versions.rs @@ -41,18 +41,17 @@ impl LintPass for Pass { impl EarlyLintPass for Pass { fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &Crate) { - let metadata = match cargo_metadata::metadata_deps(None, true) { - Ok(metadata) => metadata, - Err(_) => { - span_lint( - cx, - MULTIPLE_CRATE_VERSIONS, - krate.span, - "could not read cargo metadata" - ); + let metadata = if let Ok(metadata) = cargo_metadata::metadata_deps(None, true) { + metadata + } else { + span_lint( + cx, + MULTIPLE_CRATE_VERSIONS, + krate.span, + "could not read cargo metadata" + ); - return; - } + return; }; let mut packages = metadata.packages;