Skip to content

Emit warning when there is no space between -o and arg #143719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xizheyin
Copy link
Contributor

@xizheyin xizheyin commented Jul 10, 2025

Closes #142812

getopt doesn't seem to have an API to check this, so we have to check the args manually.

r? compiler

@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 10, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 10, 2025

This PR modifies run-make tests.

cc @jieyouxu

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable, though I can imagine this might be a bit annoying. I'll defer to @wesleywiser for a second opinion.

@jieyouxu
Copy link
Member

r? @wesleywiser (re. #142812)

@rustbot rustbot assigned wesleywiser and unassigned jieyouxu Jul 10, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 10, 2025

wesleywiser is not on the review rotation at the moment.
They may take a while to respond.

@jieyouxu
Copy link
Member

Ah right. I'll wait a bit in case Wesley has feedback.
r? jieyouxu

Comment on lines 1240 to 1286
// To avoid confusion, emit warning if no space
// between `-o` and arg, e.g.`-optimize`, is applied, see issue #142812
if let Some(name) = matches.opt_str("o") {
if args.iter().any(|arg| arg.starts_with("-o") && !arg.starts_with("-o=") && arg.ne("-o")) {
early_dcx.early_warn(format!("option `-o {}` is applied", name));
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: if we're going to emit this warning, can you also include a bit more context on why this is warned on in the first place and how users can address this warning? I.e. for the wording, I suggest

warning: option `-o` has no space between flag name and value, which can be confusing
help: option `-o {}` is applied instead of a flag named `o{}`
help: if you meant to specify output filename `{}`, write `-o {}` instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: also, maybe remark this case in the rustc book on compiler flags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestions, I will finish this later.

Copy link
Member

@jieyouxu jieyouxu Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to hold off on changing this for a moment, still discussing formulation of this warning in the linked thread

@jieyouxu
Copy link
Member

jieyouxu commented Jul 10, 2025

Asking for some more opinions about if warning on -ofilename might be too annoying. Let's give it sometime for the vibecheck, flip this to review / ping me by next thursday (2025-07-17) if we don't have a resolution by then yet.

cf. #t-compiler > Warn on `-ofilename`/`-Lpath` without space

@rustbot label: -S-waiting-on-review +S-waiting-on-team

@rustbot rustbot added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 10, 2025
@xizheyin
Copy link
Contributor Author

xizheyin commented Jul 11, 2025

Now, it prints like this

$ rustc +stage1 src/main.rs -optimize
warning: option `-o` has no space between flag name and value, which can be confusing

note: option `-o ptimize` is applied instead of a flag named `optimize` to specify output filename `ptimize`

$ rustc +stage1 src/main.rs -out-dir
warning: option `-o` has no space between flag name and value, which can be confusing

note: option `-o ut-dir` is applied instead of a flag named `out-dir` to specify output filename `ut-dir`

note: Do you mean `--out-dir`?

$ rustc +stage1 src/main.rs -overflow-checks
warning: option `-o` has no space between flag name and value, which can be confusing

note: option `-o verflow-checks` is applied instead of a flag named `overflow-checks` to specify output filename `verflow-checks`

note: Do you mean `-C overflow_checks`?

$ rustc +stage1 src/main.rs -overflow_checks
warning: option `-o` has no space between flag name and value, which can be confusing

note: option `-o verflow_checks` is applied instead of a flag named `overflow_checks` to specify output filename `verflow_checks`

note: Do you mean `-C overflow_checks`?

$ rustc +stage1 src/main.rs -o3
warning: option `-o` has no space between flag name and value, which can be confusing

note: option `-o 3` is applied instead of a flag named `o3` to specify output filename `3`

Copy link
Contributor Author

@xizheyin xizheyin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rustbot ready

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 11, 2025
@jieyouxu jieyouxu removed the S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). label Jul 12, 2025
Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, some thoughts. Mostly to make this even more conservative.

Comment on lines 168 to 173
for option in optgroups {
let prefix = String::from("--");
if starts_with_ignoring_separators(option.long_name(), suspect) {
return Some(prefix + option.long_name());
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: I would also not bother with e.g. --oprint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, -oprint won't emit a warning, do you mean we should emit a warning?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'm not sure what I meant by this, I meant we should not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's the way it is now. it match oprint which does not exist in rustc option group.

@jieyouxu
Copy link
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 15, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 15, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@xizheyin
Copy link
Contributor Author

Done :)

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 15, 2025
Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. We'll have to see if even this ends up too annoying in practice, but IMO this is sufficiently conservative.

@jieyouxu
Copy link
Member

You can r=me once PR CI is green.
@bors delegate+ rollup

@bors
Copy link
Collaborator

bors commented Jul 15, 2025

✌️ @xizheyin, you can now approve this pull request!

If @jieyouxu told you to "r=me" after making some further change, please make that change, then do @bors r=@jieyouxu

@xizheyin
Copy link
Contributor Author

@bors r=@jieyouxu

@bors
Copy link
Collaborator

bors commented Jul 15, 2025

📌 Commit 2110bc1 has been approved by jieyouxu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 15, 2025
samueltardieu added a commit to samueltardieu/rust that referenced this pull request Jul 15, 2025
Emit warning when there is no space between `-o` and arg

Closes rust-lang#142812

`getopt` doesn't seem to have an API to check this, so we have to check the args manually.

r? compiler
samueltardieu added a commit to samueltardieu/rust that referenced this pull request Jul 15, 2025
Emit warning when there is no space between `-o` and arg

Closes rust-lang#142812

`getopt` doesn't seem to have an API to check this, so we have to check the args manually.

r? compiler
samueltardieu added a commit to samueltardieu/rust that referenced this pull request Jul 15, 2025
Emit warning when there is no space between `-o` and arg

Closes rust-lang#142812

`getopt` doesn't seem to have an API to check this, so we have to check the args manually.

r? compiler
samueltardieu added a commit to samueltardieu/rust that referenced this pull request Jul 15, 2025
Emit warning when there is no space between `-o` and arg

Closes rust-lang#142812

`getopt` doesn't seem to have an API to check this, so we have to check the args manually.

r? compiler
samueltardieu added a commit to samueltardieu/rust that referenced this pull request Jul 15, 2025
Emit warning when there is no space between `-o` and arg

Closes rust-lang#142812

`getopt` doesn't seem to have an API to check this, so we have to check the args manually.

r? compiler
bors added a commit that referenced this pull request Jul 15, 2025
Rollup of 12 pull requests

Successful merges:

 - #142936 (rustdoc-json: Structured attributes)
 - #143355 (wrapping shift: remove first bitmask and table)
 - #143448 (remote-test-client: Exit code `128 + <signal-number>` instead of `3`)
 - #143692 (miri: fix out-of-bounds error for ptrs with negative offsets)
 - #143719 (Emit warning when there is no space between `-o` and arg)
 - #143738 (Move several float tests to floats/mod.rs)
 - #143891 (Port `#[coverage]` to the new attribute system)
 - #143920 (Make more of codegen_llvm safe)
 - #143921 (Constify `Index` traits)
 - #143939 (Add 0323pin as maintainer of NetBSD targets, fix link to pkgsrc-wip and explain.)
 - #143948 (Update mdbook to 0.4.52)
 - #143968 (Add tracing to `InterpCx::fn_abi_of_instance/fn_abi_of_fn_ptr`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 15, 2025
Rollup of 12 pull requests

Successful merges:

 - #142936 (rustdoc-json: Structured attributes)
 - #143355 (wrapping shift: remove first bitmask and table)
 - #143448 (remote-test-client: Exit code `128 + <signal-number>` instead of `3`)
 - #143692 (miri: fix out-of-bounds error for ptrs with negative offsets)
 - #143719 (Emit warning when there is no space between `-o` and arg)
 - #143738 (Move several float tests to floats/mod.rs)
 - #143891 (Port `#[coverage]` to the new attribute system)
 - #143920 (Make more of codegen_llvm safe)
 - #143921 (Constify `Index` traits)
 - #143939 (Add 0323pin as maintainer of NetBSD targets, fix link to pkgsrc-wip and explain.)
 - #143948 (Update mdbook to 0.4.52)
 - #143968 (Add tracing to `InterpCx::fn_abi_of_instance/fn_abi_of_fn_ptr`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 15, 2025
Rollup of 12 pull requests

Successful merges:

 - #142936 (rustdoc-json: Structured attributes)
 - #143355 (wrapping shift: remove first bitmask and table)
 - #143448 (remote-test-client: Exit code `128 + <signal-number>` instead of `3`)
 - #143692 (miri: fix out-of-bounds error for ptrs with negative offsets)
 - #143719 (Emit warning when there is no space between `-o` and arg)
 - #143738 (Move several float tests to floats/mod.rs)
 - #143891 (Port `#[coverage]` to the new attribute system)
 - #143920 (Make more of codegen_llvm safe)
 - #143921 (Constify `Index` traits)
 - #143939 (Add 0323pin as maintainer of NetBSD targets, fix link to pkgsrc-wip and explain.)
 - #143948 (Update mdbook to 0.4.52)
 - #143968 (Add tracing to `InterpCx::fn_abi_of_instance/fn_abi_of_fn_ptr`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 15, 2025
Rollup of 12 pull requests

Successful merges:

 - #142936 (rustdoc-json: Structured attributes)
 - #143355 (wrapping shift: remove first bitmask and table)
 - #143448 (remote-test-client: Exit code `128 + <signal-number>` instead of `3`)
 - #143692 (miri: fix out-of-bounds error for ptrs with negative offsets)
 - #143719 (Emit warning when there is no space between `-o` and arg)
 - #143738 (Move several float tests to floats/mod.rs)
 - #143891 (Port `#[coverage]` to the new attribute system)
 - #143920 (Make more of codegen_llvm safe)
 - #143921 (Constify `Index` traits)
 - #143939 (Add 0323pin as maintainer of NetBSD targets, fix link to pkgsrc-wip and explain.)
 - #143948 (Update mdbook to 0.4.52)
 - #143968 (Add tracing to `InterpCx::fn_abi_of_instance/fn_abi_of_fn_ptr`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 15, 2025
Rollup of 12 pull requests

Successful merges:

 - #142936 (rustdoc-json: Structured attributes)
 - #143355 (wrapping shift: remove first bitmask and table)
 - #143448 (remote-test-client: Exit code `128 + <signal-number>` instead of `3`)
 - #143692 (miri: fix out-of-bounds error for ptrs with negative offsets)
 - #143719 (Emit warning when there is no space between `-o` and arg)
 - #143738 (Move several float tests to floats/mod.rs)
 - #143891 (Port `#[coverage]` to the new attribute system)
 - #143920 (Make more of codegen_llvm safe)
 - #143921 (Constify `Index` traits)
 - #143939 (Add 0323pin as maintainer of NetBSD targets, fix link to pkgsrc-wip and explain.)
 - #143948 (Update mdbook to 0.4.52)
 - #143968 (Add tracing to `InterpCx::fn_abi_of_instance/fn_abi_of_fn_ptr`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 15, 2025
Rollup of 12 pull requests

Successful merges:

 - #142936 (rustdoc-json: Structured attributes)
 - #143355 (wrapping shift: remove first bitmask and table)
 - #143448 (remote-test-client: Exit code `128 + <signal-number>` instead of `3`)
 - #143692 (miri: fix out-of-bounds error for ptrs with negative offsets)
 - #143719 (Emit warning when there is no space between `-o` and arg)
 - #143738 (Move several float tests to floats/mod.rs)
 - #143891 (Port `#[coverage]` to the new attribute system)
 - #143920 (Make more of codegen_llvm safe)
 - #143921 (Constify `Index` traits)
 - #143939 (Add 0323pin as maintainer of NetBSD targets, fix link to pkgsrc-wip and explain.)
 - #143948 (Update mdbook to 0.4.52)
 - #143968 (Add tracing to `InterpCx::fn_abi_of_instance/fn_abi_of_fn_ptr`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 15, 2025
Rollup of 12 pull requests

Successful merges:

 - #142936 (rustdoc-json: Structured attributes)
 - #143355 (wrapping shift: remove first bitmask and table)
 - #143448 (remote-test-client: Exit code `128 + <signal-number>` instead of `3`)
 - #143692 (miri: fix out-of-bounds error for ptrs with negative offsets)
 - #143719 (Emit warning when there is no space between `-o` and arg)
 - #143738 (Move several float tests to floats/mod.rs)
 - #143891 (Port `#[coverage]` to the new attribute system)
 - #143920 (Make more of codegen_llvm safe)
 - #143921 (Constify `Index` traits)
 - #143939 (Add 0323pin as maintainer of NetBSD targets, fix link to pkgsrc-wip and explain.)
 - #143948 (Update mdbook to 0.4.52)
 - #143968 (Add tracing to `InterpCx::fn_abi_of_instance/fn_abi_of_fn_ptr`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 15, 2025
Rollup of 12 pull requests

Successful merges:

 - #142936 (rustdoc-json: Structured attributes)
 - #143355 (wrapping shift: remove first bitmask and table)
 - #143448 (remote-test-client: Exit code `128 + <signal-number>` instead of `3`)
 - #143692 (miri: fix out-of-bounds error for ptrs with negative offsets)
 - #143719 (Emit warning when there is no space between `-o` and arg)
 - #143738 (Move several float tests to floats/mod.rs)
 - #143891 (Port `#[coverage]` to the new attribute system)
 - #143920 (Make more of codegen_llvm safe)
 - #143921 (Constify `Index` traits)
 - #143939 (Add 0323pin as maintainer of NetBSD targets, fix link to pkgsrc-wip and explain.)
 - #143948 (Update mdbook to 0.4.52)
 - #143968 (Add tracing to `InterpCx::fn_abi_of_instance/fn_abi_of_fn_ptr`)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

-L and -o rustc arguments can be used unintuitively
5 participants