Skip to content

Commit 320fdaa

Browse files
committed
add EDITIONS_NAME_LIST, make edition tracked, enforce that only stable editions are allowed to be used on non-nightly builds
1 parent 51f5110 commit 320fdaa

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

src/librustc/session/config.rs

+18-9
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use middle::cstore;
3030

3131
use syntax::ast::{self, IntTy, UintTy};
3232
use syntax::codemap::{FileName, FilePathMapping};
33-
use syntax::edition::{Edition, ALL_EDITIONS, DEFAULT_EDITION};
33+
use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
3434
use syntax::parse::token;
3535
use syntax::parse;
3636
use syntax::symbol::Symbol;
@@ -412,7 +412,7 @@ top_level_options!(
412412

413413
// Remap source path prefixes in all output (messages, object files, debug, etc)
414414
remap_path_prefix: Vec<(PathBuf, PathBuf)> [UNTRACKED],
415-
edition: Edition [UNTRACKED],
415+
edition: Edition [TRACKED],
416416
}
417417
);
418418

@@ -1643,7 +1643,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
16431643
"",
16441644
"edition",
16451645
"Specify which edition of the compiler to use when compiling code.",
1646-
&edition_name_list(),
1646+
EDITION_NAME_LIST,
16471647
),
16481648
opt::multi_s(
16491649
"",
@@ -1712,14 +1712,26 @@ pub fn build_session_options_and_crate_config(
17121712
&format!(
17131713
"argument for --edition must be one of: \
17141714
{}. (instead was `{}`)",
1715-
edition_name_list(),
1715+
EDITION_NAME_LIST,
17161716
arg
17171717
),
17181718
),
17191719
}
17201720
None => DEFAULT_EDITION,
17211721
};
17221722

1723+
if !edition.is_stable() && !nightly_options::is_nightly_build() {
1724+
early_error(
1725+
ErrorOutputType::default(),
1726+
&format!(
1727+
"Edition {} is unstable an only\
1728+
available for nightly builds of rustc.",
1729+
edition,
1730+
)
1731+
)
1732+
}
1733+
1734+
17231735
// We need the opts_present check because the driver will send us Matches
17241736
// with only stable options if no unstable options are used. Since error-format
17251737
// is unstable, it will not be present. We have to use opts_present not
@@ -2311,6 +2323,7 @@ mod dep_tracking {
23112323
use syntax::feature_gate::UnstableFeatures;
23122324
use rustc_back::{PanicStrategy, RelroLevel};
23132325
use rustc_back::target::TargetTriple;
2326+
use syntax::edition::Edition;
23142327

23152328
pub trait DepTrackingHash {
23162329
fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType);
@@ -2370,6 +2383,7 @@ mod dep_tracking {
23702383
impl_dep_tracking_hash_via_hash!(Sanitizer);
23712384
impl_dep_tracking_hash_via_hash!(Option<Sanitizer>);
23722385
impl_dep_tracking_hash_via_hash!(TargetTriple);
2386+
impl_dep_tracking_hash_via_hash!(Edition);
23732387

23742388
impl_dep_tracking_hash_for_sortable_vec_of!(String);
23752389
impl_dep_tracking_hash_for_sortable_vec_of!(PathBuf);
@@ -2427,11 +2441,6 @@ mod dep_tracking {
24272441
}
24282442
}
24292443

2430-
pub fn edition_name_list() -> String {
2431-
let names: Vec<String> = ALL_EDITIONS.iter().map(|e| format!("{}", e)).collect();
2432-
names.join("|")
2433-
}
2434-
24352444
#[cfg(test)]
24362445
mod tests {
24372446
use errors;

src/librustc_driver/driver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ where
691691
krate,
692692
&sess.parse_sess,
693693
sess.opts.test,
694-
sess.opts.debugging_opts.edition,
694+
sess.edition(),
695695
);
696696
// these need to be set "early" so that expansion sees `quote` if enabled.
697697
sess.init_features(features);

src/libsyntax/edition.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@ pub enum Edition {
2424

2525
// when adding new editions, be sure to update:
2626
//
27-
// - the list in the `parse_edition` static in librustc::session::config
27+
// - Update the `ALL_EDITIONS` const
28+
// - Update the EDITION_NAME_LIST const
2829
// - add a `rust_####()` function to the session
2930
// - update the enum in Cargo's sources as well
3031
}
3132

3233
// must be in order from oldest to newest
3334
pub const ALL_EDITIONS: &[Edition] = &[Edition::Edition2015, Edition::Edition2018];
3435

36+
pub const EDITION_NAME_LIST: &'static str = "2015|2018";
37+
3538
pub const DEFAULT_EDITION: Edition = Edition::Edition2015;
3639

3740
impl fmt::Display for Edition {
@@ -58,6 +61,13 @@ impl Edition {
5861
Edition::Edition2018 => "rust_2018_preview",
5962
}
6063
}
64+
65+
pub fn is_stable(&self) -> bool {
66+
match *self {
67+
Edition::Edition2015 => true,
68+
Edition::Edition2018 => false,
69+
}
70+
}
6171
}
6272

6373
impl FromStr for Edition {

0 commit comments

Comments
 (0)