add EDITIONS_NAME_LIST, make edition tracked, enforce that only stable editions are allowed to be used on non-nightly builds

This commit is contained in:
Kurtis Nusbaum 2018-04-19 21:03:21 -07:00
parent 51f51109ce
commit 320fdaa942
3 changed files with 30 additions and 11 deletions

View file

@ -30,7 +30,7 @@ use middle::cstore;
use syntax::ast::{self, IntTy, UintTy};
use syntax::codemap::{FileName, FilePathMapping};
use syntax::edition::{Edition, ALL_EDITIONS, DEFAULT_EDITION};
use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
use syntax::parse::token;
use syntax::parse;
use syntax::symbol::Symbol;
@ -412,7 +412,7 @@ top_level_options!(
// Remap source path prefixes in all output (messages, object files, debug, etc)
remap_path_prefix: Vec<(PathBuf, PathBuf)> [UNTRACKED],
edition: Edition [UNTRACKED],
edition: Edition [TRACKED],
}
);
@ -1643,7 +1643,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
"",
"edition",
"Specify which edition of the compiler to use when compiling code.",
&edition_name_list(),
EDITION_NAME_LIST,
),
opt::multi_s(
"",
@ -1712,7 +1712,7 @@ pub fn build_session_options_and_crate_config(
&format!(
"argument for --edition must be one of: \
{}. (instead was `{}`)",
edition_name_list(),
EDITION_NAME_LIST,
arg
),
),
@ -1720,6 +1720,18 @@ pub fn build_session_options_and_crate_config(
None => DEFAULT_EDITION,
};
if !edition.is_stable() && !nightly_options::is_nightly_build() {
early_error(
ErrorOutputType::default(),
&format!(
"Edition {} is unstable an only\
available for nightly builds of rustc.",
edition,
)
)
}
// We need the opts_present check because the driver will send us Matches
// with only stable options if no unstable options are used. Since error-format
// is unstable, it will not be present. We have to use opts_present not
@ -2311,6 +2323,7 @@ mod dep_tracking {
use syntax::feature_gate::UnstableFeatures;
use rustc_back::{PanicStrategy, RelroLevel};
use rustc_back::target::TargetTriple;
use syntax::edition::Edition;
pub trait DepTrackingHash {
fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType);
@ -2370,6 +2383,7 @@ mod dep_tracking {
impl_dep_tracking_hash_via_hash!(Sanitizer);
impl_dep_tracking_hash_via_hash!(Option<Sanitizer>);
impl_dep_tracking_hash_via_hash!(TargetTriple);
impl_dep_tracking_hash_via_hash!(Edition);
impl_dep_tracking_hash_for_sortable_vec_of!(String);
impl_dep_tracking_hash_for_sortable_vec_of!(PathBuf);
@ -2427,11 +2441,6 @@ mod dep_tracking {
}
}
pub fn edition_name_list() -> String {
let names: Vec<String> = ALL_EDITIONS.iter().map(|e| format!("{}", e)).collect();
names.join("|")
}
#[cfg(test)]
mod tests {
use errors;

View file

@ -691,7 +691,7 @@ where
krate,
&sess.parse_sess,
sess.opts.test,
sess.opts.debugging_opts.edition,
sess.edition(),
);
// these need to be set "early" so that expansion sees `quote` if enabled.
sess.init_features(features);

View file

@ -24,7 +24,8 @@ pub enum Edition {
// when adding new editions, be sure to update:
//
// - the list in the `parse_edition` static in librustc::session::config
// - Update the `ALL_EDITIONS` const
// - Update the EDITION_NAME_LIST const
// - add a `rust_####()` function to the session
// - update the enum in Cargo's sources as well
}
@ -32,6 +33,8 @@ pub enum Edition {
// must be in order from oldest to newest
pub const ALL_EDITIONS: &[Edition] = &[Edition::Edition2015, Edition::Edition2018];
pub const EDITION_NAME_LIST: &'static str = "2015|2018";
pub const DEFAULT_EDITION: Edition = Edition::Edition2015;
impl fmt::Display for Edition {
@ -58,6 +61,13 @@ impl Edition {
Edition::Edition2018 => "rust_2018_preview",
}
}
pub fn is_stable(&self) -> bool {
match *self {
Edition::Edition2015 => true,
Edition::Edition2018 => false,
}
}
}
impl FromStr for Edition {