Skip to content

Commit

Permalink
Unrolled build for rust-lang#116393
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#116393 - compiler-errors:auto-bad, r=WaffleLapkin

Emit feature gate *warning* for `auto` traits pre-expansion

Auto traits were introduced before we were more careful about not stabilizing new syntax pre-expansion.

This is a more conservative step in the general direction we want to go in https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Removal.20of.20.60auto.20trait.60.20syntax.

Fixes rust-lang#116121
  • Loading branch information
rust-timer authored Oct 4, 2023
2 parents 4910642 + 7815641 commit a1a82f3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
"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);
}
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,12 @@ impl<'a> Parser<'a> {
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()?;
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/auto-traits/pre-cfg.rs
Original file line number Diff line number Diff line change
@@ -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() {}
13 changes: 13 additions & 0 deletions tests/ui/auto-traits/pre-cfg.stderr
Original file line number Diff line number Diff line change
@@ -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

1 change: 1 addition & 0 deletions tests/ui/macros/stringify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// compile-flags: --test

#![feature(async_closure)]
#![feature(auto_traits)]
#![feature(box_patterns)]
#![feature(const_trait_impl)]
#![feature(decl_macro)]
Expand Down

0 comments on commit a1a82f3

Please sign in to comment.