Skip to content

rustc book: Outdated parameters for --print #138698

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

Closed
xizheyin opened this issue Mar 19, 2025 · 6 comments · Fixed by #139850
Closed

rustc book: Outdated parameters for --print #138698

xizheyin opened this issue Mar 19, 2025 · 6 comments · Fixed by #139850
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools A-print-requests Area: print requests (`--print=...`) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@xizheyin
Copy link
Contributor

Location

https://doc.rust-lang.org/rustc/command-line-arguments.html#--print-print-compiler-information

Summary

When I use rustc ---print, it reports

       Usage:
           --print [all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models]

But some of them can not be found in the corresponding chapter in rustc book. And the order in which the parameters are arranged needs to be adjusted.

@xizheyin xizheyin added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Mar 19, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 19, 2025
@Urgau
Copy link
Member

Urgau commented Mar 19, 2025

But some of them can not be found in the corresponding chapter in rustc book

That's because some of them are unstable.

And the order in which the parameters are arranged needs to be adjusted.

What do you mean by "adjusted"?

@Urgau Urgau added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-print-requests Area: print requests (`--print=...`) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 19, 2025
@ChrisDenton
Copy link
Member

We should probably try to hide the unstable options on stable? Although that might be more difficult to do since I don't think stable/unstable is easy to query.

@xizheyin
Copy link
Contributor Author

What do you mean by "adjusted"?

Alphabetical order may be more beautiful.

We should probably try to hide the unstable options on stable?

I think so, too, otherwise it may cause confusion.Is it possible to mark as unstable?

@jieyouxu
Copy link
Member

jieyouxu commented Mar 19, 2025

It should be possible to hide the unstable options on stable due to how print requests are handed: see

let kind = if let Some((print_name, print_kind)) =
PRINT_KINDS.iter().find(|&&(name, _)| name == req)
{
check_print_request_stability(early_dcx, unstable_opts, (print_name, *print_kind));
*print_kind
} else {
emit_unknown_print_request_help(early_dcx, req)
};

Probably just pull out the "what is considered unstable print request" logic

fn check_print_request_stability(
early_dcx: &EarlyDiagCtxt,
unstable_opts: &UnstableOptions,
(print_name, print_kind): (&str, PrintKind),
) {
match print_kind {
PrintKind::AllTargetSpecsJson | PrintKind::CheckCfg | PrintKind::TargetSpecJson
if !unstable_opts.unstable_options =>
{
early_dcx.early_fatal(format!(
"the `-Z unstable-options` flag must also be passed to enable the `{print_name}` \
print option"
));
}
_ => {}
}
}

(There might be a bit more nuance to this, I haven't tried implementing it)

@xizheyin
Copy link
Contributor Author

xizheyin commented Apr 7, 2025

jieyou, are you going to do this? If not, I can give it a try. @jieyouxu

@jieyouxu
Copy link
Member

jieyouxu commented Apr 7, 2025

I am not working on this, no.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue 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 issue 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 bors closed this as completed in d2db1c1 Apr 17, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue 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```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools A-print-requests Area: print requests (`--print=...`) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants