Gate all usages of dyn*, even in macros

This commit is contained in:
Michael Goulet 2023-03-11 21:18:45 +00:00
parent 8a73f50d87
commit bd4355500a
8 changed files with 32 additions and 12 deletions

View File

@ -337,9 +337,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
ast::TyKind::Never => { ast::TyKind::Never => {
gate_feature_post!(&self, never_type, ty.span, "the `!` type is experimental"); gate_feature_post!(&self, never_type, ty.span, "the `!` type is experimental");
} }
ast::TyKind::TraitObject(_, ast::TraitObjectSyntax::DynStar, ..) => {
gate_feature_post!(&self, dyn_star, ty.span, "dyn* trait objects are unstable");
}
_ => {} _ => {}
} }
visit::walk_ty(self, ty) visit::walk_ty(self, ty)
@ -594,6 +591,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
gate_all!(inline_const_pat, "inline-const in pattern position is experimental"); gate_all!(inline_const_pat, "inline-const in pattern position is experimental");
gate_all!(associated_const_equality, "associated const equality is incomplete"); gate_all!(associated_const_equality, "associated const equality is incomplete");
gate_all!(yeet_expr, "`do yeet` expression is experimental"); gate_all!(yeet_expr, "`do yeet` expression is experimental");
gate_all!(dyn_star, "`dyn*` trait objects are experimental");
// All uses of `gate_all!` below this point were added in #65742, // All uses of `gate_all!` below this point were added in #65742,
// and subsequently disabled (with the non-early gating readded). // and subsequently disabled (with the non-early gating readded).

View File

@ -624,10 +624,12 @@ impl<'a> Parser<'a> {
/// ///
/// Note that this does *not* parse bare trait objects. /// Note that this does *not* parse bare trait objects.
fn parse_dyn_ty(&mut self, impl_dyn_multi: &mut bool) -> PResult<'a, TyKind> { fn parse_dyn_ty(&mut self, impl_dyn_multi: &mut bool) -> PResult<'a, TyKind> {
let lo = self.token.span;
self.bump(); // `dyn` self.bump(); // `dyn`
// parse dyn* types // parse dyn* types
let syntax = if self.eat(&TokenKind::BinOp(token::Star)) { let syntax = if self.eat(&TokenKind::BinOp(token::Star)) {
self.sess.gated_spans.gate(sym::dyn_star, lo.to(self.prev_token.span));
TraitObjectSyntax::DynStar TraitObjectSyntax::DynStar
} else { } else {
TraitObjectSyntax::Dyn TraitObjectSyntax::Dyn

View File

@ -3,7 +3,7 @@
/// dyn* is not necessarily the final surface syntax (if we have one at all), /// dyn* is not necessarily the final surface syntax (if we have one at all),
/// but for now we will support it to aid in writing tests independently. /// but for now we will support it to aid in writing tests independently.
pub fn dyn_star_parameter(_: &dyn* Send) { pub fn dyn_star_parameter(_: &dyn* Send) {
//~^ dyn* trait objects are unstable //~^ `dyn*` trait objects are experimental
} }
fn main() {} fn main() {}

View File

@ -1,8 +1,8 @@
error[E0658]: dyn* trait objects are unstable error[E0658]: `dyn*` trait objects are experimental
--> $DIR/feature-gate-dyn_star.rs:5:31 --> $DIR/feature-gate-dyn_star.rs:5:31
| |
LL | pub fn dyn_star_parameter(_: &dyn* Send) { LL | pub fn dyn_star_parameter(_: &dyn* Send) {
| ^^^^^^^^^ | ^^^^
| |
= note: see issue #102425 <https://github.com/rust-lang/rust/issues/102425> for more information = note: see issue #102425 <https://github.com/rust-lang/rust/issues/102425> for more information
= help: add `#![feature(dyn_star)]` to the crate attributes to enable = help: add `#![feature(dyn_star)]` to the crate attributes to enable

View File

@ -0,0 +1,8 @@
macro_rules! t {
($t:ty) => {}
}
t!(dyn* Send);
//~^ ERROR `dyn*` trait objects are experimental
fn main() {}

View File

@ -0,0 +1,12 @@
error[E0658]: `dyn*` trait objects are experimental
--> $DIR/gated-span.rs:5:4
|
LL | t!(dyn* Send);
| ^^^^
|
= note: see issue #102425 <https://github.com/rust-lang/rust/issues/102425> for more information
= help: add `#![feature(dyn_star)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View File

@ -4,8 +4,8 @@ fn make_dyn_star() {
let i = 42usize; let i = 42usize;
let dyn_i: dyn* Debug = i as dyn* Debug; let dyn_i: dyn* Debug = i as dyn* Debug;
//~^ ERROR casting `usize` as `dyn* Debug` is invalid //~^ ERROR casting `usize` as `dyn* Debug` is invalid
//~| ERROR dyn* trait objects are unstable //~| ERROR `dyn*` trait objects are experimental
//~| ERROR dyn* trait objects are unstable //~| ERROR `dyn*` trait objects are experimental
} }
fn main() { fn main() {

View File

@ -1,17 +1,17 @@
error[E0658]: dyn* trait objects are unstable error[E0658]: `dyn*` trait objects are experimental
--> $DIR/no-explicit-dyn-star-cast.rs:5:16 --> $DIR/no-explicit-dyn-star-cast.rs:5:16
| |
LL | let dyn_i: dyn* Debug = i as dyn* Debug; LL | let dyn_i: dyn* Debug = i as dyn* Debug;
| ^^^^^^^^^^ | ^^^^
| |
= note: see issue #102425 <https://github.com/rust-lang/rust/issues/102425> for more information = note: see issue #102425 <https://github.com/rust-lang/rust/issues/102425> for more information
= help: add `#![feature(dyn_star)]` to the crate attributes to enable = help: add `#![feature(dyn_star)]` to the crate attributes to enable
error[E0658]: dyn* trait objects are unstable error[E0658]: `dyn*` trait objects are experimental
--> $DIR/no-explicit-dyn-star-cast.rs:5:34 --> $DIR/no-explicit-dyn-star-cast.rs:5:34
| |
LL | let dyn_i: dyn* Debug = i as dyn* Debug; LL | let dyn_i: dyn* Debug = i as dyn* Debug;
| ^^^^^^^^^^ | ^^^^
| |
= note: see issue #102425 <https://github.com/rust-lang/rust/issues/102425> for more information = note: see issue #102425 <https://github.com/rust-lang/rust/issues/102425> for more information
= help: add `#![feature(dyn_star)]` to the crate attributes to enable = help: add `#![feature(dyn_star)]` to the crate attributes to enable