@@ -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+
115140impl_stable_hash_for ! ( enum self :: OutputType {
116141 Bitcode ,
117142 Assembly ,
@@ -783,11 +808,13 @@ macro_rules! options {
783808 Some ( "`string` or `string=string`" ) ;
784809 pub const parse_lto: Option <& ' static str > =
785810 Some ( "one of `thin`, `fat`, or omitted" ) ;
811+ pub const parse_epoch: Option <& ' static str > =
812+ Some ( "one of: `2015`, `2018`" ) ;
786813 }
787814
788815 #[ allow( dead_code) ]
789816 mod $mod_set {
790- use super :: { $struct_name, Passes , SomePasses , AllPasses , Sanitizer , Lto } ;
817+ use super :: { $struct_name, Passes , SomePasses , AllPasses , Sanitizer , Lto , Epoch } ;
791818 use rustc_back:: { LinkerFlavor , PanicStrategy , RelroLevel } ;
792819 use std:: path:: PathBuf ;
793820
@@ -991,6 +1018,15 @@ macro_rules! options {
9911018 } ;
9921019 true
9931020 }
1021+
1022+ fn parse_epoch( slot: & mut Epoch , v: Option <& str >) -> bool {
1023+ match v {
1024+ Some ( "2015" ) => * slot = Epoch :: Epoch2015 ,
1025+ Some ( "2018" ) => * slot = Epoch :: Epoch2018 ,
1026+ _ => return false ,
1027+ }
1028+ true
1029+ }
9941030 }
9951031) }
9961032
@@ -1278,6 +1314,10 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12781314 `everybody_loops` (all function bodies replaced with `loop {}`),
12791315 `hir` (the HIR), `hir,identified`, or
12801316 `hir,typed` (HIR with types for each node)." ) ,
1317+ epoch: Epoch = ( Epoch :: Epoch2015 , parse_epoch, [ TRACKED ] ,
1318+ "The epoch to build Rust with. Newer epochs may include features
1319+ that require breaking changes. The default epoch is 2015 (the first
1320+ epoch). Crates compiled with different epochs can be linked together." ) ,
12811321}
12821322
12831323pub fn default_lib_output ( ) -> CrateType {
@@ -2069,7 +2109,7 @@ mod dep_tracking {
20692109 use std:: path:: PathBuf ;
20702110 use std:: collections:: hash_map:: DefaultHasher ;
20712111 use super :: { Passes , CrateType , OptLevel , DebugInfoLevel , Lto ,
2072- OutputTypes , Externs , ErrorOutputType , Sanitizer } ;
2112+ OutputTypes , Externs , ErrorOutputType , Sanitizer , Epoch } ;
20732113 use syntax:: feature_gate:: UnstableFeatures ;
20742114 use rustc_back:: { PanicStrategy , RelroLevel } ;
20752115
@@ -2131,6 +2171,7 @@ mod dep_tracking {
21312171 impl_dep_tracking_hash_via_hash ! ( cstore:: NativeLibraryKind ) ;
21322172 impl_dep_tracking_hash_via_hash ! ( Sanitizer ) ;
21332173 impl_dep_tracking_hash_via_hash ! ( Option <Sanitizer >) ;
2174+ impl_dep_tracking_hash_via_hash ! ( Epoch ) ;
21342175
21352176 impl_dep_tracking_hash_for_sortable_vec_of ! ( String ) ;
21362177 impl_dep_tracking_hash_for_sortable_vec_of ! ( PathBuf ) ;
0 commit comments