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 1259
// 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
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
@jieyouxu jieyouxu removed the S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). label Jul 12, 2025
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-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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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