Open
Description
Categories: Performance, Correctness, warn-by-default
warn-by-default
because the author may want to verify the UTF-8 validly
of the expression.
Auto-apply suggestion ability
None. It's hard to make correct suggestion.
What it does
Check for convert from lossless OsStr-compatible types (Like Path
, PathBuf
)
to &str
when passing to arguments of std::process::Command
methods:
-
Command::new
-
Command::arg
-
Command::args
-
Command::env
-
Command::envs
-
Command::env_remove
-
Command::current_dir
Known problems
The author may intend to verify the UTF-8 validly of the expression.
Example
use std::path::Path;
use std::process::Command;
// Assume this is the non UTF-8 path
let dest = Path::new("<non-utf8 path>");
Command::new("git")
.args(&[
"clone",
"https://github.com/rust-lang/rust-clippy",
&dest.to_string_lossy(),
])
.status()
.unwrap();
Could be written as:
use std::ffi::OsStr;
Command::new("git")
.args(&[
OsStr::new("clone"),
OsStr::new("https://github.com/rust-lang/rust-clippy"),
OsStr::new(dest),
])
.status()
.unwrap();