Skip to content

fix some clippy::pedantic warnings found in the codebase. #3224

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

Merged
merged 2 commits into from
Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions clippy_dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -46,12 +46,12 @@ impl Lint {
}

/// Returns all non-deprecated lints
pub fn active_lints(lints: &[Lint]) -> impl Iterator<Item=&Lint> {
pub fn active_lints(lints: &[Self]) -> impl Iterator<Item=&Self> {
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<String, Vec<Lint>> {
pub fn by_lint_group(lints: &[Self]) -> HashMap<String, Vec<Self>> {
lints.iter().map(|lint| (lint.group.to_string(), lint.clone())).into_group_map()
}
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/duration_subsec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/inherent_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct Pass {

impl Default for Pass {
fn default() -> Self {
Pass { impls: FxHashMap::default() }
Self { impls: FxHashMap::default() }
}
}

Expand Down
21 changes: 10 additions & 11 deletions clippy_lints/src/multiple_crate_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/utils/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down