Skip to content

Commit e0cea6c

Browse files
committed
pre-expansion gate optin_builtin_traits & extern_types
1 parent dd2df8f commit e0cea6c

9 files changed

+54
-27
lines changed

src/libsyntax/feature_gate/check.rs

+7-20
Original file line numberDiff line numberDiff line change
@@ -414,27 +414,14 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
414414
}
415415
}
416416

417-
ast::ItemKind::Impl(_, polarity, defaultness, ..) => {
418-
if polarity == ast::ImplPolarity::Negative {
419-
gate_feature_post!(&self, optin_builtin_traits,
420-
i.span,
421-
"negative trait bounds are not yet fully implemented; \
422-
use marker types for now");
423-
}
424-
417+
ast::ItemKind::Impl(_, _, defaultness, ..) => {
425418
if let ast::Defaultness::Default = defaultness {
426419
gate_feature_post!(&self, specialization,
427420
i.span,
428421
"specialization is unstable");
429422
}
430423
}
431424

432-
ast::ItemKind::Trait(ast::IsAuto::Yes, ..) => {
433-
gate_feature_post!(&self, optin_builtin_traits,
434-
i.span,
435-
"auto traits are experimental and possibly buggy");
436-
}
437-
438425
ast::ItemKind::OpaqueTy(..) => {
439426
gate_feature_post!(
440427
&self,
@@ -464,11 +451,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
464451
"linking to LLVM intrinsics is experimental");
465452
}
466453
}
467-
ast::ForeignItemKind::Ty => {
468-
gate_feature_post!(&self, extern_types, i.span,
469-
"extern types are experimental");
470-
}
471-
ast::ForeignItemKind::Macro(..) => {}
454+
_ => {}
472455
}
473456

