Skip to content

Conversation

@epage
Copy link
Contributor

@epage epage commented Nov 7, 2025

What does this PR try to resolve?

It is not obvious that how to escape arguments to be forwarded literally to an underlying program, like --help.

cargo test has a message:

Run `cargo test -- --help` for test binary options.

Mirroring that exactly in cargo run isn't appropriate because we'd be saying there is --help when there might not be.

Instead, I took inspiration from clap's error message:

$ cargo test --gfdfgdf
error: unexpected argument '--gfdfgdf' found

  tip: to pass '--gfdfgdf' as a value, use '-- --gfdfgdf'

Usage: cargo test [OPTIONS] [TESTNAME] [-- [ARGS]...]

For more information, try '--help'.

I checked cargo rustc and cargo rustdoc to see if they could be helped like this but they will return errors about needing to specify the specific binary, so they are a little more complicated.

Fixes #9707

How to test and review this PR?

It is not obvious that how to escape arguments to be forwarded literally to an underlying program,
like `--help`.

`cargo test` has a message:
```
Run `cargo test -- --help` for test binary options.
```

Mirroring that exactly in `cargo run` isn't appropriate because we'd be
saying there is `--help` when there might not be.

Instead, I took inspiration from clap's error message:
```console
$ cargo test --gfdfgdf
error: unexpected argument '--gfdfgdf' found

  tip: to pass '--gfdfgdf' as a value, use '-- --gfdfgdf'

Usage: cargo test [OPTIONS] [TESTNAME] [-- [ARGS]...]

For more information, try '--help'.
```

I checked `cargo rustc` and `cargo rustdoc` to see if they could be
helped like this but they will return errors about needing to specify
the specific binary, so they are a little more complicated.

Fixes rust-lang#9707
@rustbot rustbot added A-cli Area: Command-line interface, option parsing, etc. Command-run S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 7, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 7, 2025

r? @ehuss

rustbot has assigned @ehuss.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@weihanglo weihanglo enabled auto-merge November 7, 2025 20:16
@weihanglo weihanglo added this pull request to the merge queue Nov 7, 2025
Merged via the queue into rust-lang:master with commit 1252c54 Nov 7, 2025
25 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 7, 2025
@epage epage deleted the escape branch November 7, 2025 21:10
bors added a commit to rust-lang/rust that referenced this pull request Nov 12, 2025
Update cargo

10 commits in 445fe4a68f469bf936b2fd81de2c503b233a7f4f..2d4fa139552ebdd5f091a1401ed03f7dc62cb43f
2025-11-07 18:08:19 +0000 to 2025-11-12 15:56:06 +0000
- feat: Add unstable rustc-unicode flag (rust-lang/cargo#16243)
- fix(package): all tar entries timestamp be the same (rust-lang/cargo#16242)
- feat: emit help messages for github pull request url in dependency (rust-lang/cargo#16207)
- docs: fix comments for alternative registry fns (rust-lang/cargo#16235)
- add into_value utility function for inheritableField (rust-lang/cargo#16234)
- fix(command-vendor): strip_prefix panic in cp_sources method (rust-lang/cargo#16214)
- fix(lock): Be moore direct in the error message (rust-lang/cargo#16233)
- fix(lock): In error, differentiate between creating and updating lockfile (rust-lang/cargo#16227)
- fix(cli): Refer to commands, not subcommands (rust-lang/cargo#16226)
- fix(run): Help teach about argument escaping (rust-lang/cargo#16225)
@rustbot rustbot added this to the 1.93.0 milestone Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area: Command-line interface, option parsing, etc. Command-run

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Detect if --help was likely intended for binary being run

4 participants