Gate against auto traits pre-expansion

This commit is contained in:
Michael Goulet 2023-10-03 19:06:17 +00:00
parent 5333b878c8
commit 7815641be0
5 changed files with 29 additions and 1 deletions

View file

@ -603,6 +603,7 @@ macro_rules! gate_all_legacy_dont_use {
"exclusive range pattern syntax is experimental"
);
gate_all_legacy_dont_use!(try_blocks, "`try` blocks are unstable");
gate_all_legacy_dont_use!(auto_traits, "`auto` traits are unstable");
visit::walk_crate(&mut visitor, krate);
}

View file

@ -813,7 +813,12 @@ fn check_auto_or_unsafe_trait_item(&mut self) -> bool {
fn parse_item_trait(&mut self, attrs: &mut AttrVec, lo: Span) -> PResult<'a, ItemInfo> {
let unsafety = self.parse_unsafety(Case::Sensitive);
// Parse optional `auto` prefix.
let is_auto = if self.eat_keyword(kw::Auto) { IsAuto::Yes } else { IsAuto::No };
let is_auto = if self.eat_keyword(kw::Auto) {
self.sess.gated_spans.gate(sym::auto_traits, self.prev_token.span);
IsAuto::Yes
} else {
IsAuto::No
};
self.expect_keyword(kw::Trait)?;
let ident = self.parse_ident()?;

View file

@ -0,0 +1,8 @@
// check-pass
#[cfg(FALSE)]
auto trait Foo {}
//~^ WARN `auto` traits are unstable
//~| WARN unstable syntax can change at any point in the future, causing a hard error!
fn main() {}

View file

@ -0,0 +1,13 @@
warning: `auto` traits are unstable
--> $DIR/pre-cfg.rs:4:1
|
LL | auto trait Foo {}
| ^^^^
|
= note: see issue #13231 <https://github.com/rust-lang/rust/issues/13231> for more information
= help: add `#![feature(auto_traits)]` to the crate attributes to enable
= warning: unstable syntax can change at any point in the future, causing a hard error!
= note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860>
warning: 1 warning emitted

View file

@ -3,6 +3,7 @@
// compile-flags: --test
#![feature(async_closure)]
#![feature(auto_traits)]
#![feature(box_patterns)]
#![feature(const_trait_impl)]
#![feature(decl_macro)]