Merge branch '49001_epoch' of https://github.com/klnusbaum/rust into rollup
This commit is contained in:
@@ -13,7 +13,7 @@ use feature_gate::{feature_err, EXPLAIN_STMT_ATTR_SYNTAX, Features, get_features
|
||||
use {fold, attr};
|
||||
use ast;
|
||||
use codemap::Spanned;
|
||||
use epoch::Epoch;
|
||||
use edition::Edition;
|
||||
use parse::{token, ParseSess};
|
||||
|
||||
use ptr::P;
|
||||
@@ -27,7 +27,7 @@ pub struct StripUnconfigured<'a> {
|
||||
}
|
||||
|
||||
// `cfg_attr`-process the crate's attributes and compute the crate's features.
|
||||
pub fn features(mut krate: ast::Crate, sess: &ParseSess, should_test: bool, epoch: Epoch)
|
||||
pub fn features(mut krate: ast::Crate, sess: &ParseSess, should_test: bool, edition: Edition)
|
||||
-> (ast::Crate, Features) {
|
||||
let features;
|
||||
{
|
||||
@@ -47,7 +47,7 @@ pub fn features(mut krate: ast::Crate, sess: &ParseSess, should_test: bool, epoc
|
||||
return (krate, Features::new());
|
||||
}
|
||||
|
||||
features = get_features(&sess.span_diagnostic, &krate.attrs, epoch);
|
||||
features = get_features(&sess.span_diagnostic, &krate.attrs, edition);
|
||||
|
||||
// Avoid reconfiguring malformed `cfg_attr`s
|
||||
if err_count == sess.span_diagnostic.err_count() {
|
||||
|
||||
@@ -11,58 +11,58 @@
|
||||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
|
||||
/// The epoch of the compiler (RFC 2052)
|
||||
/// The edition of the compiler (RFC 2052)
|
||||
#[derive(Clone, Copy, Hash, PartialOrd, Ord, Eq, PartialEq, Debug)]
|
||||
#[non_exhaustive]
|
||||
pub enum Epoch {
|
||||
// epochs must be kept in order, newest to oldest
|
||||
pub enum Edition {
|
||||
// editions must be kept in order, newest to oldest
|
||||
|
||||
/// The 2015 epoch
|
||||
Epoch2015,
|
||||
/// The 2018 epoch
|
||||
Epoch2018,
|
||||
/// The 2015 edition
|
||||
Edition2015,
|
||||
/// The 2018 edition
|
||||
Edition2018,
|
||||
|
||||
// when adding new epochs, be sure to update:
|
||||
// when adding new editions, be sure to update:
|
||||
//
|
||||
// - the list in the `parse_epoch` static in librustc::session::config
|
||||
// - the list in the `parse_edition` static in librustc::session::config
|
||||
// - add a `rust_####()` function to the session
|
||||
// - update the enum in Cargo's sources as well
|
||||
//
|
||||
// When -Zepoch becomes --epoch, there will
|
||||
// also be a check for the epoch being nightly-only
|
||||
// When -Zedition becomes --edition, there will
|
||||
// also be a check for the edition being nightly-only
|
||||
// somewhere. That will need to be updated
|
||||
// whenever we're stabilizing/introducing a new epoch
|
||||
// whenever we're stabilizing/introducing a new edition
|
||||
// as well as changing the default Cargo template.
|
||||
}
|
||||
|
||||
// must be in order from oldest to newest
|
||||
pub const ALL_EPOCHS: &[Epoch] = &[Epoch::Epoch2015, Epoch::Epoch2018];
|
||||
pub const ALL_EDITIONS: &[Edition] = &[Edition::Edition2015, Edition::Edition2018];
|
||||
|
||||
impl fmt::Display for Epoch {
|
||||
impl fmt::Display for Edition {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let s = match *self {
|
||||
Epoch::Epoch2015 => "2015",
|
||||
Epoch::Epoch2018 => "2018",
|
||||
Edition::Edition2015 => "2015",
|
||||
Edition::Edition2018 => "2018",
|
||||
};
|
||||
write!(f, "{}", s)
|
||||
}
|
||||
}
|
||||
|
||||
impl Epoch {
|
||||
impl Edition {
|
||||
pub fn lint_name(&self) -> &'static str {
|
||||
match *self {
|
||||
Epoch::Epoch2015 => "epoch_2015",
|
||||
Epoch::Epoch2018 => "epoch_2018",
|
||||
Edition::Edition2015 => "edition_2015",
|
||||
Edition::Edition2018 => "edition_2018",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Epoch {
|
||||
impl FromStr for Edition {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<Self, ()> {
|
||||
match s {
|
||||
"2015" => Ok(Epoch::Epoch2015),
|
||||
"2018" => Ok(Epoch::Epoch2018),
|
||||
"2015" => Ok(Edition::Edition2015),
|
||||
"2018" => Ok(Edition::Edition2018),
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ use self::AttributeGate::*;
|
||||
use abi::Abi;
|
||||
use ast::{self, NodeId, PatKind, RangeEnd};
|
||||
use attr;
|
||||
use epoch::Epoch;
|
||||
use edition::Edition;
|
||||
use codemap::Spanned;
|
||||
use syntax_pos::{Span, DUMMY_SP};
|
||||
use errors::{DiagnosticBuilder, Handler, FatalError};
|
||||
@@ -55,13 +55,13 @@ macro_rules! set {
|
||||
}
|
||||
|
||||
macro_rules! declare_features {
|
||||
($((active, $feature: ident, $ver: expr, $issue: expr, $epoch: expr),)+) => {
|
||||
($((active, $feature: ident, $ver: expr, $issue: expr, $edition: expr),)+) => {
|
||||
/// Represents active features that are currently being implemented or
|
||||
/// currently being considered for addition/removal.
|
||||
const ACTIVE_FEATURES:
|
||||
&'static [(&'static str, &'static str, Option<u32>,
|
||||
Option<Epoch>, fn(&mut Features, Span))] =
|
||||
&[$((stringify!($feature), $ver, $issue, $epoch, set!($feature))),+];
|
||||
Option<Edition>, fn(&mut Features, Span))] =
|
||||
&[$((stringify!($feature), $ver, $issue, $edition, set!($feature))),+];
|
||||
|
||||
/// A set of features to be used by later passes.
|
||||
#[derive(Clone)]
|
||||
@@ -402,7 +402,7 @@ declare_features! (
|
||||
(active, match_default_bindings, "1.22.0", Some(42640), None),
|
||||
|
||||
// Trait object syntax with `dyn` prefix
|
||||
(active, dyn_trait, "1.22.0", Some(44662), Some(Epoch::Epoch2018)),
|
||||
(active, dyn_trait, "1.22.0", Some(44662), Some(Edition::Edition2018)),
|
||||
|
||||
// `crate` as visibility modifier, synonymous to `pub(crate)`
|
||||
(active, crate_visibility_modifier, "1.23.0", Some(45388), None),
|
||||
@@ -1818,16 +1818,16 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||
}
|
||||
|
||||
pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
|
||||
epoch: Epoch) -> Features {
|
||||
edition: Edition) -> Features {
|
||||
let mut features = Features::new();
|
||||
|
||||
let mut feature_checker = FeatureChecker::default();
|
||||
|
||||
for &(.., f_epoch, set) in ACTIVE_FEATURES.iter() {
|
||||
if let Some(f_epoch) = f_epoch {
|
||||
if epoch >= f_epoch {
|
||||
for &(.., f_edition, set) in ACTIVE_FEATURES.iter() {
|
||||
if let Some(f_edition) = f_edition {
|
||||
if edition >= f_edition {
|
||||
// FIXME(Manishearth) there is currently no way to set
|
||||
// lang features by epoch
|
||||
// lang features by edition
|
||||
set(&mut features, DUMMY_SP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ pub mod codemap;
|
||||
#[macro_use]
|
||||
pub mod config;
|
||||
pub mod entry;
|
||||
pub mod epoch;
|
||||
pub mod edition;
|
||||
pub mod feature_gate;
|
||||
pub mod fold;
|
||||
pub mod parse;
|
||||
|
||||
Reference in New Issue
Block a user