Skip to content

Commit f02dd16

Browse files
committed
Add run-make test print-in-stable-or-unstable-channel
Signed-off-by: xizheyin <[email protected]>
1 parent 0df1c83 commit f02dd16

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

compiler/rustc_session/src/config.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2094,15 +2094,15 @@ fn check_print_request_stability(
20942094
unstable_opts: &UnstableOptions,
20952095
(print_name, print_kind): (&str, PrintKind),
20962096
) {
2097-
if !is_print_request_stability(print_kind) && !unstable_opts.unstable_options {
2097+
if !is_print_request_stable(print_kind) && !unstable_opts.unstable_options {
20982098
early_dcx.early_fatal(format!(
20992099
"the `-Z unstable-options` flag must also be passed to enable the `{print_name}` \
21002100
print option"
21012101
));
21022102
}
21032103
}
21042104

2105-
fn is_print_request_stability(print_kind: PrintKind) -> bool {
2105+
fn is_print_request_stable(print_kind: PrintKind) -> bool {
21062106
match print_kind {
21072107
PrintKind::AllTargetSpecsJson
21082108
| PrintKind::CheckCfg
@@ -2118,7 +2118,7 @@ fn emit_unknown_print_request_help(early_dcx: &EarlyDiagCtxt, req: &str, is_nigh
21182118
.iter()
21192119
.filter_map(|(name, kind)| {
21202120
// If we're not on nightly, we don't want to print unstable options
2121-
if !is_nightly && !is_print_request_stability(*kind) {
2121+
if !is_nightly && !is_print_request_stable(*kind) {
21222122
None
21232123
} else {
21242124
Some(format!("`{name}`"))
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)