From d073870efc518b9d481e30ea08cd09f1ad1ab07a Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Thu, 17 Jul 2025 13:46:48 +0200 Subject: [PATCH] ref: Enable `string-to-string` lint Using `clone` makes it clearer that we are cloning a `String` versus calling `to_string` on a `String. --- Cargo.toml | 1 + src/commands/debug_files/bundle_jvm.rs | 2 +- src/commands/files/upload.rs | 2 +- src/commands/send_event.rs | 2 +- src/commands/sourcemaps/explain.rs | 2 +- src/config.rs | 7 +++---- src/utils/sourcemaps.rs | 11 +++++------ src/utils/vcs.rs | 4 ++-- 8 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8f34e19471..09cee444ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -101,6 +101,7 @@ unstable-mobile-app = ["apple-catalog-parsing"] [workspace.lints.clippy] allow-attributes = "warn" str-to-string = "warn" +string-to-string = "warn" unnecessary-wraps = "warn" unwrap-used = "warn" diff --git a/src/commands/debug_files/bundle_jvm.rs b/src/commands/debug_files/bundle_jvm.rs index bdb5d4911a..df2625d6a4 100644 --- a/src/commands/debug_files/bundle_jvm.rs +++ b/src/commands/debug_files/bundle_jvm.rs @@ -96,7 +96,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> { let local_path_jvm_ext = local_path.with_extension("jvm"); let url = format!("~/{}", path_as_url(&local_path_jvm_ext)); ( - url.to_string(), + url.clone(), SourceFile { url, path: source.path.clone(), diff --git a/src/commands/files/upload.rs b/src/commands/files/upload.rs index 557253de8f..21d3a9de4b 100644 --- a/src/commands/files/upload.rs +++ b/src/commands/files/upload.rs @@ -205,7 +205,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> { let url = format!("{}/{}{}", url_prefix, path_as_url(local_path), url_suffix); ( - url.to_string(), + url.clone(), SourceFile { url, path: source.path.clone(), diff --git a/src/commands/send_event.rs b/src/commands/send_event.rs index 82a7ba9e52..90ea4513bf 100644 --- a/src/commands/send_event.rs +++ b/src/commands/send_event.rs @@ -316,7 +316,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> { if let Some(fingerprint) = matches.get_many::("fingerprint") { event.fingerprint = fingerprint - .map(|x| x.to_string().into()) + .map(|x| x.clone().into()) .collect::>() .into(); } diff --git a/src/commands/sourcemaps/explain.rs b/src/commands/sourcemaps/explain.rs index b0c0132cb2..3ff03d5977 100644 --- a/src/commands/sourcemaps/explain.rs +++ b/src/commands/sourcemaps/explain.rs @@ -333,7 +333,7 @@ fn print_mapped_frame(frame: &Frame) { fn extract_release(event: &ProcessedEvent) -> Result { if let Some(release) = event.release.as_ref() { success(format!("Event has release name: {release}")); - Ok(release.to_string()) + Ok(release.clone()) } else { error("Event is missing a release name"); tip("Configure 'release' option in the SDK.\n \ diff --git a/src/config.rs b/src/config.rs index ded047a9bc..e4e12dbb7a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -194,8 +194,7 @@ impl Config { ); } Some(Auth::Key(ref val)) => { - self.ini - .set_to(Some("auth"), "api_key".into(), val.to_string()); + self.ini.set_to(Some("auth"), "api_key".into(), val.clone()); } None => {} } @@ -351,7 +350,7 @@ impl Config { format_err!("An organization ID or slug is required (provide with --org)") }), (None, Some(cli_org)) => Ok(cli_org), - (Some(token_org), None) => Ok(token_org.to_string()), + (Some(token_org), None) => Ok(token_org.clone()), (Some(token_org), Some(cli_org)) => { if cli_org != *token_org { log::warn!( @@ -381,7 +380,7 @@ impl Config { // Backward compatibility with `releases files ` commands. pub fn get_release_with_legacy_fallback(&self, matches: &ArgMatches) -> Result { if let Some(version) = matches.get_one::("version") { - Ok(version.to_string()) + Ok(version.clone()) } else { self.get_release(matches) } diff --git a/src/utils/sourcemaps.rs b/src/utils/sourcemaps.rs index 686408bdc0..e0351e9a6c 100644 --- a/src/utils/sourcemaps.rs +++ b/src/utils/sourcemaps.rs @@ -292,7 +292,7 @@ impl SourceMapProcessor { .iter() .map(|x| x.1) .filter(|x| x.ty == SourceFileType::SourceMap) - .map(|x| x.url.to_string()) + .map(|x| x.url.clone()) .collect(); for source in self.sources.values_mut() { @@ -325,15 +325,14 @@ impl SourceMapProcessor { source.warn(format!( "could not determine a source map reference ({err})" )); - self.sourcemap_references - .insert(source.url.to_string(), None); + self.sourcemap_references.insert(source.url.clone(), None); continue; } }, }; self.sourcemap_references - .insert(source.url.to_string(), Some(sourcemap_reference)); + .insert(source.url.clone(), Some(sourcemap_reference)); } } @@ -610,7 +609,7 @@ impl SourceMapProcessor { } if let Some(Some(sourcemap)) = self.sourcemap_references.get(&source.url) { - source.set_sourcemap_reference(sourcemap.url.to_string()); + source.set_sourcemap_reference(sourcemap.url.clone()); } } } @@ -925,7 +924,7 @@ impl SourceMapProcessor { let sourcemap_url = match &matches[..] { [] => normalized, - [x] => x.to_string(), + [x] => x.clone(), _ => { warn!("Ambiguous matches for sourcemap path {normalized}:"); for path in matches { diff --git a/src/utils/vcs.rs b/src/utils/vcs.rs index 81f14c40eb..b3738b9c3a 100644 --- a/src/utils/vcs.rs +++ b/src/utils/vcs.rs @@ -424,7 +424,7 @@ pub fn find_heads( } else { for repo in repos { let spec = CommitSpec { - repo: repo.name.to_string(), + repo: repo.name.clone(), path: None, rev: "HEAD".into(), prev_rev: None, @@ -433,7 +433,7 @@ pub fn find_heads( find_matching_rev(spec.reference(), &spec, repos, false, remote_name.clone())? { rv.push(Ref { - repo: repo.name.to_string(), + repo: repo.name.clone(), rev, prev_rev: None, });