Skip to content

Commit b88a61e

Browse files
committed
Make it possible to ungate features by epoch
1 parent c3fe3a5 commit b88a61e

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

src/librustc_driver/driver.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,9 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
647647
{
648648
let time_passes = sess.time_passes();
649649

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

src/libsyntax/config.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use feature_gate::{feature_err, EXPLAIN_STMT_ATTR_SYNTAX, Features, get_features
1313
use {fold, attr};
1414
use ast;
1515
use codemap::Spanned;
16+
use epoch::Epoch;
1617
use parse::{token, ParseSess};
1718

1819
use ptr::P;
@@ -26,7 +27,7 @@ pub struct StripUnconfigured<'a> {
2627
}
2728

2829
// `cfg_attr`-process the crate's attributes and compute the crate's features.
29-
pub fn features(mut krate: ast::Crate, sess: &ParseSess, should_test: bool)
30+
pub fn features(mut krate: ast::Crate, sess: &ParseSess, should_test: bool, epoch: Epoch)
3031
-> (ast::Crate, Features) {
3132
let features;
3233
{
@@ -46,7 +47,7 @@ pub fn features(mut krate: ast::Crate, sess: &ParseSess, should_test: bool)
4647
return (krate, Features::new());
4748
}
4849

49-
features = get_features(&sess.span_diagnostic, &krate.attrs);
50+
features = get_features(&sess.span_diagnostic, &krate.attrs, epoch);
5051

5152
// Avoid reconfiguring malformed `cfg_attr`s
5253
if err_count == sess.span_diagnostic.err_count() {

src/libsyntax/feature_gate.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use ast::{self, NodeId, PatKind, RangeEnd, RangeSyntax};
3030
use attr;
3131
use epoch::Epoch;
3232
use codemap::Spanned;
33-
use syntax_pos::Span;
33+
use syntax_pos::{Span, DUMMY_SP};
3434
use errors::{DiagnosticBuilder, Handler, FatalError};
3535
use visit::{self, FnKind, Visitor};
3636
use parse::ParseSess;
@@ -59,7 +59,8 @@ macro_rules! declare_features {
5959
/// Represents active features that are currently being implemented or
6060
/// currently being considered for addition/removal.
6161
const ACTIVE_FEATURES:
62-
&'static [(&'static str, &'static str, Option<u32>, Option<Epoch>, fn(&mut Features, Span))] =
62+
&'static [(&'static str, &'static str, Option<u32>,
63+
Option<Epoch>, fn(&mut Features, Span))] =
6364
&[$((stringify!($feature), $ver, $issue, $epoch, set!($feature))),+];
6465

6566
/// A set of features to be used by later passes.
@@ -408,7 +409,7 @@ declare_features! (
408409
(active, match_default_bindings, "1.22.0", Some(42640), None),
409410

410411
// Trait object syntax with `dyn` prefix
411-
(active, dyn_trait, "1.22.0", Some(44662), None),
412+
(active, dyn_trait, "1.22.0", Some(44662), Some(Epoch::Epoch2018)),
412413

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

1797-
pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute]) -> Features {
1798+
pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
1799+
epoch: Epoch) -> Features {
17981800
let mut features = Features::new();
17991801

18001802
let mut feature_checker = FeatureChecker::default();
18011803

1804+
for &(.., f_epoch, set) in ACTIVE_FEATURES.iter() {
1805+
if let Some(f_epoch) = f_epoch {
1806+
if epoch >= f_epoch {
1807+
// FIXME(Manishearth) there is currently no way to set
1808+
// lang features by epoch
1809+
set(&mut features, DUMMY_SP);
1810+
}
1811+
}
1812+
}
1813+
18021814
for attr in krate_attrs {
18031815
if !attr.check_name("feature") {
18041816
continue

0 commit comments

Comments
 (0)