Skip to content

Commit 75ec2d3

Browse files
committed
Auto merge of #5280 - klausi:clippy-191-trvials, r=matklad
chore(clippy): Simplify minor stuff found by clippy Executed clippy 0.0.191, fixed the trivial stuff. Filed rust-lang/rust-clippy#2615 for all the format_err!() false positives.
2 parents fe53c11 + 51d19d0 commit 75ec2d3

File tree

15 files changed

+58
-64
lines changed

15 files changed

+58
-64
lines changed

src/cargo/core/dependency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl Dependency {
186186
}
187187

188188
pub fn new_override(name: &str, source_id: &SourceId) -> Dependency {
189-
assert!(name.len() > 0);
189+
assert!(!name.is_empty());
190190
Dependency {
191191
inner: Rc::new(Inner {
192192
name: InternedString::new(name),

src/cargo/core/resolver/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ struct Requirements<'a> {
340340
}
341341

342342
impl<'r> Requirements<'r> {
343-
fn new<'a>(summary: &'a Summary) -> Requirements<'a> {
343+
fn new(summary: &Summary) -> Requirements {
344344
Requirements {
345345
summary,
346346
deps: HashMap::new(),
@@ -390,7 +390,7 @@ impl<'r> Requirements<'r> {
390390
),
391391
_ => {}
392392
}
393-
self.require_value(&fv)?;
393+
self.require_value(fv)?;
394394
}
395395
Ok(())
396396
}

src/cargo/core/resolver/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ fn activate_deps_loop(
432432
.remaining_siblings
433433
.clone()
434434
.filter_map(|(_, (ref new_dep, _, _))| {
435-
past_conflicting_activations.conflicting(&cx, &new_dep)
435+
past_conflicting_activations.conflicting(&cx, new_dep)
436436
})
437437
.next()
438438
{
@@ -818,7 +818,7 @@ fn compatible(a: &semver::Version, b: &semver::Version) -> bool {
818818
///
819819
/// Read <https://github.com/rust-lang/cargo/pull/4834>
820820
/// For several more detailed explanations of the logic here.
821-
fn find_candidate<'a>(
821+
fn find_candidate(
822822
backtrack_stack: &mut Vec<BacktrackFrame>,
823823
parent: &Summary,
824824
conflicting_activations: &HashMap<PackageId, ConflictReason>,

src/cargo/core/resolver/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ impl<'a> RegistryQueryer<'a> {
134134
let previous_cmp = a_in_previous.cmp(&b_in_previous).reverse();
135135
match previous_cmp {
136136
Ordering::Equal => {
137-
let cmp = a.summary.version().cmp(&b.summary.version());
138-
if self.minimal_versions == true {
137+
let cmp = a.summary.version().cmp(b.summary.version());
138+
if self.minimal_versions {
139139
// Lower version ordered first.
140140
cmp
141141
} else {

src/cargo/core/summary.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl PartialEq for Summary {
130130
// and creates FeatureValues for each feature.
131131
fn build_feature_map(
132132
features: BTreeMap<String, Vec<String>>,
133-
dependencies: &Vec<Dependency>,
133+
dependencies: &[Dependency],
134134
) -> CargoResult<FeatureMap> {
135135
use self::FeatureValue::*;
136136
let mut map = BTreeMap::new();
@@ -145,9 +145,9 @@ fn build_feature_map(
145145

146146
// Find data for the referenced dependency...
147147
let dep_data = {
148-
let dep_name = match &val {
149-
&Feature(_) => "",
150-
&Crate(ref dep_name) | &CrateFeature(ref dep_name, _) => dep_name,
148+
let dep_name = match val {
149+
Feature(_) => "",
150+
Crate(ref dep_name) | CrateFeature(ref dep_name, _) => dep_name,
151151
};
152152
dependencies.iter().find(|d| *d.name() == *dep_name)
153153
};

src/cargo/ops/cargo_new.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ pub fn new(opts: &NewOptions, config: &Config) -> CargoResult<()> {
318318

319319
let mkopts = MkOptions {
320320
version_control: opts.version_control,
321-
path: &path,
321+
path,
322322
name,
323323
source_files: vec![plan_new_source_file(opts.kind.is_bin(), name.to_string())],
324324
bin: opts.kind.is_bin(),
@@ -341,12 +341,12 @@ pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<()> {
341341
bail!("`cargo init` cannot be run on existing Cargo projects")
342342
}
343343

344-
let name = get_name(&path, opts)?;
344+
let name = get_name(path, opts)?;
345345
check_name(name, opts)?;
346346

347347
let mut src_paths_types = vec![];
348348

349-
detect_source_paths_and_types(&path, name, &mut src_paths_types)?;
349+
detect_source_paths_and_types(path, name, &mut src_paths_types)?;
350350

351351
if src_paths_types.is_empty() {
352352
src_paths_types.push(plan_new_source_file(opts.kind.is_bin(), name.to_string()));
@@ -444,37 +444,40 @@ fn mk(config: &Config, opts: &MkOptions) -> CargoResult<()> {
444444

445445
match vcs {
446446
VersionControl::Git => {
447-
if !fs::metadata(&path.join(".git")).is_ok() {
447+
if !path.join(".git").exists() {
448448
GitRepo::init(path, config.cwd())?;
449449
}
450-
let ignore = match fs::metadata(&path.join(".gitignore")) {
451-
Ok(_) => format!("\n{}", ignore),
452-
_ => ignore,
450+
let ignore = if path.join(".gitignore").exists() {
451+
format!("\n{}", ignore)
452+
} else {
453+
ignore
453454
};
454455
paths::append(&path.join(".gitignore"), ignore.as_bytes())?;
455456
}
456457
VersionControl::Hg => {
457-
if !fs::metadata(&path.join(".hg")).is_ok() {
458+
if !path.join(".hg").exists() {
458459
HgRepo::init(path, config.cwd())?;
459460
}
460-
let hgignore = match fs::metadata(&path.join(".hgignore")) {
461-
Ok(_) => format!("\n{}", hgignore),
462-
_ => hgignore,
461+
let hgignore = if path.join(".hgignore").exists() {
462+
format!("\n{}", hgignore)
463+
} else {
464+
hgignore
463465
};
464466
paths::append(&path.join(".hgignore"), hgignore.as_bytes())?;
465467
}
466468
VersionControl::Pijul => {
467-
if !fs::metadata(&path.join(".pijul")).is_ok() {
469+
if !path.join(".pijul").exists() {
468470
PijulRepo::init(path, config.cwd())?;
469471
}
470-
let ignore = match fs::metadata(&path.join(".ignore")) {
471-
Ok(_) => format!("\n{}", ignore),
472-
_ => ignore,
472+
let ignore = if path.join(".ignore").exists() {
473+
format!("\n{}", ignore)
474+
} else {
475+
ignore
473476
};
474477
paths::append(&path.join(".ignore"), ignore.as_bytes())?;
475478
}
476479
VersionControl::Fossil => {
477-
if !fs::metadata(&path.join(".fossil")).is_ok() {
480+
if path.join(".fossil").exists() {
478481
FossilRepo::init(path, config.cwd())?;
479482
}
480483
}

src/cargo/ops/cargo_package.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn package(ws: &Workspace, opts: &PackageOpts) -> CargoResult<Option<FileLoc
4747
.iter()
4848
.map(|file| util::without_prefix(file, root).unwrap().to_path_buf())
4949
.collect();
50-
if include_lockfile(&pkg) {
50+
if include_lockfile(pkg) {
5151
list.push("Cargo.lock".into());
5252
}
5353
list.sort();

src/cargo/ops/cargo_run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn run(
1818
Packages::Packages(ref xs) => match xs.len() {
1919
0 => ws.current()?,
2020
1 => ws.members()
21-
.find(|pkg| &*pkg.name() == xs[0])
21+
.find(|pkg| *pkg.name() == xs[0])
2222
.ok_or_else(|| {
2323
format_err!("package `{}` is not a member of the workspace", xs[0])
2424
})?,

src/cargo/ops/cargo_rustc/context/compilation_files.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ fn compute_metadata<'a, 'cfg>(
384384
&& (unit.target.is_dylib() || unit.target.is_cdylib()
385385
|| (unit.target.is_bin() && cx.target_triple().starts_with("wasm32-")))
386386
&& unit.pkg.package_id().source_id().is_path()
387-
&& !__cargo_default_lib_metadata.is_ok()
387+
&& __cargo_default_lib_metadata.is_err()
388388
{
389389
return None;
390390
}

src/cargo/ops/cargo_rustc/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,13 +603,13 @@ fn link_targets<'a, 'cfg>(
603603
}
604604
};
605605
destinations.push(dst.display().to_string());
606-
hardlink_or_copy(&src, &dst)?;
606+
hardlink_or_copy(src, dst)?;
607607
if let Some(ref path) = export_dir {
608608
if !path.exists() {
609609
fs::create_dir_all(path)?;
610610
}
611611

612-
hardlink_or_copy(&src, &path.join(dst.file_name().unwrap()))?;
612+
hardlink_or_copy(src, &path.join(dst.file_name().unwrap()))?;
613613
}
614614
}
615615

src/cargo/ops/registry.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -604,15 +604,15 @@ pub fn search(
604604
}
605605

606606
let search_max_limit = 100;
607-
if total_crates > u32::from(limit) && limit < search_max_limit {
607+
if total_crates > limit && limit < search_max_limit {
608608
println!(
609609
"... and {} crates more (use --limit N to see more)",
610-
total_crates - u32::from(limit)
610+
total_crates - limit
611611
);
612-
} else if total_crates > u32::from(limit) && limit >= search_max_limit {
612+
} else if total_crates > limit && limit >= search_max_limit {
613613
println!(
614614
"... and {} crates more (go to http://crates.io/search?q={} to see more)",
615-
total_crates - u32::from(limit),
615+
total_crates - limit,
616616
percent_encode(query.as_bytes(), QUERY_ENCODE_SET)
617617
);
618618
}

src/cargo/sources/git/utils.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,11 @@ impl GitReference {
212212
})()
213213
.chain_err(|| format!("failed to find tag `{}`", s))?,
214214
GitReference::Branch(ref s) => {
215-
(|| {
216-
let b = repo.find_branch(s, git2::BranchType::Local)?;
217-
b.get()
218-
.target()
219-
.ok_or_else(|| format_err!("branch `{}` did not have a target", s))
220-
})()
221-
.chain_err(|| format!("failed to find branch `{}`", s))?
215+
let b = repo.find_branch(s, git2::BranchType::Local)
216+
.chain_err(|| format!("failed to find branch `{}`", s))?;
217+
b.get()
218+
.target()
219+
.ok_or_else(|| format_err!("branch `{}` did not have a target", s))?
222220
}
223221
GitReference::Rev(ref s) => {
224222
let obj = repo.revparse_single(s)?;

src/cargo/util/paths.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,10 @@ fn _remove_file(p: &Path) -> CargoResult<()> {
237237
Err(e) => e,
238238
};
239239

240-
if err.kind() == io::ErrorKind::PermissionDenied {
241-
if set_not_readonly(p).unwrap_or(false) {
242-
match fs::remove_file(p) {
243-
Ok(()) => return Ok(()),
244-
Err(e) => err = e,
245-
}
240+
if err.kind() == io::ErrorKind::PermissionDenied && set_not_readonly(p).unwrap_or(false) {
241+
match fs::remove_file(p) {
242+
Ok(()) => return Ok(()),
243+
Err(e) => err = e,
246244
}
247245
}
248246

src/crates-io/lib.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,16 @@ impl Registry {
167167
(json.len() >> 8) as u8,
168168
(json.len() >> 16) as u8,
169169
(json.len() >> 24) as u8,
170-
].iter()
171-
.map(|x| *x),
170+
].iter().cloned(),
172171
);
173-
w.extend(json.as_bytes().iter().map(|x| *x));
172+
w.extend(json.as_bytes().iter().cloned());
174173
w.extend(
175174
[
176175
(stat.len() >> 0) as u8,
177176
(stat.len() >> 8) as u8,
178177
(stat.len() >> 16) as u8,
179178
(stat.len() >> 24) as u8,
180-
].iter()
181-
.map(|x| *x),
179+
].iter().cloned(),
182180
);
183181
w
184182
};
@@ -201,10 +199,10 @@ impl Registry {
201199

202200
let body = handle(&mut self.handle, &mut |buf| body.read(buf).unwrap_or(0))?;
203201

204-
let response = if body.len() > 0 {
205-
body.parse::<serde_json::Value>()?
206-
} else {
202+
let response = if body.is_empty() {
207203
"{}".parse()?
204+
} else {
205+
body.parse::<serde_json::Value>()?
208206
};
209207

210208
let invalid_categories: Vec<String> = response
@@ -329,12 +327,9 @@ fn handle(handle: &mut Easy, read: &mut FnMut(&mut [u8]) -> usize) -> Result<Str
329327
Ok(body) => body,
330328
Err(..) => bail!("response body was not valid utf-8"),
331329
};
332-
match serde_json::from_str::<ApiErrorList>(&body) {
333-
Ok(errors) => {
334-
let errors = errors.errors.into_iter().map(|s| s.detail);
335-
bail!("api errors: {}", errors.collect::<Vec<_>>().join(", "))
336-
}
337-
Err(..) => {}
330+
if let Ok(errors) = serde_json::from_str::<ApiErrorList>(&body) {
331+
let errors = errors.errors.into_iter().map(|s| s.detail);
332+
bail!("api errors: {}", errors.collect::<Vec<_>>().join(", "));
338333
}
339334
Ok(body)
340335
}

tests/testsuite/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ fn loc_names(names: &[(&'static str, &'static str)]) -> Vec<PackageId> {
186186
}
187187

188188
#[test]
189-
#[should_panic(expected = "assertion failed: name.len() > 0")]
189+
#[should_panic(expected = "assertion failed: !name.is_empty()")]
190190
fn test_dependency_with_empty_name() {
191191
// Bug 5229, dependency-names must not be empty
192192
"".to_dep();

0 commit comments

Comments
 (0)