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 @@ fn run_command(
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) => {
@ -356,7 +356,7 @@ fn run_command(
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;
@ -396,7 +396,7 @@ fn run_command(
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
};
@ -490,7 +490,7 @@ pub(crate) fn rustc_crates(
// 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"),
}

View File

@ -285,7 +285,7 @@ pub fn fetch_metadata(
// 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();
@ -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);
@ -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);

View File

@ -19,7 +19,7 @@ fn from_str(s: &str) -> Result<Self, Self::Err> {
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 }
}

View File

@ -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)]

View File

@ -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() });
}
}

View File

@ -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);

View File

@ -241,7 +241,7 @@ fn load_inner(
.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),
@ -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 }
@ -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,
@ -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,
@ -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,