@@ -3551,6 +3551,7 @@ impl Item {
35513551 pub fn opt_generics ( & self ) -> Option < & Generics > {
35523552 match & self . kind {
35533553 ItemKind :: ExternCrate ( ..)
3554+ | ItemKind :: ConstBlock ( _)
35543555 | ItemKind :: Use ( _)
35553556 | ItemKind :: Mod ( ..)
35563557 | ItemKind :: ForeignMod ( _)
@@ -3792,6 +3793,15 @@ impl ConstItemRhs {
37923793 }
37933794}
37943795
3796+ #[ derive( Clone , Encodable , Decodable , Debug , Walkable ) ]
3797+ pub struct ConstBlockItem {
3798+ pub body : Box < Expr > ,
3799+ }
3800+
3801+ impl ConstBlockItem {
3802+ pub const IDENT : Ident = Ident { name : kw:: Underscore , span : DUMMY_SP } ;
3803+ }
3804+
37953805// Adding a new variant? Please update `test_item` in `tests/ui/macros/stringify.rs`.
37963806#[ derive( Clone , Encodable , Decodable , Debug ) ]
37973807pub enum ItemKind {
@@ -3811,6 +3821,11 @@ pub enum ItemKind {
38113821 ///
38123822 /// E.g., `const FOO: i32 = 42;`.
38133823 Const ( Box < ConstItem > ) ,
3824+ /// A module-level const block.
3825+ /// Equivalent to `const _: () = const { ... }`.
3826+ ///
3827+ /// E.g., `const { assert!(true) }`.
3828+ ConstBlock ( ConstBlockItem ) ,
38143829 /// A function declaration (`fn`).
38153830 ///
38163831 /// E.g., `fn foo(bar: usize) -> usize { .. }`.
@@ -3887,6 +3902,8 @@ impl ItemKind {
38873902 | ItemKind :: MacroDef ( ident, _)
38883903 | ItemKind :: Delegation ( box Delegation { ident, .. } ) => Some ( ident) ,
38893904
3905+ ItemKind :: ConstBlock ( _) => Some ( ConstBlockItem :: IDENT ) ,
3906+
38903907 ItemKind :: Use ( _)
38913908 | ItemKind :: ForeignMod ( _)
38923909 | ItemKind :: GlobalAsm ( _)
@@ -3900,9 +3917,9 @@ impl ItemKind {
39003917 pub fn article ( & self ) -> & ' static str {
39013918 use ItemKind :: * ;
39023919 match self {
3903- Use ( ..) | Static ( ..) | Const ( ..) | Fn ( ..) | Mod ( ..) | GlobalAsm ( .. ) | TyAlias ( ..)
3904- | Struct ( ..) | Union ( ..) | Trait ( ..) | TraitAlias ( ..) | MacroDef ( ..)
3905- | Delegation ( ..) | DelegationMac ( ..) => "a" ,
3920+ Use ( ..) | Static ( ..) | Const ( ..) | ConstBlock ( ..) | Fn ( ..) | Mod ( ..)
3921+ | GlobalAsm ( ..) | TyAlias ( ..) | Struct ( ..) | Union ( ..) | Trait ( .. ) | TraitAlias ( ..)
3922+ | MacroDef ( .. ) | Delegation ( ..) | DelegationMac ( ..) => "a" ,
39063923 ExternCrate ( ..) | ForeignMod ( ..) | MacCall ( ..) | Enum ( ..) | Impl { .. } => "an" ,
39073924 }
39083925 }
@@ -3913,6 +3930,7 @@ impl ItemKind {
39133930 ItemKind :: Use ( ..) => "`use` import" ,
39143931 ItemKind :: Static ( ..) => "static item" ,
39153932 ItemKind :: Const ( ..) => "constant item" ,
3933+ ItemKind :: ConstBlock ( ..) => "const block" ,
39163934 ItemKind :: Fn ( ..) => "function" ,
39173935 ItemKind :: Mod ( ..) => "module" ,
39183936 ItemKind :: ForeignMod ( ..) => "extern block" ,
@@ -3942,7 +3960,18 @@ impl ItemKind {
39423960 | Self :: Trait ( box Trait { generics, .. } )
39433961 | Self :: TraitAlias ( box TraitAlias { generics, .. } )
39443962 | Self :: Impl ( Impl { generics, .. } ) => Some ( generics) ,
3945- _ => None ,
3963+
3964+ Self :: ExternCrate ( ..)
3965+ | Self :: Use ( ..)
3966+ | Self :: Static ( ..)
3967+ | Self :: ConstBlock ( ..)
3968+ | Self :: Mod ( ..)
3969+ | Self :: ForeignMod ( ..)
3970+ | Self :: GlobalAsm ( ..)
3971+ | Self :: MacCall ( ..)
3972+ | Self :: MacroDef ( ..)
3973+ | Self :: Delegation ( ..)
3974+ | Self :: DelegationMac ( ..) => None ,
39463975 }
39473976 }
39483977}
0 commit comments