Skip to content

Commit 3738e1d

Browse files
committed
Auto merge of #7574 - igor-makarov:clippy-fixes, r=Eh2406
Fix all Clippy suggestions (but not add it to CI 🙃) This PR adds a `clippy` job to the Azure Pipelines CI. In addition to adding the job, I made sure to fix all the lints in all the packages. I'm new to Rust, so please check my code modifications extra carefully 😂
2 parents d0a41be + 1432651 commit 3738e1d

File tree

13 files changed

+34
-20
lines changed

13 files changed

+34
-20
lines changed

crates/cargo-test-macro/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn cargo_test(attr: TokenStream, item: TokenStream) -> TokenStream {
5252
))));
5353
}
5454

55-
return ret;
55+
ret
5656
}
5757

5858
fn contains_ident(t: &TokenStream, ident: &str) -> bool {

crates/cargo-test-support/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ dependency.
105105
106106
*/
107107

108+
#![allow(clippy::needless_doctest_main)] // according to @ehuss this lint is fussy
109+
#![allow(clippy::inefficient_to_string)] // this causes suggestions that result in `(*s).to_string()`
110+
108111
use std::env;
109112
use std::ffi::OsStr;
110113
use std::fmt;
@@ -1141,9 +1144,9 @@ impl Execs {
11411144

11421145
// Do the template replacements on the expected string.
11431146
let matcher = match &self.process_builder {
1144-
None => matcher.to_string(),
1147+
None => matcher,
11451148
Some(p) => match p.get_cwd() {
1146-
None => matcher.to_string(),
1149+
None => matcher,
11471150
Some(cwd) => replace_path(&matcher, cwd, "[CWD]"),
11481151
},
11491152
};

crates/resolver-tests/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#![allow(clippy::many_single_char_names)]
2+
#![allow(clippy::needless_range_loop)] // false positives
3+
14
use std::cell::RefCell;
25
use std::cmp::PartialEq;
36
use std::cmp::{max, min};

crates/resolver-tests/tests/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ fn pub_fail() {
234234
pkg!(("e", "0.0.6") => [dep_req_kind("a", "<= 0.0.4", Kind::Normal, true),]),
235235
pkg!(("kB", "0.0.3") => [dep_req("a", ">= 0.0.5"),dep("e"),]),
236236
];
237-
let reg = registry(input.clone());
237+
let reg = registry(input);
238238
assert!(resolve_and_validated(vec![dep("kB")], &reg, None).is_err());
239239
}
240240

src/bin/cargo/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![warn(rust_2018_idioms)] // while we're getting used to 2018
2-
#![allow(clippy::too_many_arguments)] // large project
32
#![allow(clippy::redundant_closure)] // there's a false positive
43
#![warn(clippy::needless_borrow)]
54
#![warn(clippy::redundant_clone)]

src/cargo/core/profiles.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ impl ProfileMaker {
515515
Some(ref toml) => toml,
516516
None => return Ok(()),
517517
};
518-
let overrides = match toml.package.as_ref().or(toml.overrides.as_ref()) {
518+
let overrides = match toml.package.as_ref().or_else(|| toml.overrides.as_ref()) {
519519
Some(overrides) => overrides,
520520
None => return Ok(()),
521521
};
@@ -612,7 +612,7 @@ fn merge_toml_overrides(
612612
merge_profile(profile, build_override);
613613
}
614614
}
615-
if let Some(overrides) = toml.package.as_ref().or(toml.overrides.as_ref()) {
615+
if let Some(overrides) = toml.package.as_ref().or_else(|| toml.overrides.as_ref()) {
616616
if !is_member {
617617
if let Some(all) = overrides.get(&ProfilePackageSpec::All) {
618618
merge_profile(profile, all);

src/cargo/core/resolver/encode.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -564,19 +564,20 @@ pub struct EncodeState<'a> {
564564

565565
impl<'a> EncodeState<'a> {
566566
pub fn new(resolve: &'a Resolve) -> EncodeState<'a> {
567-
let mut counts = None;
568-
if *resolve.version() == ResolveVersion::V2 {
567+
let counts = if *resolve.version() == ResolveVersion::V2 {
569568
let mut map = HashMap::new();
570569
for id in resolve.iter() {
571570
let slot = map
572571
.entry(id.name())
573-
.or_insert(HashMap::new())
572+
.or_insert_with(HashMap::new)
574573
.entry(id.version())
575574
.or_insert(0);
576575
*slot += 1;
577576
}
578-
counts = Some(map);
579-
}
577+
Some(map)
578+
} else {
579+
None
580+
};
580581
EncodeState { counts }
581582
}
582583
}

src/cargo/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#![allow(clippy::type_complexity)] // there's an exceptionally complex type
1818
#![allow(clippy::wrong_self_convention)] // perhaps `Rc` should be special-cased in Clippy?
1919
#![allow(clippy::write_with_newline)] // too pedantic
20+
#![allow(clippy::inefficient_to_string)] // this causes suggestions that result in `(*s).to_string()`
2021
#![warn(clippy::needless_borrow)]
2122
#![warn(clippy::redundant_clone)]
2223
// Unit is now interned, and would probably be better as pass-by-copy, but

src/cargo/ops/registry.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,18 @@ fn registry(
371371
let mut src = RegistrySource::remote(sid, &HashSet::new(), config);
372372
// Only update the index if the config is not available or `force` is set.
373373
let cfg = src.config();
374-
let cfg = if force_update || cfg.is_err() {
374+
let mut updated_cfg = || {
375375
src.update()
376376
.chain_err(|| format!("failed to update {}", sid))?;
377-
cfg.or_else(|_| src.config())?
377+
src.config()
378+
};
379+
380+
let cfg = if force_update {
381+
updated_cfg()?
378382
} else {
379-
cfg.unwrap()
383+
cfg.or_else(|_| updated_cfg())?
380384
};
385+
381386
cfg.and_then(|cfg| cfg.api)
382387
.ok_or_else(|| format_err!("{} does not support API commands", sid))?
383388
};

src/cargo/util/config/de.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl<'de, 'config> de::MapAccess<'de> for ConfigMapAccess<'config> {
254254
};
255255
let result = seed.deserialize(name.into_deserializer()).map(Some);
256256
self.next = Some(key);
257-
return result;
257+
result
258258
}
259259
None => Ok(None),
260260
}
@@ -273,7 +273,7 @@ impl<'de, 'config> de::MapAccess<'de> for ConfigMapAccess<'config> {
273273
key: self.de.key.clone(),
274274
});
275275
self.de.key.pop();
276-
return result;
276+
result
277277
}
278278
}
279279

0 commit comments

Comments
 (0)