Skip to content

Commit c4e5670

Browse files
committed
Fix more clippy warnings;
clippy::comparison_to_empty clippy::needless_question_mark clippy::needless_borrow clippy::match_like_matches_macro clippy::vec_init_then_push clippy::redundant_clone clippy::nonminimal_bool clippy::ptr_arg
1 parent d12a8ba commit c4e5670

File tree

19 files changed

+41
-53
lines changed

19 files changed

+41
-53
lines changed

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,7 @@ impl TargetInfo {
408408

409409
let error = str::from_utf8(&output.stderr).unwrap();
410410
let output = str::from_utf8(&output.stdout).unwrap();
411-
Ok(parse_crate_type(
412-
crate_type,
413-
&process,
414-
output,
415-
error,
416-
&mut output.lines(),
417-
)?)
411+
parse_crate_type(crate_type, &process, output, error, &mut output.lines())
418412
}
419413

420414
/// Returns all the file types generated by rustc for the given mode/target_kind.

src/cargo/core/compiler/build_plan.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! dependencies on other Invocations.
88
99
use std::collections::BTreeMap;
10-
use std::path::PathBuf;
10+
use std::path::{Path, PathBuf};
1111

1212
use serde::Serialize;
1313

@@ -63,10 +63,10 @@ impl Invocation {
6363
}
6464
}
6565

66-
pub fn add_output(&mut self, path: &PathBuf, link: &Option<PathBuf>) {
67-
self.outputs.push(path.clone());
66+
pub fn add_output(&mut self, path: &Path, link: &Option<PathBuf>) {
67+
self.outputs.push(path.to_path_buf());
6868
if let Some(ref link) = *link {
69-
self.links.insert(link.clone(), path.clone());
69+
self.links.insert(link.clone(), path.to_path_buf());
7070
}
7171
}
7272

src/cargo/core/compiler/fingerprint.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,9 +1432,9 @@ fn build_script_local_fingerprints(
14321432
) -> (
14331433
Box<
14341434
dyn FnOnce(
1435-
&BuildDeps,
1436-
Option<&dyn Fn() -> CargoResult<String>>,
1437-
) -> CargoResult<Option<Vec<LocalFingerprint>>>
1435+
&BuildDeps,
1436+
Option<&dyn Fn() -> CargoResult<String>>,
1437+
) -> CargoResult<Option<Vec<LocalFingerprint>>>
14381438
+ Send,
14391439
>,
14401440
bool,

src/cargo/core/compiler/job_queue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ impl<'cfg> DrainState<'cfg> {
915915
// thread to run the job.
916916
doit(JobState {
917917
id,
918-
messages: messages.clone(),
918+
messages,
919919
output: Some(cx.bcx.config),
920920
rmeta_required: Cell::new(rmeta_required),
921921
_marker: marker::PhantomData,

src/cargo/core/compiler/mod.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -397,15 +397,11 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
397397
current_id: PackageId,
398398
metadata: Option<Metadata>,
399399
) {
400-
let metadata = match metadata {
401-
Some(metadata) => metadata,
402-
None => {
403-
return;
404-
}
405-
};
406-
if let Some(output) = build_script_outputs.get(current_id, metadata) {
407-
for &(ref name, ref value) in output.env.iter() {
408-
rustc.env(name, value);
400+
if let Some(metadata) = metadata {
401+
if let Some(output) = build_script_outputs.get(current_id, metadata) {
402+
for &(ref name, ref value) in output.env.iter() {
403+
rustc.env(name, value);
404+
}
409405
}
410406
}
411407
}
@@ -492,7 +488,7 @@ fn add_plugin_deps(
492488
rustc: &mut ProcessBuilder,
493489
build_script_outputs: &BuildScriptOutputs,
494490
build_scripts: &BuildScripts,
495-
root_output: &PathBuf,
491+
root_output: &Path,
496492
) -> CargoResult<()> {
497493
let var = util::dylib_path_envvar();
498494
let search_path = rustc.get_env(var).unwrap_or_default();
@@ -516,7 +512,7 @@ fn add_plugin_deps(
516512
// Strip off prefixes like "native=" or "framework=" and filter out directories
517513
// **not** inside our output directory since they are likely spurious and can cause
518514
// clashes with system shared libraries (issue #3366).
519-
fn filter_dynamic_search_path<'a, I>(paths: I, root_output: &PathBuf) -> Vec<PathBuf>
515+
fn filter_dynamic_search_path<'a, I>(paths: I, root_output: &Path) -> Vec<PathBuf>
520516
where
521517
I: Iterator<Item = &'a PathBuf>,
522518
{

src/cargo/core/package.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,8 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
607607
/// eventually be returned from `wait_for_download`. Returns `Some(pkg)` if
608608
/// the package is ready and doesn't need to be downloaded.
609609
pub fn start(&mut self, id: PackageId) -> CargoResult<Option<&'a Package>> {
610-
Ok(self
611-
.start_inner(id)
612-
.chain_err(|| format!("failed to download `{}`", id))?)
610+
self.start_inner(id)
611+
.chain_err(|| format!("failed to download `{}`", id))
613612
}
614613

615614
fn start_inner(&mut self, id: PackageId) -> CargoResult<Option<&'a Package>> {

src/cargo/core/profiles.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl Profiles {
143143
fn add_root_profiles(
144144
profile_makers: &mut Profiles,
145145
profiles: &BTreeMap<InternedString, TomlProfile>,
146-
) {
146+
) {
147147
profile_makers.by_name.insert(
148148
InternedString::new("dev"),
149149
ProfileMaker::new(Profile::default_dev(), profiles.get("dev").cloned()),

src/cargo/ops/cargo_compile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ pub fn compile_ws<'a>(
282282
let bcx = create_bcx(ws, options, &interner)?;
283283
if options.build_config.unit_graph {
284284
unit_graph::emit_serialized_unit_graph(&bcx.roots, &bcx.unit_graph)?;
285-
return Ok(Compilation::new(&bcx)?);
285+
return Compilation::new(&bcx);
286286
}
287287

288288
let _p = profile::start("compiling");

src/cargo/ops/cargo_output_metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn build_resolve_graph(
120120
metadata_opts.all_features,
121121
!metadata_opts.no_default_features,
122122
);
123-
let resolve_opts = ResolveOpts::new(/*dev_deps*/ true, requested_features.clone());
123+
let resolve_opts = ResolveOpts::new(/*dev_deps*/ true, requested_features);
124124
let force_all = if metadata_opts.filter_platforms.is_empty() {
125125
crate::core::resolver::features::ForceAllTargets::Yes
126126
} else {

src/cargo/ops/registry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ pub fn registry_configuration(
366366
// `registry.default` is handled in command-line parsing.
367367
let (index, token, process) = match registry {
368368
Some(registry) => {
369-
validate_package_name(&registry, "registry name", "")?;
370-
let index = Some(config.get_registry_index(&registry)?.to_string());
369+
validate_package_name(registry, "registry name", "")?;
370+
let index = Some(config.get_registry_index(registry)?.to_string());
371371
let token_key = format!("registries.{}.token", registry);
372372
let token = config.get_string(&token_key)?.map(|p| p.val);
373373
let process = if config.cli_unstable().credential_process {
@@ -471,7 +471,7 @@ fn registry(
471471
};
472472
let token = if validate_token {
473473
if index.is_some() {
474-
if !token.is_some() {
474+
if token.is_none() {
475475
bail!("command-line argument --index requires --token to be specified");
476476
}
477477
token

0 commit comments

Comments
 (0)