Skip to content

Commit 7815641

Browse files
Gate against auto traits pre-expansion
1 parent 5333b87 commit 7815641

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

Diff for: compiler/rustc_ast_passes/src/feature_gate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
603603
"exclusive range pattern syntax is experimental"
604604
);
605605
gate_all_legacy_dont_use!(try_blocks, "`try` blocks are unstable");
606+
gate_all_legacy_dont_use!(auto_traits, "`auto` traits are unstable");
606607

607608
visit::walk_crate(&mut visitor, krate);
608609
}

Diff for: compiler/rustc_parse/src/parser/item.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,12 @@ impl<'a> Parser<'a> {
813813
fn parse_item_trait(&mut self, attrs: &mut AttrVec, lo: Span) -> PResult<'a, ItemInfo> {
814814
let unsafety = self.parse_unsafety(Case::Sensitive);
815815
// Parse optional `auto` prefix.
816-
let is_auto = if self.eat_keyword(kw::Auto) { IsAuto::Yes } else { IsAuto::No };
816+
let is_auto = if self.eat_keyword(kw::Auto) {
817+
self.sess.gated_spans.gate(sym::auto_traits, self.prev_token.span);
818+
IsAuto::Yes
819+
} else {
820+
IsAuto::No
821+
};
817822

818823
self.expect_keyword(kw::Trait)?;
819824
let ident = self.parse_ident()?;

Diff for: tests/ui/auto-traits/pre-cfg.rs

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

Diff for: tests/ui/auto-traits/pre-cfg.stderr

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

Diff for: tests/ui/macros/stringify.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// compile-flags: --test
44

55
#![feature(async_closure)]
6+
#![feature(auto_traits)]
67
#![feature(box_patterns)]
78
#![feature(const_trait_impl)]
89
#![feature(decl_macro)]

0 commit comments

Comments
 (0)