Skip to content

Commit 370c4d0

Browse files
authored
make clippy a bit happier (#530)
Mostly consists of removing redundant clones, and one splitn that was rewritten to split_once. Also fixed two compiler erorrs in cargo-add tests by adding a `.assert()` call.
1 parent f6706af commit 370c4d0

File tree

6 files changed

+14
-20
lines changed

6 files changed

+14
-20
lines changed

src/bin/add/args.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,8 @@ impl Args {
156156
} else if self.build {
157157
vec!["build-dependencies".to_owned()]
158158
} else if let Some(ref target) = self.target {
159-
if target.is_empty() {
160-
panic!("Target specification may not be empty");
161-
}
159+
assert!(!target.is_empty(), "Target specification may not be empty");
160+
162161
vec![
163162
"target".to_owned(),
164163
target.clone(),

src/bin/upgrade/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ fn is_version_dep(dependency: &cargo_metadata::Dependency) -> bool {
130130
match dependency.source {
131131
// This is the criterion cargo uses (in `SourceId::from_url`) to decide whether a
132132
// dependency has the 'registry' kind.
133-
Some(ref s) => s.splitn(2, '+').next() == Some("registry"),
133+
Some(ref s) => s.split_once('+').map(|(x, _)| x) == Some("registry"),
134134
_ => false,
135135
}
136136
}

src/manifest.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn search(dir: &Path) -> Result<PathBuf> {
4848
} else {
4949
dir.parent()
5050
.ok_or_else(|| ErrorKind::MissingManifest.into())
51-
.and_then(|dir| search(dir))
51+
.and_then(search)
5252
}
5353
}
5454

@@ -537,7 +537,6 @@ impl LocalManifest {
537537
mod tests {
538538
use super::*;
539539
use crate::dependency::Dependency;
540-
use toml_edit;
541540

542541
#[test]
543542
fn add_remove_dependency() {

src/version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ mod test {
298298
#[track_caller]
299299
fn assert_req_bump<'a, O: Into<Option<&'a str>>>(version: &str, req: &str, expected: O) {
300300
let version = semver::Version::parse(version).unwrap();
301-
let actual = upgrade_requirement(&req, &version).unwrap();
301+
let actual = upgrade_requirement(req, &version).unwrap();
302302
let expected = expected.into();
303303
assert_eq!(actual.as_deref(), expected);
304304
}

tests/cargo-add.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ fn adds_dependency_with_upgrade_bad() {
9999
let toml = get_toml(&manifest);
100100
assert!(toml["dependencies"].is_none());
101101

102-
let upgrade_arg = format!("--upgrade=an_invalid_string",);
102+
let upgrade_arg = "--upgrade=an_invalid_string".to_string();
103103
execute_bad_command(&["add", "my-package", upgrade_arg.as_str()], &manifest);
104104
}
105105

@@ -1129,7 +1129,7 @@ fn adds_optional_dependency() {
11291129
// dependency present afterwards
11301130
let toml = get_toml(&manifest);
11311131
let val = &toml["dependencies"]["versioned-package"]["optional"];
1132-
assert_eq!(val.as_bool().expect("optional not a bool"), true);
1132+
assert!(val.as_bool().expect("optional not a bool"));
11331133
}
11341134

11351135
#[test]
@@ -1177,7 +1177,7 @@ fn adds_no_default_features_dependency() {
11771177
// dependency present afterwards
11781178
let toml = get_toml(&manifest);
11791179
let val = &toml["dependencies"]["versioned-package"]["default-features"];
1180-
assert_eq!(val.as_bool().expect("default-features not a bool"), false);
1180+
assert!(!val.as_bool().expect("default-features not a bool"));
11811181
}
11821182

11831183
#[test]
@@ -1440,6 +1440,7 @@ fn adds_dependency_normalized_name() {
14401440
"Inflector",
14411441
&format!("--manifest-path={}", manifest),
14421442
])
1443+
.assert()
14431444
.success()
14441445
.stderr(predicates::str::contains(
14451446
"WARN: Added `linked-hash-map` instead of `linked_hash_map`",
@@ -1844,11 +1845,10 @@ fn add_typo() {
18441845
.env("CARGO_IS_TEST", "1")
18451846
.assert()
18461847
.code(1)
1847-
.stderr()
1848-
.contains(
1848+
.stderr(predicates::str::contains(
18491849
"The crate `lets_hope_nobody_ever_publishes_this_crate` could not be found in registry index.",
1850-
)
1851-
.unwrap();
1850+
))
1851+
;
18521852
}
18531853

18541854
#[test]

tests/utils.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ pub fn copy_workspace_test() -> (assert_fs::TempDir, String, Vec<String>) {
4646
(root_manifest_path, workspace_manifest_paths)
4747
};
4848

49-
(
50-
tmpdir,
51-
root_manifest_path,
52-
workspace_manifest_paths.to_owned(),
53-
)
49+
(tmpdir, root_manifest_path, workspace_manifest_paths)
5450
}
5551

5652
/// Create temporary working directory with Cargo.toml manifest
@@ -59,7 +55,7 @@ pub fn clone_out_test(source: &str) -> (assert_fs::TempDir, String) {
5955
let manifest_path = tmpdir.child("Cargo.toml");
6056
manifest_path.write_file(Path::new(source)).unwrap();
6157
tmpdir.child("src/lib.rs").touch().unwrap();
62-
let path = manifest_path.to_str().unwrap().to_string().clone();
58+
let path = manifest_path.to_str().unwrap().to_string();
6359

6460
(tmpdir, path)
6561
}

0 commit comments

Comments
 (0)