Skip to content

Commit

Permalink
project-model: Fix warnings about clippy str_to_string rule
Browse files Browse the repository at this point in the history
  • Loading branch information
tetsuharuohzeki committed Feb 9, 2024
1 parent d00f1c1 commit 5d1f283
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions crates/project-model/src/build_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl WorkspaceBuildScripts {
let mut deserializer = serde_json::Deserializer::from_str(line);
deserializer.disable_recursion_limit();
let message = Message::deserialize(&mut deserializer)
.unwrap_or_else(|_| Message::TextLine(line.to_string()));
.unwrap_or_else(|_| Message::TextLine(line.to_owned()));

match message {
Message::BuildScriptExecuted(mut message) => {
Expand Down Expand Up @@ -356,7 +356,7 @@ impl WorkspaceBuildScripts {
if let Some(out_dir) =
out_dir.as_os_str().to_str().map(|s| s.to_owned())
{
data.envs.push(("OUT_DIR".to_string(), out_dir));
data.envs.push(("OUT_DIR".to_owned(), out_dir));
}
data.out_dir = Some(out_dir);
data.cfgs = cfgs;
Expand Down Expand Up @@ -396,7 +396,7 @@ impl WorkspaceBuildScripts {

let errors = if !output.status.success() {
let errors = errors.into_inner();
Some(if errors.is_empty() { "cargo check failed".to_string() } else { errors })
Some(if errors.is_empty() { "cargo check failed".to_owned() } else { errors })
} else {
None
};
Expand Down Expand Up @@ -490,7 +490,7 @@ impl WorkspaceBuildScripts {

// FIXME: Find a better way to know if it is a dylib.
fn is_dylib(path: &Utf8Path) -> bool {
match path.extension().map(|e| e.to_string().to_lowercase()) {
match path.extension().map(|e| e.to_owned().to_lowercase()) {
None => false,
Some(ext) => matches!(ext.as_str(), "dll" | "dylib" | "so"),
}
Expand Down
6 changes: 3 additions & 3 deletions crates/project-model/src/cargo_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl CargoWorkspace {
// FIXME: Fetching metadata is a slow process, as it might require
// calling crates.io. We should be reporting progress here, but it's
// unclear whether cargo itself supports it.
progress("metadata".to_string());
progress("metadata".to_owned());

(|| -> Result<cargo_metadata::Metadata, cargo_metadata::Error> {
let mut command = meta.cargo_command();
Expand Down Expand Up @@ -502,7 +502,7 @@ fn rustc_discover_host_triple(
let field = "host: ";
let target = stdout.lines().find_map(|l| l.strip_prefix(field));
if let Some(target) = target {
Some(target.to_string())
Some(target.to_owned())
} else {
// If we fail to resolve the host platform, it's not the end of the world.
tracing::info!("rustc -vV did not report host platform, got:\n{}", stdout);
Expand Down Expand Up @@ -536,7 +536,7 @@ fn parse_output_cargo_config_build_target(stdout: String) -> Vec<String> {
let trimmed = stdout.trim_start_matches("build.target = ").trim_matches('"');

if !trimmed.starts_with('[') {
return [trimmed.to_string()].to_vec();
return [trimmed.to_owned()].to_vec();
}

let res = serde_json::from_str(trimmed);
Expand Down
2 changes: 1 addition & 1 deletion crates/project-model/src/cfg_flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl FromStr for CfgFlag {
if !(value.starts_with('"') && value.ends_with('"')) {
return Err(format!("Invalid cfg ({s:?}), value should be in quotes"));
}
let key = key.to_string();
let key = key.to_owned();
let value = value[1..value.len() - 1].to_string();
CfgFlag::KeyValue { key, value }
}
Expand Down
2 changes: 1 addition & 1 deletion crates/project-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn utf8_stdout(mut cmd: Command) -> anyhow::Result<String> {
}
}
let stdout = String::from_utf8(output.stdout)?;
Ok(stdout.trim().to_string())
Ok(stdout.trim().to_owned())
}

#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion crates/project-model/src/rustc_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub(crate) fn get(
res.push(CfgFlag::Atom("target_thread_local".into()));
for ty in ["8", "16", "32", "64", "cas", "ptr"] {
for key in ["target_has_atomic", "target_has_atomic_load_store"] {
res.push(CfgFlag::KeyValue { key: key.to_string(), value: ty.into() });
res.push(CfgFlag::KeyValue { key: key.to_owned(), value: ty.into() });
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/project-model/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn get_fake_sysroot() -> Sysroot {
}

fn rooted_project_json(data: ProjectJsonData) -> ProjectJson {
let mut root = "$ROOT$".to_string();
let mut root = "$ROOT$".to_owned();
replace_root(&mut root, true);
let path = Path::new(&root);
let base = AbsPath::assert(path);
Expand Down
10 changes: 5 additions & 5 deletions crates/project-model/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl ProjectWorkspace {
.map_err(|p| Some(format!("rustc source path is not absolute: {p}"))),
Some(RustLibSource::Discover) => {
sysroot.as_ref().ok().and_then(Sysroot::discover_rustc_src).ok_or_else(
|| Some("Failed to discover rustc source for sysroot.".to_string()),
|| Some("Failed to discover rustc source for sysroot.".to_owned()),
)
}
None => Err(None),
Expand Down Expand Up @@ -840,7 +840,7 @@ fn project_json_to_crate_graph(
if let Some(name) = display_name.clone() {
CrateOrigin::Local {
repo: repository.clone(),
name: Some(name.canonical_name().to_string()),
name: Some(name.canonical_name().to_owned()),
}
} else {
CrateOrigin::Local { repo: None, name: None }
Expand Down Expand Up @@ -1117,7 +1117,7 @@ fn detached_files_to_crate_graph(
let display_name = detached_file
.file_stem()
.and_then(|os_str| os_str.to_str())
.map(|file_stem| CrateDisplayName::from_canonical_name(file_stem.to_string()));
.map(|file_stem| CrateDisplayName::from_canonical_name(file_stem.to_owned()));
let detached_file_crate = crate_graph.add_crate_root(
file_id,
Edition::CURRENT,
Expand All @@ -1129,7 +1129,7 @@ fn detached_files_to_crate_graph(
false,
CrateOrigin::Local {
repo: None,
name: display_name.map(|n| n.canonical_name().to_string()),
name: display_name.map(|n| n.canonical_name().to_owned()),
},
target_layout.clone(),
None,
Expand Down Expand Up @@ -1323,7 +1323,7 @@ fn add_target_crate_root(
}
}

let display_name = CrateDisplayName::from_canonical_name(cargo_name.to_string());
let display_name = CrateDisplayName::from_canonical_name(cargo_name.to_owned());
let crate_id = crate_graph.add_crate_root(
file_id,
edition,
Expand Down

0 comments on commit 5d1f283

Please sign in to comment.