Skip to content

Commit ded701b

Browse files
Centralize nightly compiler flags handling
1 parent f34ae3f commit ded701b

File tree

4 files changed

+154
-157
lines changed

4 files changed

+154
-157
lines changed

src/librustc/session/config.rs

+85-21
Original file line numberDiff line numberDiff line change
@@ -785,12 +785,12 @@ impl RustcOptGroup {
785785
self.stability == OptionStability::Stable
786786
}
787787

788-
fn stable(g: getopts::OptGroup) -> RustcOptGroup {
788+
pub fn stable(g: getopts::OptGroup) -> RustcOptGroup {
789789
RustcOptGroup { opt_group: g, stability: OptionStability::Stable }
790790
}
791791

792792
#[allow(dead_code)] // currently we have no "truly unstable" options
793-
fn unstable(g: getopts::OptGroup) -> RustcOptGroup {
793+
pub fn unstable(g: getopts::OptGroup) -> RustcOptGroup {
794794
RustcOptGroup { opt_group: g, stability: OptionStability::Unstable }
795795
}
796796

@@ -926,33 +926,32 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
926926
pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
927927
let mut opts = rustc_short_optgroups();
928928
opts.extend_from_slice(&[
929-
opt::multi_s("", "extern", "Specify where an external rust library is \
930-
located",
931-
"NAME=PATH"),
929+
opt::multi_s("", "extern", "Specify where an external rust library is located",
930+
"NAME=PATH"),
932931
opt::opt_s("", "sysroot", "Override the system root", "PATH"),
933932
opt::multi_ubnr("Z", "", "Set internal debugging options", "FLAG"),
934933
opt::opt_ubnr("", "error-format",
935934
"How errors and other messages are produced",
936935
"human|json"),
937936
opt::opt_s("", "color", "Configure coloring of output:
938-
auto = colorize, if output goes to a tty (default);
939-
always = always colorize output;
940-
never = never colorize output", "auto|always|never"),
937+
auto = colorize, if output goes to a tty (default);
938+
always = always colorize output;
939+
never = never colorize output", "auto|always|never"),
941940

942941
opt::flagopt_ubnr("", "pretty",
943-
"Pretty-print the input instead of compiling;
944-
valid types are: `normal` (un-annotated source),
945-
`expanded` (crates expanded), or
946-
`expanded,identified` (fully parenthesized, AST nodes with IDs).",
947-
"TYPE"),
942+
"Pretty-print the input instead of compiling;
943+
valid types are: `normal` (un-annotated source),
944+
`expanded` (crates expanded), or
945+
`expanded,identified` (fully parenthesized, AST nodes with IDs).",
946+
"TYPE"),
948947
opt::flagopt_ubnr("", "unpretty",
949-
"Present the input source, unstable (and less-pretty) variants;
950-
valid types are any of the types for `--pretty`, as well as:
951-
`flowgraph=<nodeid>` (graphviz formatted flowgraph for node),
952-
`everybody_loops` (all function bodies replaced with `loop {}`),
953-
`hir` (the HIR), `hir,identified`, or
954-
`hir,typed` (HIR with types for each node).",
955-
"TYPE"),
948+
"Present the input source, unstable (and less-pretty) variants;
949+
valid types are any of the types for `--pretty`, as well as:
950+
`flowgraph=<nodeid>` (graphviz formatted flowgraph for node),
951+
`everybody_loops` (all function bodies replaced with `loop {}`),
952+
`hir` (the HIR), `hir,identified`, or
953+
`hir,typed` (HIR with types for each node).",
954+
"TYPE"),
956955

957956
// new options here should **not** use the `_ubnr` functions, all new
958957
// unstable options should use the short variants to indicate that they
@@ -1263,7 +1262,6 @@ pub fn get_unstable_features_setting() -> UnstableFeatures {
12631262
}
12641263

12651264
pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateType>, String> {
1266-
12671265
let mut crate_types: Vec<CrateType> = Vec::new();
12681266
for unparsed_crate_type in &list_list {
12691267
for part in unparsed_crate_type.split(',') {
@@ -1287,6 +1285,72 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
12871285
return Ok(crate_types);
12881286
}
12891287

1288+
pub mod nightly_options {
1289+
use getopts;
1290+
use syntax::feature_gate::UnstableFeatures;
1291+
use super::{ErrorOutputType, OptionStability, RustcOptGroup, get_unstable_features_setting};
1292+
use session::{early_error, early_warn};
1293+
1294+
pub fn is_unstable_enabled(matches: &getopts::Matches) -> bool {
1295+
is_nightly_build() && matches.opt_strs("Z").iter().any(|x| *x == "unstable-options")
1296+
}
1297+
1298+
fn is_nightly_build() -> bool {
1299+
match get_unstable_features_setting() {
1300+
UnstableFeatures::Allow | UnstableFeatures::Cheat => true,
1301+
_ => false,
1302+
}
1303+
}
1304+
1305+
pub fn check_nightly_options(matches: &getopts::Matches, flags: &[RustcOptGroup]) {
1306+
let has_z_unstable_option = matches.opt_strs("Z").iter().any(|x| *x == "unstable-options");
1307+
let really_allows_unstable_options = match get_unstable_features_setting() {
1308+
UnstableFeatures::Disallow => false,
1309+
_ => true,
1310+
};
1311+
1312+
for opt in flags.iter() {
1313+
if opt.stability == OptionStability::Stable {
1314+
continue
1315+
}
1316+
let opt_name = if opt.opt_group.long_name.is_empty() {
1317+
&opt.opt_group.short_name
1318+
} else {
1319+
&opt.opt_group.long_name
1320+
};
1321+
if !matches.opt_present(opt_name) {
1322+
continue
1323+
}
1324+
if opt_name != "Z" && !has_z_unstable_option {
1325+
early_error(ErrorOutputType::default(),
1326+
&format!("the `-Z unstable-options` flag must also be passed to enable \
1327+
the flag `{}`",
1328+
opt_name));
1329+
}
1330+
if really_allows_unstable_options {
1331+
continue
1332+
}
1333+
match opt.stability {
1334+
OptionStability::Unstable => {
1335+
let msg = format!("the option `{}` is only accepted on the \
1336+
nightly compiler", opt_name);
1337+
early_error(ErrorOutputType::default(), &msg);
1338+
}
1339+
OptionStability::UnstableButNotReally => {
1340+
let msg = format!("the option `{}` is is unstable and should \
1341+
only be used on the nightly compiler, but \
1342+
it is currently accepted for backwards \
1343+
compatibility; this will soon change, \
1344+
see issue #31847 for more details",
1345+
opt_name);
1346+
early_warn(ErrorOutputType::default(), &msg);
1347+
}
1348+
OptionStability::Stable => {}
1349+
}
1350+
}
1351+
}
1352+
}
1353+
12901354
impl fmt::Display for CrateType {
12911355
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
12921356
match *self {

src/librustc_driver/lib.rs

+4-49
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use rustc_save_analysis as save;
6868
use rustc_trans::back::link;
6969
use rustc::session::{config, Session, build_session, CompileResult};
7070
use rustc::session::config::{Input, PrintRequest, OutputType, ErrorOutputType};
71-
use rustc::session::config::{get_unstable_features_setting, OptionStability};
71+
use rustc::session::config::{get_unstable_features_setting, nightly_options};
7272
use rustc::middle::cstore::CrateStore;
7373
use rustc::lint::Lint;
7474
use rustc::lint;
@@ -89,7 +89,7 @@ use std::str;
8989
use std::sync::{Arc, Mutex};
9090
use std::thread;
9191

92-
use rustc::session::{early_error, early_warn};
92+
use rustc::session::early_error;
9393

9494
use syntax::ast;
9595
use syntax::parse::{self, PResult};
@@ -910,64 +910,19 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
910910
// (unstable option being used on stable)
911911
// * If we're a historically stable-but-should-be-unstable option then we
912912
// emit a warning that we're going to turn this into an error soon.
913-
let has_z_unstable_options = matches.opt_strs("Z")
914-
.iter()
915-
.any(|x| *x == "unstable-options");
916-
let really_allows_unstable_options = match get_unstable_features_setting() {
917-
UnstableFeatures::Disallow => false,
918-
_ => true,
919-
};
920-
for opt in config::rustc_optgroups() {
921-
if opt.stability == OptionStability::Stable {
922-
continue
923-
}
924-
let opt_name = if opt.opt_group.long_name.is_empty() {
925-
&opt.opt_group.short_name
926-
} else {
927-
&opt.opt_group.long_name
928-
};
929-
if !matches.opt_present(opt_name) {
930-
continue
931-
}
932-
if opt_name != "Z" && !has_z_unstable_options {
933-
let msg = format!("the `-Z unstable-options` flag must also be \
934-
passed to enable the flag `{}`", opt_name);
935-
early_error(ErrorOutputType::default(), &msg);
936-
}
937-
if really_allows_unstable_options {
938-
continue
939-
}
940-
match opt.stability {
941-
OptionStability::Unstable => {
942-
let msg = format!("the option `{}` is only accepted on the \
943-
nightly compiler", opt_name);
944-
early_error(ErrorOutputType::default(), &msg);
945-
}
946-
OptionStability::UnstableButNotReally => {
947-
let msg = format!("the option `{}` is is unstable and should \
948-
only be used on the nightly compiler, but \
949-
it is currently accepted for backwards \
950-
compatibility; this will soon change, \
951-
see issue #31847 for more details",
952-
opt_name);
953-
early_warn(ErrorOutputType::default(), &msg);
954-
}
955-
OptionStability::Stable => {}
956-
}
957-
}
913+
nightly_options::check_nightly_options(&matches, &config::rustc_optgroups());
958914

959915
if matches.opt_present("h") || matches.opt_present("help") {
960916
// Only show unstable options in --help if we *really* accept unstable
961917
// options, which catches the case where we got `-Z unstable-options` on
962918
// the stable channel of Rust which was accidentally allowed
963919
// historically.
964920
usage(matches.opt_present("verbose"),
965-
has_z_unstable_options && really_allows_unstable_options);
921+
nightly_options::is_unstable_enabled(&matches));
966922
return None;
967923
}
968924

969925
// Don't handle -W help here, because we might first load plugins.
970-
971926
let r = matches.opt_strs("Z");
972927
if r.iter().any(|x| *x == "help") {
973928
describe_debug_flags();

src/librustdoc/html/render.rs

-4
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,6 @@ pub fn run(mut krate: clean::Crate,
433433
krate: krate.name.clone(),
434434
playground_url: "".to_string(),
435435
},
436-
include_sources: true,
437-
local_sources: HashMap::new(),
438-
render_redirect_pages: false,
439-
issue_tracker_base_url: None,
440436
css_file_extension: css_file_extension,
441437
};
442438

0 commit comments

Comments
 (0)