Skip to content

Commit 2cff123

Browse files
committed
Add -Zepoch
1 parent 9af374a commit 2cff123

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

src/librustc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#![feature(macro_vis_matcher)]
5959
#![feature(match_default_bindings)]
6060
#![feature(never_type)]
61+
#![feature(non_exhaustive)]
6162
#![feature(nonzero)]
6263
#![feature(quote)]
6364
#![feature(refcell_replace_swap)]

src/librustc/session/config.rs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,31 @@ pub enum OutputType {
112112
DepInfo,
113113
}
114114

115+
/// The epoch of the compiler (RFC 2052)
116+
#[derive(Clone, Copy, Hash, PartialOrd, Ord, Eq, PartialEq)]
117+
#[non_exhaustive]
118+
pub enum Epoch {
119+
// epochs must be kept in order, newest to oldest
120+
121+
/// The 2015 epoch
122+
Epoch2015,
123+
/// The 2018 epoch
124+
Epoch2018,
125+
126+
// when adding new epochs, be sure to update:
127+
//
128+
// - the list in the `parse_epoch` static
129+
// - the match in the `parse_epoch` function
130+
// - add a `rust_####()` function to the session
131+
// - update the enum in Cargo's sources as well
132+
//
133+
// When -Zepoch becomes --epoch, there will
134+
// also be a check for the epoch being nightly-only
135+
// somewhere. That will need to be updated
136+
// whenever we're stabilizing/introducing a new epoch
137+
// as well as changing the default Cargo template.
138+
}
139+
115140
impl_stable_hash_for!(enum self::OutputType {
116141
Bitcode,
117142
Assembly,
@@ -802,11 +827,13 @@ macro_rules! options {
802827
Some("`string` or `string=string`");
803828
pub const parse_lto: Option<&'static str> =
804829
Some("one of `thin`, `fat`, or omitted");
830+
pub const parse_epoch: Option<&'static str> =
831+
Some("one of: `2015`, `2018`");
805832
}
806833

807834
#[allow(dead_code)]
808835
mod $mod_set {
809-
use super::{$struct_name, Passes, SomePasses, AllPasses, Sanitizer, Lto};
836+
use super::{$struct_name, Passes, SomePasses, AllPasses, Sanitizer, Lto, Epoch};
810837
use rustc_back::{LinkerFlavor, PanicStrategy, RelroLevel};
811838
use std::path::PathBuf;
812839

@@ -1010,6 +1037,15 @@ macro_rules! options {
10101037
};
10111038
true
10121039
}
1040+
1041+
fn parse_epoch(slot: &mut Epoch, v: Option<&str>) -> bool {
1042+
match v {
1043+
Some("2015") => *slot = Epoch::Epoch2015,
1044+
Some("2018") => *slot = Epoch::Epoch2018,
1045+
_ => return false,
1046+
}
1047+
true
1048+
}
10131049
}
10141050
) }
10151051

@@ -1297,6 +1333,10 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12971333
`everybody_loops` (all function bodies replaced with `loop {}`),
12981334
`hir` (the HIR), `hir,identified`, or
12991335
`hir,typed` (HIR with types for each node)."),
1336+
epoch: Epoch = (Epoch::Epoch2015, parse_epoch, [TRACKED],
1337+
"The epoch to build Rust with. Newer epochs may include features
1338+
that require breaking changes. The default epoch is 2015 (the first
1339+
epoch). Crates compiled with different epochs can be linked together."),
13001340
}
13011341

13021342
pub fn default_lib_output() -> CrateType {
@@ -2088,7 +2128,7 @@ mod dep_tracking {
20882128
use std::path::PathBuf;
20892129
use std::collections::hash_map::DefaultHasher;
20902130
use super::{Passes, CrateType, OptLevel, DebugInfoLevel, Lto,
2091-
OutputTypes, Externs, ErrorOutputType, Sanitizer};
2131+
OutputTypes, Externs, ErrorOutputType, Sanitizer, Epoch};
20922132
use syntax::feature_gate::UnstableFeatures;
20932133
use rustc_back::{PanicStrategy, RelroLevel};
20942134

@@ -2150,6 +2190,7 @@ mod dep_tracking {
21502190
impl_dep_tracking_hash_via_hash!(cstore::NativeLibraryKind);
21512191
impl_dep_tracking_hash_via_hash!(Sanitizer);
21522192
impl_dep_tracking_hash_via_hash!(Option<Sanitizer>);
2193+
impl_dep_tracking_hash_via_hash!(Epoch);
21532194

21542195
impl_dep_tracking_hash_for_sortable_vec_of!(String);
21552196
impl_dep_tracking_hash_for_sortable_vec_of!(PathBuf);

src/librustc/session/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use lint;
1919
use middle::allocator::AllocatorKind;
2020
use middle::dependency_format;
2121
use session::search_paths::PathKind;
22-
use session::config::{BorrowckMode, DebugInfoLevel, OutputType};
22+
use session::config::{BorrowckMode, DebugInfoLevel, OutputType, Epoch};
2323
use ty::tls;
2424
use util::nodemap::{FxHashMap, FxHashSet};
2525
use util::common::{duration_to_secs_str, ErrorReported};
@@ -864,6 +864,11 @@ impl Session {
864864
pub fn teach(&self, code: &DiagnosticId) -> bool {
865865
self.opts.debugging_opts.teach && !self.parse_sess.span_diagnostic.code_emitted(code)
866866
}
867+
868+
/// Are we allowed to use features from the Rust 2018 epoch?
869+
pub fn rust_2018(&self) -> bool {
870+
self.opts.debugging_opts.epoch >= Epoch::Epoch2018
871+
}
867872
}
868873

869874
pub fn build_session(sopts: config::Options,

0 commit comments

Comments
 (0)