Skip to content

Conversation

@xizheyin
Copy link
Member

@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
Member 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 DEPRECATED: Use the team-based variants `S-waiting-on-t-lang`, `S-waiting-on-t-compiler`, ... and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 10, 2025
@xizheyin
Copy link
Member 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
Member 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 DEPRECATED: Use the team-based variants `S-waiting-on-t-lang`, `S-waiting-on-t-compiler`, ... 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
Member 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
Member 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.

Comment on lines +1 to +5
// This test is to check if the warning is emitted when no space
// between `-o` and arg is applied, see issue #142812

//@ ignore-cross-compile
use run_make_support::rustc;
Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I see now. I added it on top of the test,

@jieyouxu
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 16, 2025

📌 Commit af39c0c 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 16, 2025
@bors bors merged commit 26f5936 into rust-lang:master Jul 18, 2025
11 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 18, 2025
@xizheyin xizheyin deleted the 142812-1 branch July 21, 2025 14:21
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

6 participants