Skip to content

Commit 2d182b8

Browse files
committed
pre-expansion gate trait_alias.
1 parent 2e64bb2 commit 2d182b8

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

src/libsyntax/feature_gate/check.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
423423
"auto traits are experimental and possibly buggy");
424424
}
425425

426-
ast::ItemKind::TraitAlias(..) => {
427-
gate_feature_post!(
428-
&self,
429-
trait_alias,
430-
i.span,
431-
"trait aliases are experimental"
432-
);
433-
}
434-
435426
ast::ItemKind::MacroDef(ast::MacroDef { legacy: false, .. }) => {
436427
let msg = "`macro` is experimental";
437428
gate_feature_post!(&self, decl_macro, i.span, msg);
@@ -867,6 +858,7 @@ pub fn check_crate(krate: &ast::Crate,
867858
gate_all!(yields, generators, "yield syntax is experimental");
868859
gate_all!(or_patterns, "or-patterns syntax is experimental");
869860
gate_all!(const_extern_fn, "`const extern fn` definitions are unstable");
861+
gate_all!(trait_alias, "trait aliases are experimental");
870862

871863
visit::walk_crate(&mut visitor, krate);
872864
}

src/libsyntax/parse/parser/item.rs

+2
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,8 @@ impl<'a> Parser<'a> {
828828
.emit();
829829
}
830830

831+
self.sess.gated_spans.trait_alias.borrow_mut().push(whole_span);
832+
831833
Ok((ident, ItemKind::TraitAlias(tps, bounds), None))
832834
} else {
833835
// It's a normal trait.

src/libsyntax/sess.rs

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ crate struct GatedSpans {
3030
crate or_patterns: Lock<Vec<Span>>,
3131
/// Spans collected for gating `const_extern_fn`, e.g. `const extern fn foo`.
3232
crate const_extern_fn: Lock<Vec<Span>>,
33+
/// Spans collected for gating `trait_alias`, e.g. `trait Foo = Ord + Eq;`.
34+
pub trait_alias: Lock<Vec<Span>>,
3335
}
3436

3537
/// Info about a parsing session.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
trait Foo = Default;
22
//~^ ERROR trait aliases are experimental
33

4+
macro_rules! accept_item {
5+
($i:item) => {}
6+
}
7+
8+
accept_item! {
9+
trait Foo = Ord + Eq;
10+
//~^ ERROR trait aliases are experimental
11+
}
12+
413
fn main() {}

src/test/ui/feature-gates/feature-gate-trait-alias.stderr

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ LL | trait Foo = Default;
77
= note: for more information, see https://github.com/rust-lang/rust/issues/41517
88
= help: add `#![feature(trait_alias)]` to the crate attributes to enable
99

10-
error: aborting due to previous error
10+
error[E0658]: trait aliases are experimental
11+
--> $DIR/feature-gate-trait-alias.rs:9:5
12+
|
13+
LL | trait Foo = Ord + Eq;
14+
| ^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: for more information, see https://github.com/rust-lang/rust/issues/41517
17+
= help: add `#![feature(trait_alias)]` to the crate attributes to enable
18+
19+
error: aborting due to 2 previous errors
1120

1221
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)