@@ -3564,6 +3564,7 @@ impl Item {
35643564 pub fn opt_generics ( & self ) -> Option < & Generics > {
35653565 match & self . kind {
35663566 ItemKind :: ExternCrate ( ..)
3567+ | ItemKind :: ConstBlock ( _)
35673568 | ItemKind :: Use ( _)
35683569 | ItemKind :: Mod ( ..)
35693570 | ItemKind :: ForeignMod ( _)
@@ -3805,6 +3806,15 @@ impl ConstItemRhs {
38053806 }
38063807}
38073808
3809+ #[ derive( Clone , Encodable , Decodable , Debug , Walkable ) ]
3810+ pub struct ConstBlockItem {
3811+ pub body : Box < Expr > ,
3812+ }
3813+
3814+ impl ConstBlockItem {
3815+ pub const IDENT : Ident = Ident { name : kw:: Underscore , span : DUMMY_SP } ;
3816+ }
3817+
38083818// Adding a new variant? Please update `test_item` in `tests/ui/macros/stringify.rs`.
38093819#[ derive( Clone , Encodable , Decodable , Debug ) ]
38103820pub enum ItemKind {
@@ -3824,6 +3834,11 @@ pub enum ItemKind {
38243834 ///
38253835 /// E.g., `const FOO: i32 = 42;`.
38263836 Const ( Box < ConstItem > ) ,
3837+ /// A module-level const block.
3838+ /// Equivalent to `const _: () = const { ... }`.
3839+ ///
3840+ /// E.g., `const { assert!(true) }`.
3841+ ConstBlock ( ConstBlockItem ) ,
38273842 /// A function declaration (`fn`).
38283843 ///
38293844 /// E.g., `fn foo(bar: usize) -> usize { .. }`.
@@ -3900,6 +3915,8 @@ impl ItemKind {
39003915 | ItemKind :: MacroDef ( ident, _)
39013916 | ItemKind :: Delegation ( box Delegation { ident, .. } ) => Some ( ident) ,
39023917
3918+ ItemKind :: ConstBlock ( _) => Some ( ConstBlockItem :: IDENT ) ,
3919+
39033920 ItemKind :: Use ( _)
39043921 | ItemKind :: ForeignMod ( _)
39053922 | ItemKind :: GlobalAsm ( _)
@@ -3913,9 +3930,9 @@ impl ItemKind {
39133930 pub fn article ( & self ) -> & ' static str {
39143931 use ItemKind :: * ;
39153932 match self {
3916- Use ( ..) | Static ( ..) | Const ( ..) | Fn ( ..) | Mod ( ..) | GlobalAsm ( .. ) | TyAlias ( ..)
3917- | Struct ( ..) | Union ( ..) | Trait ( ..) | TraitAlias ( ..) | MacroDef ( ..)
3918- | Delegation ( ..) | DelegationMac ( ..) => "a" ,
3933+ Use ( ..) | Static ( ..) | Const ( ..) | ConstBlock ( ..) | Fn ( ..) | Mod ( ..)
3934+ | GlobalAsm ( ..) | TyAlias ( ..) | Struct ( ..) | Union ( ..) | Trait ( .. ) | TraitAlias ( ..)
3935+ | MacroDef ( .. ) | Delegation ( ..) | DelegationMac ( ..) => "a" ,
39193936 ExternCrate ( ..) | ForeignMod ( ..) | MacCall ( ..) | Enum ( ..) | Impl { .. } => "an" ,
39203937 }
39213938 }
@@ -3926,6 +3943,7 @@ impl ItemKind {
39263943 ItemKind :: Use ( ..) => "`use` import" ,
39273944 ItemKind :: Static ( ..) => "static item" ,
39283945 ItemKind :: Const ( ..) => "constant item" ,
3946+ ItemKind :: ConstBlock ( ..) => "const block" ,
39293947 ItemKind :: Fn ( ..) => "function" ,
39303948 ItemKind :: Mod ( ..) => "module" ,
39313949 ItemKind :: ForeignMod ( ..) => "extern block" ,
@@ -3955,7 +3973,18 @@ impl ItemKind {
39553973 | Self :: Trait ( box Trait { generics, .. } )
39563974 | Self :: TraitAlias ( box TraitAlias { generics, .. } )
39573975 | Self :: Impl ( Impl { generics, .. } ) => Some ( generics) ,
3958- _ => None ,
3976+
3977+ Self :: ExternCrate ( ..)
3978+ | Self :: Use ( ..)
3979+ | Self :: Static ( ..)
3980+ | Self :: ConstBlock ( ..)
3981+ | Self :: Mod ( ..)
3982+ | Self :: ForeignMod ( ..)
3983+ | Self :: GlobalAsm ( ..)
3984+ | Self :: MacCall ( ..)
3985+ | Self :: MacroDef ( ..)
3986+ | Self :: Delegation ( ..)
3987+ | Self :: DelegationMac ( ..) => None ,
39593988 }
39603989 }
39613990}
0 commit comments