project-model: Fix warnings about clippy str_to_string rule

This commit is contained in:
Tetsuharu Ohzeki 2024-02-10 00:37:27 +09:00
parent d00f1c1b16
commit 5d1f2835af
7 changed files with 16 additions and 16 deletions

View file

@ -322,7 +322,7 @@ impl WorkspaceBuildScripts {
let mut deserializer = serde_json::Deserializer::from_str(line); let mut deserializer = serde_json::Deserializer::from_str(line);
deserializer.disable_recursion_limit(); deserializer.disable_recursion_limit();
let message = Message::deserialize(&mut deserializer) let message = Message::deserialize(&mut deserializer)
.unwrap_or_else(|_| Message::TextLine(line.to_string())); .unwrap_or_else(|_| Message::TextLine(line.to_owned()));
match message { match message {
Message::BuildScriptExecuted(mut message) => { Message::BuildScriptExecuted(mut message) => {
@ -356,7 +356,7 @@ impl WorkspaceBuildScripts {
if let Some(out_dir) = if let Some(out_dir) =
out_dir.as_os_str().to_str().map(|s| s.to_owned()) 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.out_dir = Some(out_dir);
data.cfgs = cfgs; data.cfgs = cfgs;
@ -396,7 +396,7 @@ impl WorkspaceBuildScripts {
let errors = if !output.status.success() { let errors = if !output.status.success() {
let errors = errors.into_inner(); 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 { } else {
None None
}; };
@ -490,7 +490,7 @@ impl WorkspaceBuildScripts {
// FIXME: Find a better way to know if it is a dylib. // FIXME: Find a better way to know if it is a dylib.
fn is_dylib(path: &Utf8Path) -> bool { 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, None => false,
Some(ext) => matches!(ext.as_str(), "dll" | "dylib" | "so"), Some(ext) => matches!(ext.as_str(), "dll" | "dylib" | "so"),
} }

View file

@ -285,7 +285,7 @@ impl CargoWorkspace {
// FIXME: Fetching metadata is a slow process, as it might require // FIXME: Fetching metadata is a slow process, as it might require
// calling crates.io. We should be reporting progress here, but it's // calling crates.io. We should be reporting progress here, but it's
// unclear whether cargo itself supports it. // unclear whether cargo itself supports it.
progress("metadata".to_string()); progress("metadata".to_owned());
(|| -> Result<cargo_metadata::Metadata, cargo_metadata::Error> { (|| -> Result<cargo_metadata::Metadata, cargo_metadata::Error> {
let mut command = meta.cargo_command(); let mut command = meta.cargo_command();
@ -502,7 +502,7 @@ fn rustc_discover_host_triple(
let field = "host: "; let field = "host: ";
let target = stdout.lines().find_map(|l| l.strip_prefix(field)); let target = stdout.lines().find_map(|l| l.strip_prefix(field));
if let Some(target) = target { if let Some(target) = target {
Some(target.to_string()) Some(target.to_owned())
} else { } else {
// If we fail to resolve the host platform, it's not the end of the world. // 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); tracing::info!("rustc -vV did not report host platform, got:\n{}", stdout);
@ -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('"'); let trimmed = stdout.trim_start_matches("build.target = ").trim_matches('"');
if !trimmed.starts_with('[') { if !trimmed.starts_with('[') {
return [trimmed.to_string()].to_vec(); return [trimmed.to_owned()].to_vec();
} }
let res = serde_json::from_str(trimmed); let res = serde_json::from_str(trimmed);

View file

@ -19,7 +19,7 @@ impl FromStr for CfgFlag {
if !(value.starts_with('"') && value.ends_with('"')) { if !(value.starts_with('"') && value.ends_with('"')) {
return Err(format!("Invalid cfg ({s:?}), value should be in quotes")); 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(); let value = value[1..value.len() - 1].to_string();
CfgFlag::KeyValue { key, value } CfgFlag::KeyValue { key, value }
} }

View file

@ -167,7 +167,7 @@ fn utf8_stdout(mut cmd: Command) -> anyhow::Result<String> {
} }
} }
let stdout = String::from_utf8(output.stdout)?; let stdout = String::from_utf8(output.stdout)?;
Ok(stdout.trim().to_string()) Ok(stdout.trim().to_owned())
} }
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]

View file

@ -33,7 +33,7 @@ pub(crate) fn get(
res.push(CfgFlag::Atom("target_thread_local".into())); res.push(CfgFlag::Atom("target_thread_local".into()));
for ty in ["8", "16", "32", "64", "cas", "ptr"] { for ty in ["8", "16", "32", "64", "cas", "ptr"] {
for key in ["target_has_atomic", "target_has_atomic_load_store"] { 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() });
} }
} }

View file

@ -129,7 +129,7 @@ fn get_fake_sysroot() -> Sysroot {
} }
fn rooted_project_json(data: ProjectJsonData) -> ProjectJson { fn rooted_project_json(data: ProjectJsonData) -> ProjectJson {
let mut root = "$ROOT$".to_string(); let mut root = "$ROOT$".to_owned();
replace_root(&mut root, true); replace_root(&mut root, true);
let path = Path::new(&root); let path = Path::new(&root);
let base = AbsPath::assert(path); let base = AbsPath::assert(path);

View file

@ -241,7 +241,7 @@ impl ProjectWorkspace {
.map_err(|p| Some(format!("rustc source path is not absolute: {p}"))), .map_err(|p| Some(format!("rustc source path is not absolute: {p}"))),
Some(RustLibSource::Discover) => { Some(RustLibSource::Discover) => {
sysroot.as_ref().ok().and_then(Sysroot::discover_rustc_src).ok_or_else( 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), None => Err(None),
@ -840,7 +840,7 @@ fn project_json_to_crate_graph(
if let Some(name) = display_name.clone() { if let Some(name) = display_name.clone() {
CrateOrigin::Local { CrateOrigin::Local {
repo: repository.clone(), repo: repository.clone(),
name: Some(name.canonical_name().to_string()), name: Some(name.canonical_name().to_owned()),
} }
} else { } else {
CrateOrigin::Local { repo: None, name: None } CrateOrigin::Local { repo: None, name: None }
@ -1117,7 +1117,7 @@ fn detached_files_to_crate_graph(
let display_name = detached_file let display_name = detached_file
.file_stem() .file_stem()
.and_then(|os_str| os_str.to_str()) .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( let detached_file_crate = crate_graph.add_crate_root(
file_id, file_id,
Edition::CURRENT, Edition::CURRENT,
@ -1129,7 +1129,7 @@ fn detached_files_to_crate_graph(
false, false,
CrateOrigin::Local { CrateOrigin::Local {
repo: None, 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(), target_layout.clone(),
None, None,
@ -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( let crate_id = crate_graph.add_crate_root(
file_id, file_id,
edition, edition,