474457
visit::walk_foreign_item(self, i)
@@ -789,7 +772,11 @@ pub fn check_crate(krate: &ast::Crate,
789772
gate_all!(try_blocks, "`try` blocks are unstable");
790773
gate_all!(label_break_value, "labels on blocks are unstable");
791774
gate_all!(box_syntax, "box expression syntax is experimental; you can call `Box::new` instead");
792-
775+
gate_all!(auto_traits, optin_builtin_traits, "auto traits are experimental and possibly buggy");
776+
gate_all!(
777+
negative_impls, optin_builtin_traits,
778+
"negative trait bounds are not yet fully implemented; use marker types for now"
779+
);
793780
// To avoid noise about type ascription in common syntax errors,
794781
// only emit if it is the *only* error. (Also check it last.)
795782
if parse_sess.span_diagnostic.err_count() == 0 {

src/libsyntax/parse/parser/item.rs

+7
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ impl<'a> Parser<'a> {
588588
// Disambiguate `impl !Trait for Type { ... }` and `impl ! { ... }` for the never type.
589589
let polarity = if self.check(&token::Not) && self.look_ahead(1, |t| t.can_begin_type()) {
590590
self.bump(); // `!`
591+
self.sess.gated_spans.negative_impls.borrow_mut().push(self.prev_span);
591592
ast::ImplPolarity::Negative
592593
} else {
593594
ast::ImplPolarity::Positive
@@ -865,6 +866,11 @@ impl<'a> Parser<'a> {
865866
}
866867
}
867868
}
869+
870+
if is_auto == IsAuto::Yes {
871+
self.sess.gated_spans.auto_traits.borrow_mut().push(lo.to(self.prev_span));
872+
}
873+
868874
Ok((ident, ItemKind::Trait(is_auto, unsafety, tps, bounds, trait_items), None))
869875
}
870876
}
@@ -1235,6 +1241,7 @@ impl<'a> Parser<'a> {
12351241
let ident = self.parse_ident()?;
12361242
let hi = self.token.span;
12371243
self.expect(&token::Semi)?;
1244+
self.sess.gated_spans.extern_types.borrow_mut().push(lo.to(self.prev_span));
12381245
Ok(ast::ForeignItem {
12391246
ident,
12401247
attrs,

src/libsyntax/sess.rs

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ crate struct GatedSpans {
5252
pub box_syntax: Lock<Vec<Span>>,
5353
/// Spans collected for gating `type_ascription`, e.g. `42: usize`.
5454
pub type_ascription: Lock<Vec<Span>>,
55+
/// Spans collected for gating `optin_builtin_traits`, e.g. `auto trait Foo {}`.
56+
pub auto_traits: Lock<Vec<Span>>,
57+
/// Spans collected for gating `optin_builtin_traits`, e.g. `impl !Trait for Type {}`.
58+
pub negative_impls: Lock<Vec<Span>>,
59+
/// Spans collected for gating `extern_types`, e.g. `extern type Foo;`.
60+
pub extern_types: Lock<Vec<Span>>,
5561
}
5662

5763
/// Info about a parsing session.

src/test/ui/feature-gates/feature-gate-extern_types.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(FALSE)]
12
extern {
23
type T; //~ ERROR extern types are experimental
34
}

src/test/ui/feature-gates/feature-gate-extern_types.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: extern types are experimental
2-
--> $DIR/feature-gate-extern_types.rs:2:5
2+
--> $DIR/feature-gate-extern_types.rs:3:5
33
|
44
LL | type T;
55
| ^^^^^^^

src/test/ui/feature-gates/feature-gate-optin-builtin-traits.rs

+9
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,13 @@ auto trait AutoDummyTrait {}
99
impl !AutoDummyTrait for DummyStruct {}
1010
//~^ ERROR negative trait bounds are not yet fully implemented; use marker types for now
1111

12+
macro_rules! accept_item { ($i:item) => {} }
13+
accept_item! {
14+
auto trait Auto {}
15+
//~^ ERROR auto traits are experimental and possibly buggy
16+
}
17+
accept_item! {
18+
impl !AutoDummyTrait for DummyStruct {}
19+
//~^ ERROR negative trait bounds are not yet fully implemented; use marker types for now
20+
}
1221
fn main() {}

src/test/ui/feature-gates/feature-gate-optin-builtin-traits.stderr

+21-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,33 @@ LL | auto trait AutoDummyTrait {}
77
= note: for more information, see https://github.com/rust-lang/rust/issues/13231
88
= help: add `#![feature(optin_builtin_traits)]` to the crate attributes to enable
99

10+
error[E0658]: auto traits are experimental and possibly buggy
11+
--> $DIR/feature-gate-optin-builtin-traits.rs:14:5
12+
|
13+
LL | auto trait Auto {}
14+
| ^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: for more information, see https://github.com/rust-lang/rust/issues/13231
17+
= help: add `#![feature(optin_builtin_traits)]` to the crate attributes to enable
18+
1019
error[E0658]: negative trait bounds are not yet fully implemented; use marker types for now
11-
--> $DIR/feature-gate-optin-builtin-traits.rs:9:1
20+
--> $DIR/feature-gate-optin-builtin-traits.rs:9:6
1221
|
1322
LL | impl !AutoDummyTrait for DummyStruct {}
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23+
| ^
24+
|
25+
= note: for more information, see https://github.com/rust-lang/rust/issues/13231
26+
= help: add `#![feature(optin_builtin_traits)]` to the crate attributes to enable
27+
28+
error[E0658]: negative trait bounds are not yet fully implemented; use marker types for now
29+
--> $DIR/feature-gate-optin-builtin-traits.rs:18:10
30+
|
31+
LL | impl !AutoDummyTrait for DummyStruct {}
32+
| ^
1533
|
1634
= note: for more information, see https://github.com/rust-lang/rust/issues/13231
1735
= help: add `#![feature(optin_builtin_traits)]` to the crate attributes to enable
1836

19-
error: aborting due to 2 previous errors
37+
error: aborting due to 4 previous errors
2038

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

src/test/ui/syntax-trait-polarity-feature-gate.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0658]: negative trait bounds are not yet fully implemented; use marker types for now
2-
--> $DIR/syntax-trait-polarity-feature-gate.rs:7:1
2+
--> $DIR/syntax-trait-polarity-feature-gate.rs:7:6
33
|
44
LL | impl !Send for TestType {}
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^
66
|
77
= note: for more information, see https://github.com/rust-lang/rust/issues/13231
88
= help: add `#![feature(optin_builtin_traits)]` to the crate attributes to enable

src/test/ui/traits/trait-alias/trait-alias-syntax-fail.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@ LL | trait D: = Eq;
2323
| ^
2424

2525
error: aborting due to 4 previous errors
26-

0 commit comments

Comments
 (0)