1
Fork 0

pre-expansion gate trait_alias.

This commit is contained in:
Mazdak Farrokhzad 2019-09-21 17:40:50 +02:00
parent 2e64bb2d37
commit 2d182b82ce
5 changed files with 24 additions and 10 deletions

View file

@ -423,15 +423,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
"auto traits are experimental and possibly buggy");
}
ast::ItemKind::TraitAlias(..) => {
gate_feature_post!(
&self,
trait_alias,
i.span,
"trait aliases are experimental"
);
}
ast::ItemKind::MacroDef(ast::MacroDef { legacy: false, .. }) => {
let msg = "`macro` is experimental";
gate_feature_post!(&self, decl_macro, i.span, msg);
@ -867,6 +858,7 @@ pub fn check_crate(krate: &ast::Crate,
gate_all!(yields, generators, "yield syntax is experimental");
gate_all!(or_patterns, "or-patterns syntax is experimental");
gate_all!(const_extern_fn, "`const extern fn` definitions are unstable");
gate_all!(trait_alias, "trait aliases are experimental");
visit::walk_crate(&mut visitor, krate);
}

View file

@ -828,6 +828,8 @@ impl<'a> Parser<'a> {
.emit();
}
self.sess.gated_spans.trait_alias.borrow_mut().push(whole_span);
Ok((ident, ItemKind::TraitAlias(tps, bounds), None))
} else {
// It's a normal trait.

View file

@ -30,6 +30,8 @@ crate struct GatedSpans {
crate or_patterns: Lock<Vec<Span>>,
/// Spans collected for gating `const_extern_fn`, e.g. `const extern fn foo`.
crate const_extern_fn: Lock<Vec<Span>>,
/// Spans collected for gating `trait_alias`, e.g. `trait Foo = Ord + Eq;`.
pub trait_alias: Lock<Vec<Span>>,
}
/// Info about a parsing session.

View file

@ -1,4 +1,13 @@
trait Foo = Default;
//~^ ERROR trait aliases are experimental
macro_rules! accept_item {
($i:item) => {}
}
accept_item! {
trait Foo = Ord + Eq;
//~^ ERROR trait aliases are experimental
}
fn main() {}

View file

@ -7,6 +7,15 @@ LL | trait Foo = Default;
= note: for more information, see https://github.com/rust-lang/rust/issues/41517
= help: add `#![feature(trait_alias)]` to the crate attributes to enable
error: aborting due to previous error
error[E0658]: trait aliases are experimental
--> $DIR/feature-gate-trait-alias.rs:9:5
|
LL | trait Foo = Ord + Eq;
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/41517
= help: add `#![feature(trait_alias)]` to the crate attributes to enable
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0658`.