Skip to content

Warn when passing what looks like multiple arguments to a single std::process::Command::arg(...) call #10316

Closed
@HayleyDeckers

Description

@HayleyDeckers

What it does

Emit a warning when an argument of the form "-x foo", "--abc bar", /X baz, or a concatenation of these is passed to std::process::Command::arg(...) and suggest to use either multiple arg calls or a single args call instead.

In these cases the programmer likely intended to pass multiple args to the process, and probably wants to use something like std::process::Command::args(["-x", "foo"]) instead.

Lint Name

possible_multiple_args_in_arg

Category

suspicious

Advantage

  • prevent unintended behavior when executing other processes with Command.

Drawbacks

This lint will by design always have some false-positives as Clippy can't be sure this isn't what you wanted to do.

Example

std::process::Command::new("mkdir")
        .arg("-p foo/bar")

Could be written as:

std::process::Command::new("mdkir")
        .args(["-p", "foo/bar"])

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions