Skip to content

Commit d12a8ba

Browse files
committed
fix clippy::unnecessary_wraps.
Make functions that return Options but only ever return Ok() return the wrapped value directly and remove redundant matching
1 parent 8e3f97f commit d12a8ba

File tree

6 files changed

+26
-34
lines changed

6 files changed

+26
-34
lines changed

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

Lines changed: 9 additions & 14 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,18 @@ 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<()> {
399+
) {
400400
let metadata = match metadata {
401401
Some(metadata) => metadata,
402-
None => return Ok(()),
402+
None => {
403+
return;
404+
}
403405
};
404406
if let Some(output) = build_script_outputs.get(current_id, metadata) {
405407
for &(ref name, ref value) in output.env.iter() {
406408
rustc.env(name, value);
407409
}
408410
}
409-
Ok(())
410411
}
411412
}
412413

@@ -603,7 +604,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
603604
rustdoc.arg("--cfg").arg(&format!("feature=\"{}\"", feat));
604605
}
605606

606-
add_error_format_and_color(cx, &mut rustdoc, false)?;
607+
add_error_format_and_color(cx, &mut rustdoc, false);
607608

608609
if let Some(args) = cx.bcx.extra_args_for(unit) {
609610
rustdoc.args(args);
@@ -725,11 +726,7 @@ fn add_cap_lints(bcx: &BuildContext<'_, '_>, unit: &Unit, cmd: &mut ProcessBuild
725726
/// intercepting messages like rmeta artifacts, etc. rustc includes a
726727
/// "rendered" field in the JSON message with the message properly formatted,
727728
/// 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<()> {
729+
fn add_error_format_and_color(cx: &Context<'_, '_>, cmd: &mut ProcessBuilder, pipelined: bool) {
733730
cmd.arg("--error-format=json");
734731
let mut json = String::from("--json=diagnostic-rendered-ansi");
735732
if pipelined {
@@ -764,8 +761,6 @@ fn add_error_format_and_color(
764761
_ => (),
765762
}
766763
}
767-
768-
Ok(())
769764
}
770765

771766
fn build_base_args(
@@ -799,7 +794,7 @@ fn build_base_args(
799794
}
800795

801796
add_path_args(bcx, unit, cmd);
802-
add_error_format_and_color(cx, cmd, cx.rmeta_required(unit))?;
797+
add_error_format_and_color(cx, cmd, cx.rmeta_required(unit));
803798

804799
if !test {
805800
for crate_type in crate_types.iter() {

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

src/cargo/ops/common_for_install_and_uninstall.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl InstallTracker {
120120
serde_json::from_str(&contents)
121121
.chain_err(|| format_err!("invalid JSON found for metadata"))?
122122
};
123-
v2.sync_v1(&v1)?;
123+
v2.sync_v1(&v1);
124124
Ok(v2)
125125
})()
126126
.chain_err(|| {
@@ -367,7 +367,7 @@ impl CrateListingV2 {
367367
/// where v2 is in use, and a v1 update is made, then v2 is used again.
368368
/// i.e., `cargo +new install foo ; cargo +old install bar ; cargo +new install bar`
369369
/// For now, v1 is the source of truth, so its values are trusted over v2.
370-
fn sync_v1(&mut self, v1: &CrateListingV1) -> CargoResult<()> {
370+
fn sync_v1(&mut self, v1: &CrateListingV1) {
371371
// Make the `bins` entries the same.
372372
for (pkg_id, bins) in &v1.v1 {
373373
self.installs
@@ -385,7 +385,6 @@ impl CrateListingV2 {
385385
for pkg_id in to_remove {
386386
self.installs.remove(&pkg_id);
387387
}
388-
Ok(())
389388
}
390389

391390
fn package_for_bin(&self, bin_name: &str) -> Option<PackageId> {

src/cargo/ops/lockfile.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ pub fn load_pkg_lockfile(ws: &Workspace<'_>) -> CargoResult<Option<Resolve>> {
2828

2929
/// Generate a toml String of Cargo.lock from a Resolve.
3030
pub fn resolve_to_string(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoResult<String> {
31-
let (_orig, out, _ws_root) = resolve_to_string_orig(ws, resolve)?;
31+
let (_orig, out, _ws_root) = resolve_to_string_orig(ws, resolve);
3232
Ok(out)
3333
}
3434

3535
pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoResult<()> {
36-
let (orig, mut out, ws_root) = resolve_to_string_orig(ws, resolve)?;
36+
let (orig, mut out, ws_root) = resolve_to_string_orig(ws, resolve);
3737

3838
// If the lock file contents haven't changed so don't rewrite it. This is
3939
// helpful on read-only filesystems.
@@ -87,7 +87,7 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoRes
8787
fn resolve_to_string_orig(
8888
ws: &Workspace<'_>,
8989
resolve: &mut Resolve,
90-
) -> CargoResult<(Option<String>, String, Filesystem)> {
90+
) -> (Option<String>, String, Filesystem) {
9191
// Load the original lock file if it exists.
9292
let ws_root = Filesystem::new(ws.root().to_path_buf());
9393
let orig = ws_root.open_ro("Cargo.lock", ws.config(), "Cargo.lock file");
@@ -97,7 +97,7 @@ fn resolve_to_string_orig(
9797
Ok(s)
9898
});
9999
let out = serialize_resolve(resolve, orig.as_ref().ok().map(|s| &**s));
100-
Ok((orig.ok(), out, ws_root))
100+
(orig.ok(), out, ws_root)
101101
}
102102

103103
fn serialize_resolve(resolve: &Resolve, orig: Option<&str>) -> String {

0 commit comments

Comments
 (0)