From e76370b3b7ab857556779159fd390fd5f94609df Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Sat, 14 Feb 2026 15:50:25 +0000 Subject: [PATCH] clippy: fix str_to_string lint https://rust-lang.github.io/rust-clippy/master/index.html#str_to_string Closes #12449 --- Cargo.toml | 1 + build.rs | 8 +++----- crates/build-man-pages/build.rs | 4 ++-- src/builtins/jobs.rs | 2 +- src/event.rs | 6 +++--- src/locale.rs | 2 +- src/proc.rs | 2 +- src/screen.rs | 2 +- 8 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 50e2b4118..f3206daf0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -215,6 +215,7 @@ ptr_offset_by_literal = "warn" ref_option = "warn" semicolon_if_nothing_returned = "warn" stable_sort_primitive = "warn" +str_to_string = "warn" unnecessary_semicolon = "warn" # We do not want to use the e?print(ln)?! macros. diff --git a/build.rs b/build.rs index 747ab6d6b..a95131a0f 100644 --- a/build.rs +++ b/build.rs @@ -159,16 +159,14 @@ fn join_if_relative(parent_if_relative: &Path, path: String) -> PathBuf { } let prefix = overridable_path("PREFIX", |env_prefix| { - Some(PathBuf::from( - env_prefix.unwrap_or("/usr/local".to_string()), - )) + Some(PathBuf::from(env_prefix.unwrap_or("/usr/local".to_owned()))) }) .unwrap(); overridable_path("SYSCONFDIR", |env_sysconfdir| { Some(join_if_relative( &prefix, - env_sysconfdir.unwrap_or("/etc/".to_string()), + env_sysconfdir.unwrap_or("/etc/".to_owned()), )) }); @@ -199,5 +197,5 @@ fn get_version() -> String { ) .unwrap() .trim_ascii_end() - .to_string() + .to_owned() } diff --git a/crates/build-man-pages/build.rs b/crates/build-man-pages/build.rs index b82666871..2649a16cc 100644 --- a/crates/build-man-pages/build.rs +++ b/crates/build-man-pages/build.rs @@ -43,7 +43,7 @@ fn build_man(sec1_dir: &Path) { ]; rsconf::rebuild_if_env_changed("FISH_BUILD_DOCS"); - if env_var("FISH_BUILD_DOCS") == Some("0".to_string()) { + if env_var("FISH_BUILD_DOCS") == Some("0".to_owned()) { rsconf::warn!("Skipping man pages because $FISH_BUILD_DOCS is set to 0"); return; } @@ -62,7 +62,7 @@ fn build_man(sec1_dir: &Path) { Err(e) if e.kind() == std::io::ErrorKind::NotFound => { assert_ne!( env_var("FISH_BUILD_DOCS"), - Some("1".to_string()), + Some("1".to_owned()), "Could not find sphinx-build required to build man pages.\n\ Install Sphinx or disable building the docs by setting $FISH_BUILD_DOCS=0." ); diff --git a/src/builtins/jobs.rs b/src/builtins/jobs.rs index a80ace1f7..859fb2a42 100644 --- a/src/builtins/jobs.rs +++ b/src/builtins/jobs.rs @@ -43,7 +43,7 @@ fn cpu_use(j: &Job) -> f64 { fn builtin_jobs_print(j: &Job, mode: JobsPrintMode, header: bool, streams: &mut IoStreams) { let pgid = match j.get_pgid() { Some(pgid) => pgid.to_string(), - None => "-".to_string(), + None => "-".to_owned(), }; let mut out = WString::new(); diff --git a/src/event.rs b/src/event.rs index d0cf56ef5..dd3b645f3 100644 --- a/src/event.rs +++ b/src/event.rs @@ -380,7 +380,7 @@ pub fn get_desc(parser: &Parser, evt: &Event) -> WString { format!("signal handler for {} ({})", signal.name(), signal.desc(),) } EventDescription::Variable { name } => format!("handler for variable '{name}'"), - EventDescription::ProcessExit { pid: None } => "exit handler for any process".to_string(), + EventDescription::ProcessExit { pid: None } => "exit handler for any process".to_owned(), EventDescription::ProcessExit { pid: Some(pid) } => { format!("exit handler for process {pid}") } @@ -392,11 +392,11 @@ pub fn get_desc(parser: &Parser, evt: &Event) -> WString { format!("exit handler for job with pid {pid}") } } else { - "exit handler for any job".to_string() + "exit handler for any job".to_owned() } } EventDescription::CallerExit { .. } => { - "exit handler for command substitution caller".to_string() + "exit handler for command substitution caller".to_owned() } EventDescription::Generic { param } => format!("handler for generic event '{param}'"), EventDescription::Any => unreachable!(), diff --git a/src/locale.rs b/src/locale.rs index a49b46fdd..41613a433 100644 --- a/src/locale.rs +++ b/src/locale.rs @@ -16,7 +16,7 @@ pub unsafe fn set_libc_locales(log_ok: bool) -> bool { if log_ok { crate::flog::flog!(env_locale, { let source = if value == from_environment { - "from environment".to_string() + "from environment".to_owned() } else { format!("to '{}'", value.to_str().unwrap()) }; diff --git a/src/proc.rs b/src/proc.rs index 71f93e476..5f44451d8 100644 --- a/src/proc.rs +++ b/src/proc.rs @@ -1465,7 +1465,7 @@ fn summary_command(j: &Job, p: Option<&Process>) -> WString { if j.external_procs().count() > 1 { // I don't think it's safe to blindly unwrap here because even though we exited with // a signal, the job could have contained a fish function? - let pid = p.pid().map_or("-".to_string(), |p| p.to_string()); + let pid = p.pid().map_or("-".to_owned(), |p| p.to_string()); buffer += &sprintf!(" %s", pid)[..]; buffer.push(' '); diff --git a/src/screen.rs b/src/screen.rs index 9fcc5ffbb..1e504b4fa 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -583,7 +583,7 @@ pub fn set_position_in_viewport(&mut self, whence: &str, viewport_y: Option".to_string(), |y| format!("{y}")), + viewport_y.map_or("".to_owned(), |y| format!("{y}")), whence, ); self.viewport_y = viewport_y;