Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-expansion gate some more things #64672

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 7 additions & 20 deletions src/libsyntax/feature_gate/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,27 +414,14 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}
}

ast::ItemKind::Impl(_, polarity, defaultness, ..) => {
if polarity == ast::ImplPolarity::Negative {
gate_feature_post!(&self, optin_builtin_traits,
i.span,
"negative trait bounds are not yet fully implemented; \
use marker types for now");
}

ast::ItemKind::Impl(_, _, defaultness, ..) => {
if let ast::Defaultness::Default = defaultness {
gate_feature_post!(&self, specialization,
i.span,
"specialization is unstable");
}
}

ast::ItemKind::Trait(ast::IsAuto::Yes, ..) => {
gate_feature_post!(&self, optin_builtin_traits,
i.span,
"auto traits are experimental and possibly buggy");
}

ast::ItemKind::OpaqueTy(..) => {
gate_feature_post!(
&self,
Expand Down Expand Up @@ -464,11 +451,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
"linking to LLVM intrinsics is experimental");
}
}
ast::ForeignItemKind::Ty => {
gate_feature_post!(&self, extern_types, i.span,
"extern types are experimental");
}
ast::ForeignItemKind::Macro(..) => {}
_ => {}
}

visit::walk_foreign_item(self, i)
Expand Down Expand Up @@ -789,7 +772,11 @@ pub fn check_crate(krate: &ast::Crate,
gate_all!(try_blocks, "`try` blocks are unstable");
gate_all!(label_break_value, "labels on blocks are unstable");
gate_all!(box_syntax, "box expression syntax is experimental; you can call `Box::new` instead");

gate_all!(auto_traits, optin_builtin_traits, "auto traits are experimental and possibly buggy");
gate_all!(
negative_impls, optin_builtin_traits,
"negative trait bounds are not yet fully implemented; use marker types for now"
);
// To avoid noise about type ascription in common syntax errors,
// only emit if it is the *only* error. (Also check it last.)
if parse_sess.span_diagnostic.err_count() == 0 {
Expand Down
7 changes: 7 additions & 0 deletions src/libsyntax/parse/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ impl<'a> Parser<'a> {
// Disambiguate `impl !Trait for Type { ... }` and `impl ! { ... }` for the never type.
let polarity = if self.check(&token::Not) && self.look_ahead(1, |t| t.can_begin_type()) {
self.bump(); // `!`
self.sess.gated_spans.negative_impls.borrow_mut().push(self.prev_span);
ast::ImplPolarity::Negative
} else {
ast::ImplPolarity::Positive
Expand Down Expand Up @@ -865,6 +866,11 @@ impl<'a> Parser<'a> {
}
}
}

if is_auto == IsAuto::Yes {
self.sess.gated_spans.auto_traits.borrow_mut().push(lo.to(self.prev_span));
}

Ok((ident, ItemKind::Trait(is_auto, unsafety, tps, bounds, trait_items), None))
}
}
Expand Down Expand Up @@ -1235,6 +1241,7 @@ impl<'a> Parser<'a> {
let ident = self.parse_ident()?;
let hi = self.token.span;
self.expect(&token::Semi)?;
self.sess.gated_spans.extern_types.borrow_mut().push(lo.to(self.prev_span));
Ok(ast::ForeignItem {
ident,
attrs,
Expand Down
6 changes: 6 additions & 0 deletions src/libsyntax/sess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ crate struct GatedSpans {
pub box_syntax: Lock<Vec<Span>>,
/// Spans collected for gating `type_ascription`, e.g. `42: usize`.
pub type_ascription: Lock<Vec<Span>>,
/// Spans collected for gating `optin_builtin_traits`, e.g. `auto trait Foo {}`.
pub auto_traits: Lock<Vec<Span>>,
/// Spans collected for gating `optin_builtin_traits`, e.g. `impl !Trait for Type {}`.
pub negative_impls: Lock<Vec<Span>>,
/// Spans collected for gating `extern_types`, e.g. `extern type Foo;`.
pub extern_types: Lock<Vec<Span>>,
}

/// Info about a parsing session.
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/feature-gates/feature-gate-extern_types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(FALSE)]
extern {
type T; //~ ERROR extern types are experimental
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/feature-gates/feature-gate-extern_types.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0658]: extern types are experimental
--> $DIR/feature-gate-extern_types.rs:2:5
--> $DIR/feature-gate-extern_types.rs:3:5
|
LL | type T;
| ^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@ auto trait AutoDummyTrait {}
impl !AutoDummyTrait for DummyStruct {}
//~^ ERROR negative trait bounds are not yet fully implemented; use marker types for now

macro_rules! accept_item { ($i:item) => {} }
accept_item! {
auto trait Auto {}
//~^ ERROR auto traits are experimental and possibly buggy
}
accept_item! {
impl !AutoDummyTrait for DummyStruct {}
//~^ ERROR negative trait bounds are not yet fully implemented; use marker types for now
}
fn main() {}
24 changes: 21 additions & 3 deletions src/test/ui/feature-gates/feature-gate-optin-builtin-traits.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,33 @@ LL | auto trait AutoDummyTrait {}
= note: for more information, see https://github.com/rust-lang/rust/issues/13231
= help: add `#![feature(optin_builtin_traits)]` to the crate attributes to enable

error[E0658]: auto traits are experimental and possibly buggy
--> $DIR/feature-gate-optin-builtin-traits.rs:14:5
|
LL | auto trait Auto {}
| ^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/13231
= help: add `#![feature(optin_builtin_traits)]` to the crate attributes to enable

error[E0658]: negative trait bounds are not yet fully implemented; use marker types for now
--> $DIR/feature-gate-optin-builtin-traits.rs:9:1
--> $DIR/feature-gate-optin-builtin-traits.rs:9:6
|
LL | impl !AutoDummyTrait for DummyStruct {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/13231
= help: add `#![feature(optin_builtin_traits)]` to the crate attributes to enable

error[E0658]: negative trait bounds are not yet fully implemented; use marker types for now
--> $DIR/feature-gate-optin-builtin-traits.rs:18:10
|
LL | impl !AutoDummyTrait for DummyStruct {}
| ^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/13231
= help: add `#![feature(optin_builtin_traits)]` to the crate attributes to enable

error: aborting due to 2 previous errors
error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0658`.
4 changes: 2 additions & 2 deletions src/test/ui/syntax-trait-polarity-feature-gate.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0658]: negative trait bounds are not yet fully implemented; use marker types for now
--> $DIR/syntax-trait-polarity-feature-gate.rs:7:1
--> $DIR/syntax-trait-polarity-feature-gate.rs:7:6
|
LL | impl !Send for TestType {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/13231
= help: add `#![feature(optin_builtin_traits)]` to the crate attributes to enable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ LL | trait D: = Eq;
| ^

error: aborting due to 4 previous errors