@@ -3626,6 +3626,7 @@ impl Item {
36263626 pub fn opt_generics ( & self ) -> Option < & Generics > {
36273627 match & self . kind {
36283628 ItemKind :: ExternCrate ( ..)
3629+ | ItemKind :: ConstBlock ( _)
36293630 | ItemKind :: Use ( _)
36303631 | ItemKind :: Mod ( ..)
36313632 | ItemKind :: ForeignMod ( _)
@@ -3895,6 +3896,17 @@ impl ConstItemRhs {
38953896 }
38963897}
38973898
3899+ #[ derive( Clone , Encodable , Decodable , Debug , Walkable ) ]
3900+ pub struct ConstBlockItem {
3901+ pub id : NodeId ,
3902+ pub span : Span ,
3903+ pub block : Box < Block > ,
3904+ }
3905+
3906+ impl ConstBlockItem {
3907+ pub const IDENT : Ident = Ident { name : kw:: Underscore , span : DUMMY_SP } ;
3908+ }
3909+
38983910// Adding a new variant? Please update `test_item` in `tests/ui/macros/stringify.rs`.
38993911#[ derive( Clone , Encodable , Decodable , Debug ) ]
39003912pub enum ItemKind {
@@ -3914,6 +3926,11 @@ pub enum ItemKind {
39143926 ///
39153927 /// E.g., `const FOO: i32 = 42;`.
39163928 Const ( Box < ConstItem > ) ,
3929+ /// A module-level const block.
3930+ /// Equivalent to `const _: () = const { ... };`.
3931+ ///
3932+ /// E.g., `const { assert!(true) }`.
3933+ ConstBlock ( ConstBlockItem ) ,
39173934 /// A function declaration (`fn`).
39183935 ///
39193936 /// E.g., `fn foo(bar: usize) -> usize { .. }`.
@@ -3990,6 +4007,8 @@ impl ItemKind {
39904007 | ItemKind :: MacroDef ( ident, _)
39914008 | ItemKind :: Delegation ( box Delegation { ident, .. } ) => Some ( ident) ,
39924009
4010+ ItemKind :: ConstBlock ( _) => Some ( ConstBlockItem :: IDENT ) ,
4011+
39934012 ItemKind :: Use ( _)
39944013 | ItemKind :: ForeignMod ( _)
39954014 | ItemKind :: GlobalAsm ( _)
@@ -4003,9 +4022,9 @@ impl ItemKind {
40034022 pub fn article ( & self ) -> & ' static str {
40044023 use ItemKind :: * ;
40054024 match self {
4006- Use ( ..) | Static ( ..) | Const ( ..) | Fn ( ..) | Mod ( ..) | GlobalAsm ( .. ) | TyAlias ( ..)
4007- | Struct ( ..) | Union ( ..) | Trait ( ..) | TraitAlias ( ..) | MacroDef ( ..)
4008- | Delegation ( ..) | DelegationMac ( ..) => "a" ,
4025+ Use ( ..) | Static ( ..) | Const ( ..) | ConstBlock ( ..) | Fn ( ..) | Mod ( ..)
4026+ | GlobalAsm ( ..) | TyAlias ( ..) | Struct ( ..) | Union ( ..) | Trait ( .. ) | TraitAlias ( ..)
4027+ | MacroDef ( .. ) | Delegation ( ..) | DelegationMac ( ..) => "a" ,
40094028 ExternCrate ( ..) | ForeignMod ( ..) | MacCall ( ..) | Enum ( ..) | Impl { .. } => "an" ,
40104029 }
40114030 }
@@ -4016,6 +4035,7 @@ impl ItemKind {
40164035 ItemKind :: Use ( ..) => "`use` import" ,
40174036 ItemKind :: Static ( ..) => "static item" ,
40184037 ItemKind :: Const ( ..) => "constant item" ,
4038+ ItemKind :: ConstBlock ( ..) => "const block" ,
40194039 ItemKind :: Fn ( ..) => "function" ,
40204040 ItemKind :: Mod ( ..) => "module" ,
40214041 ItemKind :: ForeignMod ( ..) => "extern block" ,
@@ -4045,7 +4065,18 @@ impl ItemKind {
40454065 | Self :: Trait ( box Trait { generics, .. } )
40464066 | Self :: TraitAlias ( box TraitAlias { generics, .. } )
40474067 | Self :: Impl ( Impl { generics, .. } ) => Some ( generics) ,
4048- _ => None ,
4068+
4069+ Self :: ExternCrate ( ..)
4070+ | Self :: Use ( ..)
4071+ | Self :: Static ( ..)
4072+ | Self :: ConstBlock ( ..)
4073+ | Self :: Mod ( ..)
4074+ | Self :: ForeignMod ( ..)
4075+ | Self :: GlobalAsm ( ..)
4076+ | Self :: MacCall ( ..)
4077+ | Self :: MacroDef ( ..)
4078+ | Self :: Delegation ( ..)
4079+ | Self :: DelegationMac ( ..) => None ,
40494080 }
40504081 }
40514082}
0 commit comments