diff options
| author | Kurtis Nusbaum <kurtis@uber.com> | 2018-04-19 21:03:21 -0700 |
|---|---|---|
| committer | Kurtis Nusbaum <kurtis@uber.com> | 2018-04-19 21:03:21 -0700 |
| commit | 320fdaa9423ba2ae35c283707c1501a03dd511cf (patch) | |
| tree | 04b22eba29a5108a371b1b476278bd6412db7f82 | |
| parent | 51f51109ce8c3070ab186624c241216620942360 (diff) | |
| download | rust-320fdaa9423ba2ae35c283707c1501a03dd511cf.tar.gz rust-320fdaa9423ba2ae35c283707c1501a03dd511cf.zip | |
add EDITIONS_NAME_LIST, make edition tracked, enforce that only stable editions are allowed to be used on non-nightly builds
| -rw-r--r-- | src/librustc/session/config.rs | 27 | ||||
| -rw-r--r-- | src/librustc_driver/driver.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/edition.rs | 12 |
3 files changed, 30 insertions, 11 deletions
diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 2d0b4eecf63..aac1c2fc02b 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -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; diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index f8c0289cc98..2c781fda4ed 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -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); diff --git a/src/libsyntax/edition.rs b/src/libsyntax/edition.rs index 4c1d52d7b07..3fc1c279f5a 100644 --- a/src/libsyntax/edition.rs +++ b/src/libsyntax/edition.rs @@ -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 { |
