Skip to content

Commit 382f0f3

Browse files
committed
Pre-expansion gate 'default'.
1 parent 224f080 commit 382f0f3

File tree

6 files changed

+29
-22
lines changed

6 files changed

+29
-22
lines changed

src/libsyntax/feature_gate.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,19 +1980,13 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
19801980
}
19811981
}
19821982

1983-
ast::ItemKind::Impl(_, polarity, defaultness, _, _, _, _) => {
1983+
ast::ItemKind::Impl(_, polarity, ..) => {
19841984
if polarity == ast::ImplPolarity::Negative {
19851985
gate_feature_post!(&self, optin_builtin_traits,
19861986
i.span,
19871987
"negative trait bounds are not yet fully implemented; \
19881988
use marker types for now");
19891989
}
1990-
1991-
if let ast::Defaultness::Default = defaultness {
1992-
gate_feature_post!(&self, specialization,
1993-
i.span,
1994-
"specialization is unstable");
1995-
}
19961990
}
19971991

19981992
ast::ItemKind::Trait(ast::IsAuto::Yes, ..) => {
@@ -2231,12 +2225,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
22312225
}
22322226

22332227
fn visit_impl_item(&mut self, ii: &'a ast::ImplItem) {
2234-
if ii.defaultness == ast::Defaultness::Default {
2235-
gate_feature_post!(&self, specialization,
2236-
ii.span,
2237-
"specialization is unstable");
2238-
}
2239-
22402228
match ii.node {
22412229
ast::ImplItemKind::Method(..) => {}
22422230
ast::ImplItemKind::OpaqueTy(..) => {
@@ -2451,6 +2439,7 @@ pub fn check_crate(krate: &ast::Crate,
24512439
gate_all!(async_closure, "async closures are unstable");
24522440
gate_all!(yields, generators, "yield syntax is experimental");
24532441
gate_all!(or_patterns, "or-patterns syntax is experimental");
2442+
gate_all!(specialization, "specialization is unstable");
24542443

24552444
let visitor = &mut PostExpansionVisitor {
24562445
context: &ctx,

src/libsyntax/parse/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ pub struct GatedSpans {
5353
pub yields: Lock<Vec<Span>>,
5454
/// Spans collected for gating `or_patterns`, e.g. `Some(Foo | Bar)`.
5555
pub or_patterns: Lock<Vec<Span>>,
56+
/// Spans collected for gating the `default` qualifier for `specialization`.
57+
pub specialization: Lock<Vec<Span>>,
5658
}
5759

5860
/// Info about a parsing session.

src/libsyntax/parse/parser/item.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ impl<'a> Parser<'a> {
833833
])
834834
{
835835
self.bump(); // `default`
836+
self.sess.gated_spans.specialization.borrow_mut().push(self.prev_span);
836837
Defaultness::Default
837838
} else {
838839
Defaultness::Final

src/test/ui/specialization/defaultimpl/specialization-feature-gate-default.stderr

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
error[E0658]: specialization is unstable
22
--> $DIR/specialization-feature-gate-default.rs:7:1
33
|
4-
LL | / default impl<T> Foo for T {
5-
LL | | fn foo(&self) {}
6-
LL | | }
7-
| |_^
4+
LL | default impl<T> Foo for T {
5+
| ^^^^^^^
86
|
97
= note: for more information, see https://github.com/rust-lang/rust/issues/31844
108
= help: add `#![feature(specialization)]` to the crate attributes to enable

src/test/ui/specialization/specialization-feature-gate-default.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@ trait Foo {
66
fn foo(&self);
77
}
88

9+
#[cfg(FALSE)]
910
impl<T> Foo for T {
10-
default fn foo(&self) {} //~ ERROR specialization is unstable
11+
default //~ ERROR specialization is unstable
12+
fn foo(&self) {}
13+
}
14+
15+
#[cfg(FALSE)]
16+
default //~ ERROR specialization is unstable
17+
impl<T> Foo for T {
18+
fn foo(&self) {}
1119
}
1220

1321
fn main() {}
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
error[E0658]: specialization is unstable
2-
--> $DIR/specialization-feature-gate-default.rs:10:5
2+
--> $DIR/specialization-feature-gate-default.rs:11:5
33
|
4-
LL | default fn foo(&self) {}
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^
4+
LL | default
5+
| ^^^^^^^
66
|
77
= note: for more information, see https://github.com/rust-lang/rust/issues/31844
88
= help: add `#![feature(specialization)]` to the crate attributes to enable
99

10-
error: aborting due to previous error
10+
error[E0658]: specialization is unstable
11+
--> $DIR/specialization-feature-gate-default.rs:16:1
12+
|
13+
LL | default
14+
| ^^^^^^^
15+
|
16+
= note: for more information, see https://github.com/rust-lang/rust/issues/31844
17+
= help: add `#![feature(specialization)]` 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)