Skip to content

Commit afc11e0

Browse files
authored
Unrolled build for rust-lang#139850
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```
2 parents 883f9f7 + 8562110 commit afc11e0

File tree

5 files changed

+75
-12
lines changed

5 files changed

+75
-12
lines changed

compiler/rustc_session/src/config.rs

+25-12
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,8 @@ fn collect_print_requests(
20652065
check_print_request_stability(early_dcx, unstable_opts, (print_name, *print_kind));
20662066
*print_kind
20672067
} else {
2068-
emit_unknown_print_request_help(early_dcx, req)
2068+
let is_nightly = nightly_options::match_is_nightly_build(matches);
2069+
emit_unknown_print_request_help(early_dcx, req, is_nightly)
20692070
};
20702071

20712072
let out = out.unwrap_or(OutFileName::Stdout);
@@ -2089,25 +2090,37 @@ fn check_print_request_stability(
20892090
unstable_opts: &UnstableOptions,
20902091
(print_name, print_kind): (&str, PrintKind),
20912092
) {
2093+
if !is_print_request_stable(print_kind) && !unstable_opts.unstable_options {
2094+
early_dcx.early_fatal(format!(
2095+
"the `-Z unstable-options` flag must also be passed to enable the `{print_name}` \
2096+
print option"
2097+
));
2098+
}
2099+
}
2100+
2101+
fn is_print_request_stable(print_kind: PrintKind) -> bool {
20922102
match print_kind {
20932103
PrintKind::AllTargetSpecsJson
20942104
| PrintKind::CheckCfg
20952105
| PrintKind::CrateRootLintLevels
20962106
| PrintKind::SupportedCrateTypes
2097-
| PrintKind::TargetSpecJson
2098-
if !unstable_opts.unstable_options =>
2099-
{
2100-
early_dcx.early_fatal(format!(
2101-
"the `-Z unstable-options` flag must also be passed to enable the `{print_name}` \
2102-
print option"
2103-
));
2104-
}
2105-
_ => {}
2107+
| PrintKind::TargetSpecJson => false,
2108+
_ => true,
21062109
}
21072110
}
21082111

2109-
fn emit_unknown_print_request_help(early_dcx: &EarlyDiagCtxt, req: &str) -> ! {
2110-
let prints = PRINT_KINDS.iter().map(|(name, _)| format!("`{name}`")).collect::<Vec<_>>();
2112+
fn emit_unknown_print_request_help(early_dcx: &EarlyDiagCtxt, req: &str, is_nightly: bool) -> ! {
2113+
let prints = PRINT_KINDS
2114+
.iter()
2115+
.filter_map(|(name, kind)| {
2116+
// If we're not on nightly, we don't want to print unstable options
2117+
if !is_nightly && !is_print_request_stable(*kind) {
2118+
None
2119+
} else {
2120+
Some(format!("`{name}`"))
2121+
}
2122+
})
2123+
.collect::<Vec<_>>();
21112124
let prints = prints.join(", ");
21122125

21132126
let mut diag = early_dcx.early_struct_fatal(format!("unknown print request: `{req}`"));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@@ -1,5 +1,5 @@
2+
error: unknown print request: `xxx`
3+
|
4+
- = help: valid print requests are: `calling-conventions`, `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`, `tls-models`
5+
+ = help: valid print requests are: `all-target-specs-json`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `crate-root-lint-levels`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `tls-models`
6+
= help: for more information, see the rustc book: https://doc.rust-lang.org/rustc/command-line-arguments.html#--print-print-compiler-information
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//! Check that unstable print requests are omitted from help if compiler is in stable channel.
2+
//!
3+
//! Issue: <https://github.com/rust-lang/rust/issues/138698>
4+
use run_make_support::{diff, rustc, similar};
5+
6+
fn main() {
7+
let stable_invalid_print_request_help = rustc()
8+
.env("RUSTC_BOOTSTRAP", "-1")
9+
.cfg("force_stable")
10+
.print("xxx")
11+
.run_fail()
12+
.stderr_utf8();
13+
assert!(!stable_invalid_print_request_help.contains("all-target-specs-json"));
14+
diff()
15+
.expected_file("stable-invalid-print-request-help.err")
16+
.actual_text("stable_invalid_print_request_help", &stable_invalid_print_request_help)
17+
.run();
18+
19+
let unstable_invalid_print_request_help = rustc().print("xxx").run_fail().stderr_utf8();
20+
assert!(unstable_invalid_print_request_help.contains("all-target-specs-json"));
21+
diff()
22+
.expected_file("unstable-invalid-print-request-help.err")
23+
.actual_text("unstable_invalid_print_request_help", &unstable_invalid_print_request_help)
24+
.run();
25+
26+
let help_diff = similar::TextDiff::from_lines(
27+
&stable_invalid_print_request_help,
28+
&unstable_invalid_print_request_help,
29+
)
30+
.unified_diff()
31+
.to_string();
32+
diff().expected_file("help-diff.diff").actual_text("help_diff", help_diff).run();
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: unknown print request: `xxx`
2+
|
3+
= help: valid print requests are: `calling-conventions`, `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`, `tls-models`
4+
= help: for more information, see the rustc book: https://doc.rust-lang.org/rustc/command-line-arguments.html#--print-print-compiler-information
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: unknown print request: `xxx`
2+
|
3+
= help: valid print requests are: `all-target-specs-json`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `crate-root-lint-levels`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `tls-models`
4+
= help: for more information, see the rustc book: https://doc.rust-lang.org/rustc/command-line-arguments.html#--print-print-compiler-information
5+

0 commit comments

Comments
 (0)