Skip to content

Commit fde2337

Browse files
committed
Fewer temporary needless strings
1 parent 743d4ab commit fde2337

File tree

7 files changed

+16
-18
lines changed

7 files changed

+16
-18
lines changed

credential/cargo-credential/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ pub enum Error {
4242
}
4343

4444
impl From<String> for Error {
45-
fn from(err: String) -> Self {
45+
fn from(message: String) -> Self {
4646
Box::new(StringTypedError {
47-
message: err.to_string(),
47+
message,
4848
source: None,
4949
})
5050
.into()

src/cargo/core/compiler/custom_build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
281281
.env("NUM_JOBS", &bcx.jobs().to_string())
282282
.env("TARGET", bcx.target_data.short_name(&unit.kind))
283283
.env("DEBUG", debug.to_string())
284-
.env("OPT_LEVEL", &unit.profile.opt_level.to_string())
284+
.env("OPT_LEVEL", &unit.profile.opt_level)
285285
.env(
286286
"PROFILE",
287287
match unit.profile.root {

src/cargo/core/compiler/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
252252
let mut rustc = prepare_rustc(cx, unit)?;
253253
let build_plan = cx.bcx.build_config.build_plan;
254254

255-
let name = unit.pkg.name().to_string();
255+
let name = unit.pkg.name();
256256
let buildkey = unit.buildkey();
257257

258258
let outputs = cx.outputs(unit)?;
@@ -785,7 +785,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
785785
paths::create_dir_all(&doc_dir)?;
786786

787787
let target_desc = unit.target.description_named();
788-
let name = unit.pkg.name().to_string();
788+
let name = unit.pkg.name();
789789
let build_script_outputs = Arc::clone(&cx.build_script_outputs);
790790
let package_id = unit.pkg.package_id();
791791
let manifest_path = PathBuf::from(unit.pkg.manifest_path());

src/cargo/core/package.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ pub struct Downloads<'a, 'cfg> {
338338
/// Total bytes for all successfully downloaded packages.
339339
downloaded_bytes: u64,
340340
/// Size (in bytes) and package name of the largest downloaded package.
341-
largest: (u64, String),
341+
largest: (u64, InternedString),
342342
/// Time when downloading started.
343343
start: Instant,
344344
/// Indicates *all* downloads were successful.
@@ -459,7 +459,7 @@ impl<'cfg> PackageSet<'cfg> {
459459
))),
460460
downloads_finished: 0,
461461
downloaded_bytes: 0,
462-
largest: (0, String::new()),
462+
largest: (0, InternedString::new("")),
463463
success: false,
464464
updated_at: Cell::new(Instant::now()),
465465
timeout,
@@ -891,7 +891,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
891891
self.downloads_finished += 1;
892892
self.downloaded_bytes += dl.total.get();
893893
if dl.total.get() > self.largest.0 {
894-
self.largest = (dl.total.get(), dl.id.name().to_string());
894+
self.largest = (dl.total.get(), dl.id.name());
895895
}
896896

897897
// We're about to synchronously extract the crate below. While we're

src/cargo/core/resolver/dep_cache.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -531,10 +531,9 @@ impl RequirementError {
531531
summary.package_id(),
532532
feat
533533
)),
534-
Some(p) => ActivateError::Conflict(
535-
p,
536-
ConflictReason::MissingFeatures(feat.to_string()),
537-
),
534+
Some(p) => {
535+
ActivateError::Conflict(p, ConflictReason::MissingFeatures(feat))
536+
}
538537
};
539538
}
540539
if deps.iter().any(|dep| dep.is_optional()) {
@@ -575,10 +574,9 @@ impl RequirementError {
575574
)),
576575
// This code path currently isn't used, since `foo/bar`
577576
// and `dep:` syntax is not allowed in a dependency.
578-
Some(p) => ActivateError::Conflict(
579-
p,
580-
ConflictReason::MissingFeatures(dep_name.to_string()),
581-
),
577+
Some(p) => {
578+
ActivateError::Conflict(p, ConflictReason::MissingFeatures(dep_name))
579+
}
582580
}
583581
}
584582
RequirementError::Cycle(feat) => ActivateError::Fatal(anyhow::format_err!(

src/cargo/core/resolver/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ pub enum ConflictReason {
285285
/// A dependency listed features that weren't actually available on the
286286
/// candidate. For example we tried to activate feature `foo` but the
287287
/// candidate we're activating didn't actually have the feature `foo`.
288-
MissingFeatures(String),
288+
MissingFeatures(InternedString),
289289

290290
/// A dependency listed a feature that ended up being a required dependency.
291291
/// For example we tried to activate feature `foo` but the

src/cargo/util/toml/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2326,7 +2326,7 @@ impl TomlManifest {
23262326
let mut names_sources = BTreeMap::new();
23272327
for dep in &deps {
23282328
let name = dep.name_in_toml();
2329-
let prev = names_sources.insert(name.to_string(), dep.source_id());
2329+
let prev = names_sources.insert(name, dep.source_id());
23302330
if prev.is_some() && prev != Some(dep.source_id()) {
23312331
bail!(
23322332
"Dependency '{}' has different source paths depending on the build \

0 commit comments

Comments
 (0)