diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index a21d19b6d3a20..bdcbb1eb42a88 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -1749,6 +1749,9 @@ impl<'a> Parser<'a> { } else { // Parsing a pattern of the form `(box) (ref) (mut) fieldname`. let is_box = self.eat_keyword(exp!(Box)); + if is_box { + self.psess.gated_spans.gate(sym::box_patterns, self.prev_token.span); + } let boxed_span = self.token.span; let mutability = self.parse_mutability(); let by_ref = self.parse_byref(); diff --git a/tests/ui/auto-traits/pre-cfg.rs b/tests/ui/auto-traits/pre-cfg.rs deleted file mode 100644 index 4820a53535803..0000000000000 --- a/tests/ui/auto-traits/pre-cfg.rs +++ /dev/null @@ -1,8 +0,0 @@ -//@ 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() {} diff --git a/tests/ui/feature-gates/feature-gate-box_patterns.rs b/tests/ui/feature-gates/feature-gate-box_patterns.rs index 8bec16a974e80..9ff6604c95206 100644 --- a/tests/ui/feature-gates/feature-gate-box_patterns.rs +++ b/tests/ui/feature-gates/feature-gate-box_patterns.rs @@ -1,4 +1,9 @@ fn main() { let box x = Box::new('c'); //~ ERROR box pattern syntax is experimental - println!("x: {}", x); + let _: char = x; + + struct Packet { x: Box } + + let Packet { box x } = Packet { x: Box::new(0) }; //~ ERROR box pattern syntax is experimental + let _: i32 = x; } diff --git a/tests/ui/feature-gates/feature-gate-box_patterns.stderr b/tests/ui/feature-gates/feature-gate-box_patterns.stderr index fb61b2b1810a3..6f5ee20925eea 100644 --- a/tests/ui/feature-gates/feature-gate-box_patterns.stderr +++ b/tests/ui/feature-gates/feature-gate-box_patterns.stderr @@ -8,6 +8,16 @@ LL | let box x = Box::new('c'); = help: add `#![feature(box_patterns)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: aborting due to 1 previous error +error[E0658]: box pattern syntax is experimental + --> $DIR/feature-gate-box_patterns.rs:7:18 + | +LL | let Packet { box x } = Packet { x: Box::new(0) }; + | ^^^^^ + | + = note: see issue #29641 for more information + = help: add `#![feature(box_patterns)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/feature-gates/soft-feature-gate-auto_traits.rs b/tests/ui/feature-gates/soft-feature-gate-auto_traits.rs new file mode 100644 index 0000000000000..0ccbaf1e476a9 --- /dev/null +++ b/tests/ui/feature-gates/soft-feature-gate-auto_traits.rs @@ -0,0 +1,12 @@ +// For historical reasons, auto traits don't have a proper pre-expansion feature gate. +// We're now at least issuing a *warning* for those that only exist before macro expansion. +// FIXME(#154045): Turn their post-expansion feature gate into a proper pre-expansion one. +// As part of this, move these test cases into `feature-gate-auto-traits.rs`. +//@ check-pass + +#[cfg(false)] +auto trait Foo {} +//~^ WARN `auto` traits are unstable +//~| WARN unstable syntax can change at any point in the future + +fn main() {} diff --git a/tests/ui/auto-traits/pre-cfg.stderr b/tests/ui/feature-gates/soft-feature-gate-auto_traits.stderr similarity index 92% rename from tests/ui/auto-traits/pre-cfg.stderr rename to tests/ui/feature-gates/soft-feature-gate-auto_traits.stderr index 648f9464d61df..20811aadda929 100644 --- a/tests/ui/auto-traits/pre-cfg.stderr +++ b/tests/ui/feature-gates/soft-feature-gate-auto_traits.stderr @@ -1,5 +1,5 @@ warning: `auto` traits are unstable - --> $DIR/pre-cfg.rs:4:1 + --> $DIR/soft-feature-gate-auto_traits.rs:8:1 | LL | auto trait Foo {} | ^^^^ diff --git a/tests/ui/feature-gates/soft-feature-gate-box_patterns.rs b/tests/ui/feature-gates/soft-feature-gate-box_patterns.rs new file mode 100644 index 0000000000000..8ab0e80e6be31 --- /dev/null +++ b/tests/ui/feature-gates/soft-feature-gate-box_patterns.rs @@ -0,0 +1,17 @@ +// For historical reasons, box patterns don't have a proper pre-expansion feature gate. +// We're now at least issuing a *warning* for those that only exist before macro expansion. +// FIXME(#154045): Turn their post-expansion feature gate into a proper pre-expansion one. +// As part of this, move these test cases into `feature-gate-box_patterns.rs`. +//@ check-pass + +fn main() { + #[cfg(false)] + let box x; + //~^ WARN box pattern syntax is experimental + //~| WARN unstable syntax can change at any point in the future + + #[cfg(false)] + let Packet { box x }; + //~^ WARN box pattern syntax is experimental + //~| WARN unstable syntax can change at any point in the future +} diff --git a/tests/ui/feature-gates/soft-feature-gate-box_patterns.stderr b/tests/ui/feature-gates/soft-feature-gate-box_patterns.stderr new file mode 100644 index 0000000000000..a8399b5f01f88 --- /dev/null +++ b/tests/ui/feature-gates/soft-feature-gate-box_patterns.stderr @@ -0,0 +1,26 @@ +warning: box pattern syntax is experimental + --> $DIR/soft-feature-gate-box_patterns.rs:9:9 + | +LL | let box x; + | ^^^^^ + | + = note: see issue #29641 for more information + = help: add `#![feature(box_patterns)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + = warning: unstable syntax can change at any point in the future, causing a hard error! + = note: for more information, see issue #65860 + +warning: box pattern syntax is experimental + --> $DIR/soft-feature-gate-box_patterns.rs:14:18 + | +LL | let Packet { box x }; + | ^^^ + | + = note: see issue #29641 for more information + = help: add `#![feature(box_patterns)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + = warning: unstable syntax can change at any point in the future, causing a hard error! + = note: for more information, see issue #65860 + +warning: 2 warnings emitted + diff --git a/tests/ui/feature-gates/soft-feature-gate-decl_macro.rs b/tests/ui/feature-gates/soft-feature-gate-decl_macro.rs new file mode 100644 index 0000000000000..7d2d48503797a --- /dev/null +++ b/tests/ui/feature-gates/soft-feature-gate-decl_macro.rs @@ -0,0 +1,17 @@ +// For historical reasons, decl macros 2.0 don't have a proper pre-expansion feature gate. +// We're now at least issuing a *warning* for those that only exist before macro expansion. +// FIXME(#154045): Turn their post-expansion feature gate into a proper pre-expansion one. +// As part of this, move these test cases into `feature-gate-decl_macro.rs`. +//@ check-pass + +#[cfg(false)] +macro make() {} +//~^ WARN `macro` is experimental +//~| WARN unstable syntax can change at any point in the future + +#[cfg(false)] +macro create { () => {} } +//~^ WARN `macro` is experimental +//~| WARN unstable syntax can change at any point in the future + +fn main() {} diff --git a/tests/ui/feature-gates/soft-feature-gate-decl_macro.stderr b/tests/ui/feature-gates/soft-feature-gate-decl_macro.stderr new file mode 100644 index 0000000000000..71521626f69bc --- /dev/null +++ b/tests/ui/feature-gates/soft-feature-gate-decl_macro.stderr @@ -0,0 +1,26 @@ +warning: `macro` is experimental + --> $DIR/soft-feature-gate-decl_macro.rs:8:1 + | +LL | macro make() {} + | ^^^^^^^^^^^^^^^ + | + = note: see issue #39412 for more information + = help: add `#![feature(decl_macro)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + = warning: unstable syntax can change at any point in the future, causing a hard error! + = note: for more information, see issue #65860 + +warning: `macro` is experimental + --> $DIR/soft-feature-gate-decl_macro.rs:13:1 + | +LL | macro create { () => {} } + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #39412 for more information + = help: add `#![feature(decl_macro)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + = warning: unstable syntax can change at any point in the future, causing a hard error! + = note: for more information, see issue #65860 + +warning: 2 warnings emitted + diff --git a/tests/ui/feature-gates/soft-feature-gate-trait_alias.rs b/tests/ui/feature-gates/soft-feature-gate-trait_alias.rs new file mode 100644 index 0000000000000..553e88375a2a7 --- /dev/null +++ b/tests/ui/feature-gates/soft-feature-gate-trait_alias.rs @@ -0,0 +1,17 @@ +// For historical reasons, trait aliases don't have a proper pre-expansion feature gate. +// We're now at least issuing a *warning* for those that only exist before macro expansion. +// FIXME(#154045): Turn their post-expansion feature gate into a proper pre-expansion one. +// As part of this, move these test cases into `feature-gate-trait-alias.rs`. +//@ check-pass + +#[cfg(false)] +trait Trait =; +//~^ WARN trait aliases are experimental +//~| WARN unstable syntax can change at any point in the future + +#[cfg(false)] +trait Trait = Bound where T: Bound; +//~^ WARN trait aliases are experimental +//~| WARN unstable syntax can change at any point in the future + +fn main() {} diff --git a/tests/ui/feature-gates/soft-feature-gate-trait_alias.stderr b/tests/ui/feature-gates/soft-feature-gate-trait_alias.stderr new file mode 100644 index 0000000000000..e50d4c36d1228 --- /dev/null +++ b/tests/ui/feature-gates/soft-feature-gate-trait_alias.stderr @@ -0,0 +1,26 @@ +warning: trait aliases are experimental + --> $DIR/soft-feature-gate-trait_alias.rs:8:1 + | +LL | trait Trait =; + | ^^^^^^^^^^^^^^ + | + = note: see issue #41517 for more information + = help: add `#![feature(trait_alias)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + = warning: unstable syntax can change at any point in the future, causing a hard error! + = note: for more information, see issue #65860 + +warning: trait aliases are experimental + --> $DIR/soft-feature-gate-trait_alias.rs:13:1 + | +LL | trait Trait = Bound where T: Bound; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #41517 for more information + = help: add `#![feature(trait_alias)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + = warning: unstable syntax can change at any point in the future, causing a hard error! + = note: for more information, see issue #65860 + +warning: 2 warnings emitted + diff --git a/tests/ui/feature-gates/soft-feature-gate-try_blocks.rs b/tests/ui/feature-gates/soft-feature-gate-try_blocks.rs new file mode 100644 index 0000000000000..aa51e60d56b4a --- /dev/null +++ b/tests/ui/feature-gates/soft-feature-gate-try_blocks.rs @@ -0,0 +1,13 @@ +// For historical reasons, try blocks don't have a proper pre-expansion feature gate. +// We're now at least issuing a *warning* for those that only exist before macro expansion. +// FIXME(#154045): Turn their post-expansion feature gate into a proper pre-expansion one. +// As part of this, move these test cases into `feature-gate-try_blocks.rs`. +//@ edition: 2018 +//@ check-pass + +fn main() { + #[cfg(false)] + try {} + //~^ WARN `try` blocks are unstable + //~| WARN unstable syntax can change at any point +} diff --git a/tests/ui/try-block/try-block-homogeneous-pre-expansion.stderr b/tests/ui/feature-gates/soft-feature-gate-try_blocks.stderr similarity index 91% rename from tests/ui/try-block/try-block-homogeneous-pre-expansion.stderr rename to tests/ui/feature-gates/soft-feature-gate-try_blocks.stderr index 67cbcb42fb479..2b20f40e09d07 100644 --- a/tests/ui/try-block/try-block-homogeneous-pre-expansion.stderr +++ b/tests/ui/feature-gates/soft-feature-gate-try_blocks.stderr @@ -1,5 +1,5 @@ warning: `try` blocks are unstable - --> $DIR/try-block-homogeneous-pre-expansion.rs:9:5 + --> $DIR/soft-feature-gate-try_blocks.rs:10:5 | LL | try {} | ^^^^^^ diff --git a/tests/ui/try-block/try-block-homogeneous-pre-expansion.rs b/tests/ui/try-block/try-block-homogeneous-pre-expansion.rs deleted file mode 100644 index 980f97ca0672e..0000000000000 --- a/tests/ui/try-block/try-block-homogeneous-pre-expansion.rs +++ /dev/null @@ -1,12 +0,0 @@ -//@ check-pass -//@ edition: 2018 - -// For historical reasons this is only a warning, not an error. -// See - -fn main() { - #[cfg(false)] - try {} - //~^ warn `try` blocks are unstable - //~| warn unstable syntax can change at any point -}