Skip to content

Commit 9099b49

Browse files
committed
refactor: remove unnecessary anyhow macro calls
1 parent ebca519 commit 9099b49

15 files changed

+31
-43
lines changed

src/cargo/core/compiler/compile_kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl CompileTarget {
143143
// with different paths always produce the same result.
144144
let path = Path::new(name)
145145
.canonicalize()
146-
.with_context(|| anyhow::format_err!("target path {:?} is not a valid file", name))?;
146+
.with_context(|| format!("target path {:?} is not a valid file", name))?;
147147

148148
let name = path
149149
.into_os_string()

src/cargo/core/manifest.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,8 @@ impl Manifest {
498498
self.unstable_features
499499
.require(Feature::test_dummy_unstable())
500500
.with_context(|| {
501-
anyhow::format_err!(
502-
"the `im-a-teapot` manifest key is unstable and may \
503-
not work properly in England"
504-
)
501+
"the `im-a-teapot` manifest key is unstable and may \
502+
not work properly in England"
505503
})?;
506504
}
507505

src/cargo/core/package.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
636636
.ok_or_else(|| internal(format!("couldn't find source for `{}`", id)))?;
637637
let pkg = source
638638
.download(id)
639-
.with_context(|| anyhow::format_err!("unable to get packages from source"))?;
639+
.with_context(|| "unable to get packages from source")?;
640640
let (url, descriptor) = match pkg {
641641
MaybePackage::Ready(pkg) => {
642642
debug!("{} doesn't need a download", id);

src/cargo/core/package_id_spec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl PackageIdSpec {
8787
let i: Vec<_> = i.into_iter().collect();
8888
let spec = PackageIdSpec::parse(spec).with_context(|| {
8989
let suggestion = lev_distance::closest_msg(spec, i.iter(), |id| id.name().as_str());
90-
anyhow::format_err!("invalid package ID specification: `{}`{}", spec, suggestion)
90+
format!("invalid package ID specification: `{}`{}", spec, suggestion)
9191
})?;
9292
spec.query(i)
9393
}

src/cargo/core/profiles.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,10 +1142,9 @@ fn get_config_profile(ws: &Workspace<'_>, name: &str) -> CargoResult<Option<Toml
11421142
.val
11431143
.validate(name, ws.unstable_features(), &mut warnings)
11441144
.with_context(|| {
1145-
anyhow::format_err!(
1145+
format!(
11461146
"config profile `{}` is not valid (defined in `{}`)",
1147-
name,
1148-
profile.definition
1147+
name, profile.definition
11491148
)
11501149
})?;
11511150
for warning in warnings {

src/cargo/core/registry.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl<'cfg> PackageRegistry<'cfg> {
282282
// corresponding to this `dep`.
283283
self.ensure_loaded(dep.source_id(), Kind::Normal)
284284
.with_context(|| {
285-
anyhow::format_err!(
285+
format!(
286286
"failed to load source for dependency `{}`",
287287
dep.package_name()
288288
)
@@ -322,7 +322,7 @@ impl<'cfg> PackageRegistry<'cfg> {
322322
Ok(summary)
323323
})
324324
.collect::<CargoResult<Vec<_>>>()
325-
.with_context(|| anyhow::format_err!("failed to resolve patches for `{}`", url))?;
325+
.with_context(|| format!("failed to resolve patches for `{}`", url))?;
326326

327327
let mut name_and_version = HashSet::new();
328328
for summary in unlocked_summaries.iter() {
@@ -390,7 +390,7 @@ impl<'cfg> PackageRegistry<'cfg> {
390390
let _p = profile::start(format!("updating: {}", source_id));
391391
self.sources.get_mut(source_id).unwrap().update()
392392
})()
393-
.with_context(|| anyhow::format_err!("Unable to update {}", source_id))?;
393+
.with_context(|| format!("Unable to update {}", source_id))?;
394394
Ok(())
395395
}
396396

@@ -542,7 +542,7 @@ impl<'cfg> Registry for PackageRegistry<'cfg> {
542542
// Ensure the requested source_id is loaded
543543
self.ensure_loaded(dep.source_id(), Kind::Normal)
544544
.with_context(|| {
545-
anyhow::format_err!(
545+
format!(
546546
"failed to load source for dependency `{}`",
547547
dep.package_name()
548548
)

src/cargo/core/resolver/dep_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl<'a> RegistryQueryer<'a> {
225225
.into_iter()
226226
.map(|(dep, features)| {
227227
let candidates = self.query(&dep).with_context(|| {
228-
anyhow::format_err!(
228+
format!(
229229
"failed to get `{}` as a dependency of {}",
230230
dep.package_name(),
231231
describe_path(&cx.parents.path_to_bottom(&candidate.package_id())),

src/cargo/core/workspace.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,14 +1415,9 @@ impl WorkspaceRootConfig {
14151415
Some(p) => p,
14161416
None => return Ok(Vec::new()),
14171417
};
1418-
let res = glob(path)
1419-
.with_context(|| anyhow::format_err!("could not parse pattern `{}`", &path))?;
1418+
let res = glob(path).with_context(|| format!("could not parse pattern `{}`", &path))?;
14201419
let res = res
1421-
.map(|p| {
1422-
p.with_context(|| {
1423-
anyhow::format_err!("unable to match path to pattern `{}`", &path)
1424-
})
1425-
})
1420+
.map(|p| p.with_context(|| format!("unable to match path to pattern `{}`", &path)))
14261421
.collect::<Result<Vec<_>, _>>()?;
14271422
Ok(res)
14281423
}

src/cargo/ops/cargo_clean.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,12 @@ fn rm_rf(path: &Path, config: &Config) -> CargoResult<()> {
224224
config
225225
.shell()
226226
.verbose(|shell| shell.status("Removing", path.display()))?;
227-
paths::remove_dir_all(path)
228-
.with_context(|| anyhow::format_err!("could not remove build directory"))?;
227+
paths::remove_dir_all(path).with_context(|| "could not remove build directory")?;
229228
} else if m.is_ok() {
230229
config
231230
.shell()
232231
.verbose(|shell| shell.status("Removing", path.display()))?;
233-
paths::remove_file(path)
234-
.with_context(|| anyhow::format_err!("failed to remove build artifact"))?;
232+
paths::remove_file(path).with_context(|| "failed to remove build artifact")?;
235233
}
236234
Ok(())
237235
}

src/cargo/ops/cargo_install.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ fn install_one(
357357
td.into_path();
358358
}
359359

360-
format_err!(
360+
format!(
361361
"failed to compile `{}`, intermediate artifacts can be \
362362
found at `{}`",
363363
pkg,
@@ -422,7 +422,7 @@ fn install_one(
422422
let dst = dst.join(bin);
423423
config.shell().status("Installing", dst.display())?;
424424
fs::rename(&src, &dst).with_context(|| {
425-
format_err!("failed to move `{}` to `{}`", src.display(), dst.display())
425+
format!("failed to move `{}` to `{}`", src.display(), dst.display())
426426
})?;
427427
installed.bins.push(dst);
428428
successful_bins.insert(bin.to_string());
@@ -437,7 +437,7 @@ fn install_one(
437437
let dst = dst.join(bin);
438438
config.shell().status("Replacing", dst.display())?;
439439
fs::rename(&src, &dst).with_context(|| {
440-
format_err!("failed to move `{}` to `{}`", src.display(), dst.display())
440+
format!("failed to move `{}` to `{}`", src.display(), dst.display())
441441
})?;
442442
successful_bins.insert(bin.to_string());
443443
}

0 commit comments

Comments
 (0)