Skip to content

Commit

Permalink
Make it possible to ungate features by epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Mar 9, 2018
1 parent c3fe3a5 commit b88a61e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/librustc_driver/driver.rs
Expand Up @@ -647,7 +647,9 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
{
let time_passes = sess.time_passes();

let (mut krate, features) = syntax::config::features(krate, &sess.parse_sess, sess.opts.test);
let (mut krate, features) = syntax::config::features(krate, &sess.parse_sess,
sess.opts.test,
sess.opts.debugging_opts.epoch);
// these need to be set "early" so that expansion sees `quote` if enabled.
sess.init_features(features);

Expand Down
5 changes: 3 additions & 2 deletions src/libsyntax/config.rs
Expand Up @@ -13,6 +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 parse::{token, ParseSess};

use ptr::P;
Expand All @@ -26,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)
pub fn features(mut krate: ast::Crate, sess: &ParseSess, should_test: bool, epoch: Epoch)
-> (ast::Crate, Features) {
let features;
{
Expand All @@ -46,7 +47,7 @@ pub fn features(mut krate: ast::Crate, sess: &ParseSess, should_test: bool)
return (krate, Features::new());
}

features = get_features(&sess.span_diagnostic, &krate.attrs);
features = get_features(&sess.span_diagnostic, &krate.attrs, epoch);

// Avoid reconfiguring malformed `cfg_attr`s
if err_count == sess.span_diagnostic.err_count() {
Expand Down
20 changes: 16 additions & 4 deletions src/libsyntax/feature_gate.rs
Expand Up @@ -30,7 +30,7 @@ use ast::{self, NodeId, PatKind, RangeEnd, RangeSyntax};
use attr;
use epoch::Epoch;
use codemap::Spanned;
use syntax_pos::Span;
use syntax_pos::{Span, DUMMY_SP};
use errors::{DiagnosticBuilder, Handler, FatalError};
use visit::{self, FnKind, Visitor};
use parse::ParseSess;
Expand Down Expand Up @@ -59,7 +59,8 @@ macro_rules! declare_features {
/// 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))] =
&'static [(&'static str, &'static str, Option<u32>,
Option<Epoch>, fn(&mut Features, Span))] =
&[$((stringify!($feature), $ver, $issue, $epoch, set!($feature))),+];

/// A set of features to be used by later passes.
Expand Down Expand Up @@ -408,7 +409,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), None),
(active, dyn_trait, "1.22.0", Some(44662), Some(Epoch::Epoch2018)),

// `crate` as visibility modifier, synonymous to `pub(crate)`
(active, crate_visibility_modifier, "1.23.0", Some(45388), None),
Expand Down Expand Up @@ -1794,11 +1795,22 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}
}

pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute]) -> Features {
pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
epoch: Epoch) -> 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 {
// FIXME(Manishearth) there is currently no way to set
// lang features by epoch
set(&mut features, DUMMY_SP);
}
}
}

for attr in krate_attrs {
if !attr.check_name("feature") {
continue
Expand Down

0 comments on commit b88a61e

Please sign in to comment.