Skip to content

Commit 94e21ad

Browse files
committed
Auto merge of #9051 - matthiaskrgr:clippy_v18, r=ehuss
another round of clippy lint fixes
2 parents 6bdf178 + c4e5670 commit 94e21ad

25 files changed

+109
-140
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,8 @@ impl CargoPathExt for Path {
127127
if let Err(e) = remove_dir_all::remove_dir_all(self) {
128128
panic!("failed to remove {:?}: {:?}", self, e)
129129
}
130-
} else {
131-
if let Err(e) = fs::remove_file(self) {
132-
panic!("failed to remove {:?}: {:?}", self, e)
133-
}
130+
} else if let Err(e) = fs::remove_file(self) {
131+
panic!("failed to remove {:?}: {:?}", self, e)
134132
}
135133
}
136134

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/custom_build.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ pub fn build_map(cx: &mut Context<'_, '_>) -> CargoResult<()> {
750750

751751
// Load any dependency declarations from a previous run.
752752
if unit.mode.is_run_custom_build() {
753-
parse_previous_explicit_deps(cx, unit)?;
753+
parse_previous_explicit_deps(cx, unit);
754754
}
755755

756756
// We want to invoke the compiler deterministically to be cache-friendly
@@ -787,13 +787,12 @@ pub fn build_map(cx: &mut Context<'_, '_>) -> CargoResult<()> {
787787
}
788788
}
789789

790-
fn parse_previous_explicit_deps(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<()> {
790+
fn parse_previous_explicit_deps(cx: &mut Context<'_, '_>, unit: &Unit) {
791791
let script_run_dir = cx.files().build_script_run_dir(unit);
792792
let output_file = script_run_dir.join("output");
793793
let (prev_output, _) = prev_build_output(cx, unit);
794794
let deps = BuildDeps::new(&output_file, prev_output.as_ref());
795795
cx.build_explicit_deps.insert(unit.clone(), deps);
796-
Ok(())
797796
}
798797
}
799798

src/cargo/core/compiler/job_queue.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -780,14 +780,12 @@ impl<'cfg> DrainState<'cfg> {
780780
if err_state.is_some() {
781781
// Already encountered one error.
782782
log::warn!("{:?}", new_err);
783+
} else if !self.active.is_empty() {
784+
crate::display_error(&new_err, shell);
785+
drop(shell.warn("build failed, waiting for other jobs to finish..."));
786+
*err_state = Some(anyhow::format_err!("build failed"));
783787
} else {
784-
if !self.active.is_empty() {
785-
crate::display_error(&new_err, shell);
786-
drop(shell.warn("build failed, waiting for other jobs to finish..."));
787-
*err_state = Some(anyhow::format_err!("build failed"));
788-
} else {
789-
*err_state = Some(new_err);
790-
}
788+
*err_state = Some(new_err);
791789
}
792790
}
793791

@@ -917,7 +915,7 @@ impl<'cfg> DrainState<'cfg> {
917915
// thread to run the job.
918916
doit(JobState {
919917
id,
920-
messages: messages.clone(),
918+
messages,
921919
output: Some(cx.bcx.config),
922920
rmeta_required: Cell::new(rmeta_required),
923921
_marker: marker::PhantomData,

src/cargo/core/compiler/mod.rs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::env;
2424
use std::ffi::{OsStr, OsString};
2525
use std::fs::{self, File};
2626
use std::io::{BufRead, Write};
27-
use std::path::PathBuf;
27+
use std::path::{Path, PathBuf};
2828
use std::sync::Arc;
2929

3030
use anyhow::Error;
@@ -276,7 +276,7 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
276276
)?;
277277
add_plugin_deps(&mut rustc, &script_outputs, &build_scripts, &root_output)?;
278278
}
279-
add_custom_env(&mut rustc, &script_outputs, current_id, script_metadata)?;
279+
add_custom_env(&mut rustc, &script_outputs, current_id, script_metadata);
280280
}
281281

282282
for output in outputs.iter() {
@@ -396,17 +396,14 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
396396
build_script_outputs: &BuildScriptOutputs,
397397
current_id: PackageId,
398398
metadata: Option<Metadata>,
399-
) -> CargoResult<()> {
400-
let metadata = match metadata {
401-
Some(metadata) => metadata,
402-
None => return Ok(()),
403-
};
404-
if let Some(output) = build_script_outputs.get(current_id, metadata) {
405-
for &(ref name, ref value) in output.env.iter() {
406-
rustc.env(name, value);
399+
) {
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+
}
407405
}
408406
}
409-
Ok(())
410407
}
411408
}
412409

