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

+1-1
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

+5-2
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

+3
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

+1-1
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

-1
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

+2-2
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

+6-5
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

+1
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

+8-3
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

+2-2
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

β€Žsrc/cargo/util/config/key.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl ConfigKey {
4646
for part in key.split('.') {
4747
cfg.push(part);
4848
}
49-
return cfg;
49+
cfg
5050
}
5151

5252
/// Pushes a new sub-key on this `ConfigKey`. This sub-key should be

β€Žsrc/cargo/util/network.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn with_retry_repeats_the_call_then_works() {
112112
let config = Config::default().unwrap();
113113
*config.shell() = Shell::from_write(Box::new(Vec::new()));
114114
let result = with_retry(&config, || results.pop().unwrap());
115-
assert_eq!(result.unwrap(), ())
115+
assert!(result.is_ok())
116116
}
117117

118118
#[test]
@@ -135,7 +135,7 @@ fn with_retry_finds_nested_spurious_errors() {
135135
let config = Config::default().unwrap();
136136
*config.shell() = Shell::from_write(Box::new(Vec::new()));
137137
let result = with_retry(&config, || results.pop().unwrap());
138-
assert_eq!(result.unwrap(), ())
138+
assert!(result.is_ok())
139139
}
140140

141141
#[test]

β€Žtests/testsuite/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#![allow(clippy::blacklisted_name)]
44
#![allow(clippy::explicit_iter_loop)]
55
#![allow(clippy::redundant_closure)]
6+
#![allow(clippy::block_in_if_condition_stmt)] // clippy doesn't agree with rustfmt πŸ˜‚
7+
#![allow(clippy::inefficient_to_string)] // this causes suggestions that result in `(*s).to_string()`
68
#![warn(clippy::needless_borrow)]
79
#![warn(clippy::redundant_clone)]
810

0 commit comments

Comments
Β (0)