Skip to content

Commit cfe0033

Browse files
committed
--print option to list available feature gates
The option is only made available on nightly builds, for the obvious reason. While we're here, also prevent the unstable `target-spec-json` (tracking issue rust-lang#38338) from showing up in the --help on stable builds (although the way in which we accomplish this is slightly clumsy for lifetime reasons, as noted in the FIXME). We make REMOVED_FEATURES, ACCEPTED_FEATURES, &c. public for consistency, even though the functionality at issue only needs ACTIVE_FEATURES. The UI test will add a little bit of friction for future feature developers, but it's better than under-testing. Resolves rust-lang#38768.
1 parent cbf5d39 commit cfe0033

File tree

5 files changed

+185
-9
lines changed

5 files changed

+185
-9
lines changed

src/librustc/session/config.rs

+27-4
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ pub enum PrintRequest {
369369
CodeModels,
370370
TargetSpec,
371371
NativeStaticLibs,
372+
UnstableFeatures,
372373
}
373374

374375
pub enum Input {
@@ -1306,6 +1307,17 @@ mod opt {
13061307
/// including metadata for each option, such as whether the option is
13071308
/// part of the stable long-term interface for rustc.
13081309
pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
1310+
// FIXME: unfortunately, we need to hardcode these nightly vs. stable
1311+
// option value listings separately (rather than, say, plumbing in the
1312+
// extra nightly values with `format!`) because the `opt` interface
1313+
// requires a static lifetime
1314+
let stable_print_options = "[crate-name|file-names|sysroot|cfg|target-list|\
1315+
target-cpus|target-features|relocation-models|\
1316+
code-models|native-static-libs]";
1317+
let nightly_print_options = "[crate-name|file-names|sysroot|cfg|target-list|\
1318+
target-cpus|target-features|relocation-models|\
1319+
code-models|native-static-libs|target-spec-json|\
1320+
unstable-features]";
13091321
vec![
13101322
opt::flag_s("h", "help", "Display this message"),
13111323
opt::multi_s("", "cfg", "Configure the compilation environment", "SPEC"),
@@ -1325,10 +1337,12 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
13251337
the compiler to emit",
13261338
"[asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]"),
13271339
opt::multi_s("", "print", "Comma separated list of compiler information to \
1328-
print on stdout",
1329-
"[crate-name|file-names|sysroot|cfg|target-list|\
1330-
target-cpus|target-features|relocation-models|\
1331-
code-models|target-spec-json|native-static-libs]"),
1340+
print on stdout",
1341+
if nightly_options::is_nightly_build() {
1342+
nightly_print_options
1343+
} else {
1344+
stable_print_options
1345+
}),
13321346
opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"),
13331347
opt::flagmulti_s("O", "", "Equivalent to -C opt-level=2"),
13341348
opt::opt_s("o", "", "Write output to <filename>", "FILENAME"),
@@ -1679,6 +1693,15 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
16791693
enable the target-spec-json print option"));
16801694
}
16811695
},
1696+
"unstable-features" => {
1697+
if nightly_options::is_nightly_build() {
1698+
PrintRequest::UnstableFeatures
1699+
} else {
1700+
early_error(error_format,
1701+
&format!("unstable features require a nightly \
1702+
build of the compiler"));
1703+
}
1704+
},
16821705
req => {
16831706
early_error(error_format, &format!("unknown print request `{}`", req))
16841707
}

src/librustc_driver/lib.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ use std::thread;
9696

9797
use syntax::ast;
9898
use syntax::codemap::{CodeMap, FileLoader, RealFileLoader};
99-
use syntax::feature_gate::{GatedCfg, UnstableFeatures};
99+
use syntax::feature_gate::{ACTIVE_FEATURES, GatedCfg, UnstableFeatures};
100100
use syntax::parse::{self, PResult};
101101
use syntax_pos::{DUMMY_SP, MultiSpan};
102102

@@ -801,6 +801,38 @@ impl RustcDefaultCalls {
801801
PrintRequest::NativeStaticLibs => {
802802
println!("Native static libs can be printed only during linking");
803803
}
804+
PrintRequest::UnstableFeatures => {
805+
let (feat_width, ver_width, iss_width) = ACTIVE_FEATURES.iter()
806+
.map(|&(feat, ver, iss_maybe, _)| {
807+
(feat.len(),
808+
ver.len(),
809+
iss_maybe.map(|no| no.to_string().len()).unwrap_or(1))
810+
})
811+
.fold((7, 7, 5), // lengths of col. headings: "feature", "version", "issue"
812+
|max_widths, feat_widths| {
813+
(max(max_widths.0, feat_widths.0),
814+
max(max_widths.1, feat_widths.1),
815+
max(max_widths.2, feat_widths.2))
816+
});
817+
println!("| {0:feat_width$} | {1:ver_width$} | {2:iss_width$} |",
818+
"feature", "version", "issue",
819+
feat_width = feat_width,
820+
ver_width = ver_width,
821+
iss_width = iss_width);
822+
println!("{:->total_width$}", "",
823+
// `+ 10` is for ` | ` column borders: 2 + 3 + 3 + 2
824+
total_width = feat_width + ver_width + iss_width + 10);
825+
let mut features = ACTIVE_FEATURES.to_vec();
826+
features.sort_by_key(|&f| f.0);
827+
for &(feature, version, issue_maybe, _) in &features {
828+
println!("| {0:feat_width$} | {1:>ver_width$} | {2:>iss_width$} |",
829+
feature, version,
830+
issue_maybe.map(|no| no.to_string()).unwrap_or("—".to_owned()),
831+
feat_width = feat_width,
832+
ver_width = ver_width,
833+
iss_width = iss_width);
834+
}
835+
}
804836
}
805837
}
806838
return Compilation::Stop;

src/libsyntax/feature_gate.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ macro_rules! declare_features {
5858
($((active, $feature: ident, $ver: expr, $issue: expr),)+) => {
5959
/// Represents active features that are currently being implemented or
6060
/// currently being considered for addition/removal.
61-
const ACTIVE_FEATURES:
61+
pub const ACTIVE_FEATURES:
6262
&'static [(&'static str, &'static str, Option<u32>, fn(&mut Features, Span))] =
6363
&[$((stringify!($feature), $ver, $issue, set!($feature))),+];
6464

@@ -84,21 +84,21 @@ macro_rules! declare_features {
8484

8585
($((removed, $feature: ident, $ver: expr, $issue: expr),)+) => {
8686
/// Represents unstable features which have since been removed (it was once Active)
87-
const REMOVED_FEATURES: &'static [(&'static str, &'static str, Option<u32>)] = &[
87+
pub const REMOVED_FEATURES: &'static [(&'static str, &'static str, Option<u32>)] = &[
8888
$((stringify!($feature), $ver, $issue)),+
8989
];
9090
};
9191

9292
($((stable_removed, $feature: ident, $ver: expr, $issue: expr),)+) => {
9393
/// Represents stable features which have since been removed (it was once Accepted)
94-
const STABLE_REMOVED_FEATURES: &'static [(&'static str, &'static str, Option<u32>)] = &[
94+
pub const STABLE_REMOVED_FEATURES: &'static [(&'static str, &'static str, Option<u32>)] = &[
9595
$((stringify!($feature), $ver, $issue)),+
9696
];
9797
};
9898

9999
($((accepted, $feature: ident, $ver: expr, $issue: expr),)+) => {
100100
/// Those language feature has since been Accepted (it was once Active)
101-
const ACCEPTED_FEATURES: &'static [(&'static str, &'static str, Option<u32>)] = &[
101+
pub const ACCEPTED_FEATURES: &'static [(&'static str, &'static str, Option<u32>)] = &[
102102
$((stringify!($feature), $ver, $issue)),+
103103
];
104104
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: --print unstable-features
12+
13+
fn main() {}
+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
| feature | version | issue |
2+
-----------------------------------------------------
3+
| abi_msp430_interrupt | 1.16.0 | 38487 |
4+
| abi_ptx | 1.15.0 | — |
5+
| abi_sysv64 | 1.13.0 | 36167 |
6+
| abi_thiscall | 1.19.0 | — |
7+
| abi_unadjusted | 1.16.0 | — |
8+
| abi_vectorcall | 1.7.0 | — |
9+
| abi_x86_interrupt | 1.17.0 | 40180 |
10+
| advanced_slice_patterns | 1.0.0 | 23121 |
11+
| allocator_internals | 1.20.0 | — |
12+
| allow_fail | 1.19.0 | 42219 |
13+
| allow_internal_unsafe | 1.0.0 | — |
14+
| allow_internal_unstable | 1.0.0 | — |
15+
| asm | 1.0.0 | 29722 |
16+
| associated_type_defaults | 1.2.0 | 29661 |
17+
| attr_literals | 1.13.0 | 34981 |
18+
| box_patterns | 1.0.0 | 29641 |
19+
| box_syntax | 1.0.0 | 27779 |
20+
| catch_expr | 1.17.0 | 31436 |
21+
| cfg_target_feature | 1.4.0 | 29717 |
22+
| cfg_target_has_atomic | 1.9.0 | 32976 |
23+
| cfg_target_thread_local | 1.7.0 | 29594 |
24+
| cfg_target_vendor | 1.5.0 | 29718 |
25+
| clone_closures | 1.22.0 | 44490 |
26+
| compiler_builtins | 1.13.0 | — |
27+
| concat_idents | 1.0.0 | 29599 |
28+
| conservative_impl_trait | 1.12.0 | 34511 |
29+
| const_fn | 1.2.0 | 24111 |
30+
| const_indexing | 1.4.0 | 29947 |
31+
| copy_closures | 1.22.0 | 44490 |
32+
| custom_attribute | 1.0.0 | 29642 |
33+
| custom_derive | 1.0.0 | 29644 |
34+
| decl_macro | 1.17.0 | 39412 |
35+
| default_type_parameter_fallback | 1.3.0 | 27336 |
36+
| doc_cfg | 1.21.0 | 43781 |
37+
| doc_masked | 1.21.0 | 44027 |
38+
| dotdoteq_in_patterns | 1.22.0 | 28237 |
39+
| dropck_eyepatch | 1.10.0 | 34761 |
40+
| dropck_parametricity | 1.3.0 | 28498 |
41+
| exclusive_range_pattern | 1.11.0 | 37854 |
42+
| fn_must_use | 1.21.0 | 43302 |
43+
| fundamental | 1.0.0 | 29635 |
44+
| generators | 1.21.0 | — |
45+
| generic_param_attrs | 1.11.0 | 34761 |
46+
| global_allocator | 1.20.0 | — |
47+
| global_asm | 1.18.0 | 35119 |
48+
| i128_type | 1.16.0 | 35118 |
49+
| inclusive_range_syntax | 1.7.0 | 28237 |
50+
| intrinsics | 1.0.0 | — |
51+
| lang_items | 1.0.0 | — |
52+
| link_args | 1.0.0 | 29596 |
53+
| link_cfg | 1.14.0 | 37406 |
54+
| link_llvm_intrinsics | 1.0.0 | 29602 |
55+
| linkage | 1.0.0 | 29603 |
56+
| log_syntax | 1.0.0 | 29598 |
57+
| macro_reexport | 1.0.0 | 29638 |
58+
| macro_vis_matcher | 1.18.0 | 41022 |
59+
| main | 1.0.0 | 29634 |
60+
| match_beginning_vert | 1.21.0 | 44101 |
61+
| match_default_bindings | 1.22.0 | 42640 |
62+
| naked_functions | 1.9.0 | 32408 |
63+
| needs_allocator | 1.4.0 | 27389 |
64+
| needs_panic_runtime | 1.10.0 | 32837 |
65+
| never_type | 1.13.0 | 35121 |
66+
| no_core | 1.3.0 | 29639 |
67+
| no_debug | 1.5.0 | 29721 |
68+
| non_ascii_idents | 1.0.0 | 28979 |
69+
| omit_gdb_pretty_printer_section | 1.5.0 | — |
70+
| on_unimplemented | 1.0.0 | 29628 |
71+
| optin_builtin_traits | 1.0.0 | 13231 |
72+
| overlapping_marker_traits | 1.18.0 | 29864 |
73+
| panic_runtime | 1.10.0 | 32837 |
74+
| placement_in_syntax | 1.0.0 | 27779 |
75+
| platform_intrinsics | 1.4.0 | 27731 |
76+
| plugin | 1.0.0 | 29597 |
77+
| plugin_registrar | 1.0.0 | 29597 |
78+
| prelude_import | 1.2.0 | — |
79+
| proc_macro | 1.16.0 | 38356 |
80+
| profiler_runtime | 1.18.0 | — |
81+
| quote | 1.0.0 | 29601 |
82+
| repr128 | 1.16.0 | 35118 |
83+
| repr_align | 1.17.0 | 33626 |
84+
| repr_simd | 1.4.0 | 27731 |
85+
| rustc_attrs | 1.0.0 | 29642 |
86+
| rustc_const_unstable | 1.0.0 | — |
87+
| rustc_diagnostic_macros | 1.0.0 | — |
88+
| sanitizer_runtime | 1.17.0 | — |
89+
| simd | 1.0.0 | 27731 |
90+
| simd_ffi | 1.0.0 | 27731 |
91+
| slice_patterns | 1.0.0 | 23121 |
92+
| specialization | 1.7.0 | 31844 |
93+
| staged_api | 1.0.0 | — |
94+
| start | 1.0.0 | 29633 |
95+
| static_nobundle | 1.16.0 | 37403 |
96+
| stmt_expr_attributes | 1.6.0 | 15701 |
97+
| structural_match | 1.8.0 | 31434 |
98+
| target_feature | 1.15.0 | — |
99+
| thread_local | 1.0.0 | 29594 |
100+
| trace_macros | 1.0.0 | 29598 |
101+
| type_ascription | 1.6.0 | 23416 |
102+
| unboxed_closures | 1.0.0 | 29625 |
103+
| underscore_lifetimes | 1.22.0 | 44524 |
104+
| unsized_tuple_coercion | 1.20.0 | 42877 |
105+
| untagged_unions | 1.13.0 | 32836 |
106+
| unwind_attributes | 1.4.0 | — |
107+
| use_extern_macros | 1.15.0 | 35896 |
108+
| used | 1.18.0 | 40289 |

0 commit comments

Comments
 (0)