@@ -491,7 +488,7 @@ fn add_plugin_deps(
491488
rustc: &mut ProcessBuilder,
492489
build_script_outputs: &BuildScriptOutputs,
493490
build_scripts: &BuildScripts,
494-
root_output: &PathBuf,
491+
root_output: &Path,
495492
) -> CargoResult<()> {
496493
let var = util::dylib_path_envvar();
497494
let search_path = rustc.get_env(var).unwrap_or_default();
@@ -515,7 +512,7 @@ fn add_plugin_deps(
515512
// Strip off prefixes like "native=" or "framework=" and filter out directories
516513
// **not** inside our output directory since they are likely spurious and can cause
517514
// clashes with system shared libraries (issue #3366).
518-
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>
519516
where
520517
I: Iterator<Item = &'a PathBuf>,
521518
{
@@ -603,7 +600,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
603600
rustdoc.arg("--cfg").arg(&format!("feature=\"{}\"", feat));
604601
}
605602

606-
add_error_format_and_color(cx, &mut rustdoc, false)?;
603+
add_error_format_and_color(cx, &mut rustdoc, false);
607604

608605
if let Some(args) = cx.bcx.extra_args_for(unit) {
609606
rustdoc.args(args);
@@ -725,11 +722,7 @@ fn add_cap_lints(bcx: &BuildContext<'_, '_>, unit: &Unit, cmd: &mut ProcessBuild
725722
/// intercepting messages like rmeta artifacts, etc. rustc includes a
726723
/// "rendered" field in the JSON message with the message properly formatted,
727724
/// which Cargo will extract and display to the user.
728-
fn add_error_format_and_color(
729-
cx: &Context<'_, '_>,
730-
cmd: &mut ProcessBuilder,
731-
pipelined: bool,
732-
) -> CargoResult<()> {
725+
fn add_error_format_and_color(cx: &Context<'_, '_>, cmd: &mut ProcessBuilder, pipelined: bool) {
733726
cmd.arg("--error-format=json");
734727
let mut json = String::from("--json=diagnostic-rendered-ansi");
735728
if pipelined {
@@ -764,8 +757,6 @@ fn add_error_format_and_color(
764757
_ => (),
765758
}
766759
}
767-
768-
Ok(())
769760
}
770761

771762
fn build_base_args(
@@ -799,7 +790,7 @@ fn build_base_args(
799790
}
800791

801792
add_path_args(bcx, unit, cmd);
802-
add_error_format_and_color(cx, cmd, cx.rmeta_required(unit))?;
793+
add_error_format_and_color(cx, cmd, cx.rmeta_required(unit));
803794

804795
if !test {
805796
for crate_type in crate_types.iter() {

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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl Profiles {
100100
requested_profile,
101101
};
102102

103-
Self::add_root_profiles(&mut profile_makers, &profiles)?;
103+
Self::add_root_profiles(&mut profile_makers, &profiles);
104104

105105
// Merge with predefined profiles.
106106
use std::collections::btree_map::Entry;
@@ -143,7 +143,7 @@ impl Profiles {
143143
fn add_root_profiles(
144144
profile_makers: &mut Profiles,
145145
profiles: &BTreeMap<InternedString, TomlProfile>,
146-
) -> CargoResult<()> {
146+
) {
147147
profile_makers.by_name.insert(
148148
InternedString::new("dev"),
149149
ProfileMaker::new(Profile::default_dev(), profiles.get("dev").cloned()),
@@ -153,7 +153,6 @@ impl Profiles {
153153
InternedString::new("release"),
154154
ProfileMaker::new(Profile::default_release(), profiles.get("release").cloned()),
155155
);
156-
Ok(())
157156
}
158157

159158
/// Returns the built-in profiles (not including dev/release, which are

src/cargo/core/summary.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl Summary {
108108
if !weak_dep_features {
109109
for (feat_name, features) in self.features() {
110110
for fv in features {
111-
if matches!(fv, FeatureValue::DepFeature{weak: true, ..}) {
111+
if matches!(fv, FeatureValue::DepFeature { weak: true, .. }) {
112112
bail!(
113113
"optional dependency features with `?` syntax are only \
114114
allowed on the nightly channel and requires the \
@@ -416,7 +416,14 @@ impl FeatureValue {
416416

417417
/// Returns `true` if this feature explicitly used `dep:` syntax.
418418
pub fn has_dep_prefix(&self) -> bool {
419-
matches!(self, FeatureValue::Dep{..} | FeatureValue::DepFeature{dep_prefix:true, ..})
419+
matches!(
420+
self,
421+
FeatureValue::Dep { .. }
422+
| FeatureValue::DepFeature {
423+
dep_prefix: true,
424+
..
425+
}
426+
)
420427
}
421428
}
422429

src/cargo/core/workspace.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -437,14 +437,14 @@ impl<'cfg> Workspace<'cfg> {
437437
/// Returns an error if `manifest_path` isn't actually a valid manifest or
438438
/// if some other transient error happens.
439439
fn find_root(&mut self, manifest_path: &Path) -> CargoResult<Option<PathBuf>> {
440-
fn read_root_pointer(member_manifest: &Path, root_link: &str) -> CargoResult<PathBuf> {
440+
fn read_root_pointer(member_manifest: &Path, root_link: &str) -> PathBuf {
441441
let path = member_manifest
442442
.parent()
443443
.unwrap()
444444
.join(root_link)
445445
.join("Cargo.toml");
446446
debug!("find_root - pointer {}", path.display());
447-
Ok(paths::normalize_path(&path))
447+
paths::normalize_path(&path)
448448
}
449449

450450
{
@@ -456,7 +456,7 @@ impl<'cfg> Workspace<'cfg> {
456456
}
457457
WorkspaceConfig::Member {
458458
root: Some(ref path_to_root),
459-
} => return Ok(Some(read_root_pointer(manifest_path, path_to_root)?)),
459+
} => return Ok(Some(read_root_pointer(manifest_path, path_to_root))),
460460
WorkspaceConfig::Member { root: None } => {}
461461
}
462462
}
@@ -481,7 +481,7 @@ impl<'cfg> Workspace<'cfg> {
481481
root: Some(ref path_to_root),
482482
} => {
483483
debug!("find_root - found pointer");
484-
return Ok(Some(read_root_pointer(&ances_manifest_path, path_to_root)?));
484+
return Ok(Some(read_root_pointer(&ances_manifest_path, path_to_root)));
485485
}
486486
WorkspaceConfig::Member { .. } => {}
487487
}
@@ -957,7 +957,7 @@ impl<'cfg> Workspace<'cfg> {
957957
if self.allows_new_cli_feature_behavior() {
958958
self.members_with_features_new(specs, requested_features)
959959
} else {
960-
self.members_with_features_old(specs, requested_features)
960+
Ok(self.members_with_features_old(specs, requested_features))
961961
}
962962
}
963963

@@ -1067,7 +1067,7 @@ impl<'cfg> Workspace<'cfg> {
10671067
&self,
10681068
specs: &[PackageIdSpec],
10691069
requested_features: &RequestedFeatures,
1070-
) -> CargoResult<Vec<(&Package, RequestedFeatures)>> {
1070+
) -> Vec<(&Package, RequestedFeatures)> {
10711071
// Split off any features with the syntax `member-name/feature-name` into a map
10721072
// so that those features can be applied directly to those workspace-members.
10731073
let mut member_specific_features: HashMap<&str, BTreeSet<InternedString>> = HashMap::new();
@@ -1131,7 +1131,7 @@ impl<'cfg> Workspace<'cfg> {
11311131
}
11321132
}
11331133
});
1134-
Ok(ms.collect())
1134+
ms.collect()
11351135
}
11361136
}
11371137

0 commit comments

Comments
 (0)