Skip to content

Hide unstable print kinds within emit_unknown_print_request_help in stable channel #139850

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

Merged
merged 1 commit into from
Apr 17, 2025

Conversation

xizheyin
Copy link
Contributor

@xizheyin xizheyin commented Apr 15, 2025

Fixes #138698

We need to get the channel from matches. However, since matches(Line 1169) is constructed after rustc_optgroups (Line1165, where RustcOptGroup::value_hint is generated, i.e. what rustc --print print prints), I've left it unchanged here for now.

pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<getopts::Matches> {
// Parse with *all* options defined in the compiler, we don't worry about
// option stability here we just want to parse as much as possible.
let mut options = getopts::Options::new();
let optgroups = config::rustc_optgroups();
for option in &optgroups {
option.apply(&mut options);
}
let matches = options.parse(args).unwrap_or_else(|e| {

There is actually a way to manually parse the --crate-name parameter, but I'm afraid that's an unorthodox practice. So I conservatively just modified emit_unknown_print_request_help to print different parameters depending on whether they are nightly or not when passing the error parameter.

r? @jieyouxu

@rustbot
Copy link
Collaborator

rustbot commented Apr 15, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
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

@rustbot rustbot added 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 Apr 15, 2025
@rustbot rustbot assigned jieyouxu and unassigned petrochenkov Apr 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.

Can you add a functional test for this change? In the test, I'd also like to see exercised:

  • Single stable print flag vs single unstable print flag
  • Mixed unstable/stable print flag

@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 Apr 15, 2025
@xizheyin
Copy link
Contributor Author

Sure no problem, but I would like to know how to add functional tests, is it done locally to me?

@jieyouxu
Copy link
Member

jieyouxu commented Apr 15, 2025

As in, a ui test

e.g. https://rustc-dev-guide.rust-lang.org/tests/adding.html

@xizheyin
Copy link
Contributor Author

Ooh, I have no idea to control the channel, e.g. nightly or stable, in the ui test. It may be like

//@ compile-flags: --print zzz
//@ exec-env:CFG_CHANNEL=stable

//~? ERROR unknown print request: `zzz`

or

//@ exec-env:CFG_RELEASE_CHANNEL=stable

or

//@ exec-env:CFG_DISABLE_UNSTABLE_FEATURES=1

But they are failed. Do you have any suggestion?

@jieyouxu
Copy link
Member

jieyouxu commented Apr 15, 2025

What you can do for the purpose of this test (RUSTC_BOOTSTRAP=1 will permit unstable features, which as a corollary should cause the nightly gating you have to be active)

//@ revisions: force_stable force_unstable
//@[force_stable] rustc-env: RUSTC_BOOTSTRAP=-1
//@[force_unstable] rustc-env: RUSTC_BOOTSTRAP=1

@xizheyin
Copy link
Contributor Author

It works, but it passes unstable flags -Z to the rustc,

command: env -u RUSTC_LOG_COLOR RUSTC_BOOTSTRAP="-1" RUSTC_ICE="0" RUST_BACKTRACE="short" "/home/nju/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" "/home/nju/rust/tests/ui/print-request/hide-unstable-in-stable-issue-138698.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/home/nju/.cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/home/nju/rust/vendor" "--sysroot" "/home/nju/rust/build/x86_64-unknown-linux-gnu/stage1" "--target=x86_64-unknown-linux-gnu" "--cfg" "force_stable" "--check-cfg" "cfg(test,FALSE,force_stable,force_unstable)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/home/nju/rust/build/x86_64-unknown-linux-gnu/test/ui/print-request/hide-unstable-in-stable-issue-138698.force_stable" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/home/nju/rust/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--print" "xxx"

and report

error: the option `Z` is only accepted on the nightly compiler

help: consider switching to a nightly toolchain: `rustup default nightly`

note: selecting a toolchain with `+toolchain` arguments require a rustup proxy; see <https://rust-lang.github.io/rustup/concepts/index.html>

note: for more information about Rust's stability policy, see <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html#unstable-features>

error: 1 nightly option were parsed

How to turn off the flags?

By the way, would it be better to write it to rustc_develop_guide, I didn't find this in the documentation.

@jieyouxu
Copy link
Member

Oh right I forgor about the ui test preset flags. In this case, can you use a run-make test instead, since you want to explicitly control and constrain the exact compiler flags you want to pass.

@jieyouxu
Copy link
Member

By the way, would it be better to write it to rustc_develop_guide, I didn't find this in the documentation.

https://rustc-dev-guide.rust-lang.org/tests/misc.html

@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Apr 16, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 16, 2025

This PR modifies run-make tests.

cc @jieyouxu

@xizheyin
Copy link
Contributor Author

I've added a run-make test for current PR, and a few more that may help later with changes to the relevant topic. So I named it print-in-stable-or-unstable-channel.

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 more nits

@jieyouxu
Copy link
Member

I've added a run-make test for current PR, and a few more that may help later with changes to the relevant topic. So I named it print-in-stable-or-unstable-channel.

Can you call it sth like "print-request-help-stable-unstable" instead (see the review comments above regarding redundant tests)?

@xizheyin
Copy link
Contributor Author

Thank you, I revised it. : ) @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.

Looks good for the most part, some suggestions

@xizheyin
Copy link
Contributor Author

I updated it. 😊

@jieyouxu
Copy link
Member

BTW you can mark PR as ready for review with @rustbot review, otherwise I might not look at S-waiting-on-author PRs in my review queue.

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, can you squash the commits into one?

@xizheyin
Copy link
Contributor Author

Ok, so that's how you review.

@rustbot review

@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 Apr 17, 2025
@jieyouxu
Copy link
Member

jieyouxu commented Apr 17, 2025

Ah yeah, triagebot would print that help message about @rustbot ready (review is an alias for ready) now if I explicitly write:

@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 Apr 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 17, 2025

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

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

@jieyouxu
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Apr 17, 2025

📌 Commit 8562110 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 Apr 17, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 17, 2025
Hide unstable print kinds within emit_unknown_print_request_help in stable channel

Fixes rust-lang#138698

We need to get the channel from `matches`. However, since `matches`(Line 1169) is constructed after `rustc_optgroups` (Line1165, where `RustcOptGroup::value_hint` is generated, i.e. what `rustc --print print` prints), I've left it unchanged here for now.

https://github.com/rust-lang/rust/blob/2da29dbe8fe23df1c7c4ab1d8740ca3c32b15526/compiler/rustc_driver_impl/src/lib.rs#L1161-L1169

There is actually a way to manually parse the `--crate-name` parameter, but I'm afraid that's an unorthodox practice. So I conservatively just modified `emit_unknown_print_request_help` to print different parameters depending on whether they are nightly or not when passing the error parameter.

r? `@jieyouxu`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 17, 2025
Hide unstable print kinds within emit_unknown_print_request_help in stable channel

Fixes rust-lang#138698

We need to get the channel from `matches`. However, since `matches`(Line 1169) is constructed after `rustc_optgroups` (Line1165, where `RustcOptGroup::value_hint` is generated, i.e. what `rustc --print print` prints), I've left it unchanged here for now.

https://github.com/rust-lang/rust/blob/2da29dbe8fe23df1c7c4ab1d8740ca3c32b15526/compiler/rustc_driver_impl/src/lib.rs#L1161-L1169

There is actually a way to manually parse the `--crate-name` parameter, but I'm afraid that's an unorthodox practice. So I conservatively just modified `emit_unknown_print_request_help` to print different parameters depending on whether they are nightly or not when passing the error parameter.

r? ``@jieyouxu``
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 17, 2025
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#139774 (Fix replacing supertrait aliases in `ReplaceProjectionWith`)
 - rust-lang#139850 (Hide unstable print kinds within emit_unknown_print_request_help in stable channel)
 - rust-lang#139870 (add retries to remove and create dir all)
 - rust-lang#139902 (do not emit `OpaqueCast` projections with `-Znext-solver`)
 - rust-lang#139931 (bootstrap: enable zlib for LLVM for Windows GNU)
 - rust-lang#139935 (Upgrade to `rustc-rayon-core` 0.5.1)
 - rust-lang#139943 (rustdoc: Support inlined cross-crate re-exported trait aliases)
 - rust-lang#139961 (Two `rustc_const_eval` cleanups)
 - rust-lang#139962 (opt-dist: add a flag for running tests)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit d2db1c1 into rust-lang:master Apr 17, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone Apr 17, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 17, 2025
Rollup merge of rust-lang#139850 - xizheyin:issue-138698, r=jieyouxu

Hide unstable print kinds within emit_unknown_print_request_help in stable channel

Fixes rust-lang#138698

We need to get the channel from `matches`. However, since `matches`(Line 1169) is constructed after `rustc_optgroups` (Line1165, where `RustcOptGroup::value_hint` is generated, i.e. what `rustc --print print` prints), I've left it unchanged here for now.

https://github.com/rust-lang/rust/blob/2da29dbe8fe23df1c7c4ab1d8740ca3c32b15526/compiler/rustc_driver_impl/src/lib.rs#L1161-L1169

There is actually a way to manually parse the `--crate-name` parameter, but I'm afraid that's an unorthodox practice. So I conservatively just modified `emit_unknown_print_request_help` to print different parameters depending on whether they are nightly or not when passing the error parameter.

r? ```@jieyouxu```
@xizheyin xizheyin deleted the issue-138698 branch April 22, 2025 04:10
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.

rustc book: Outdated parameters for --print
5 participants