@@ -1675,6 +1675,14 @@ pub struct AnonConst {
16751675 pub body : BodyId ,
16761676}
16771677
1678+ /// An inline constant expression `const { something }`.
1679+ #[ derive( Copy , Clone , Debug , HashStable_Generic ) ]
1680+ pub struct ConstBlock {
1681+ pub hir_id : HirId ,
1682+ pub def_id : LocalDefId ,
1683+ pub body : BodyId ,
1684+ }
1685+
16781686/// An expression.
16791687#[ derive( Debug , Clone , Copy , HashStable_Generic ) ]
16801688pub struct Expr < ' hir > {
@@ -1922,7 +1930,7 @@ pub fn is_range_literal(expr: &Expr<'_>) -> bool {
19221930#[ derive( Debug , Clone , Copy , HashStable_Generic ) ]
19231931pub enum ExprKind < ' hir > {
19241932 /// Allow anonymous constants from an inline `const` block
1925- ConstBlock ( AnonConst ) ,
1933+ ConstBlock ( ConstBlock ) ,
19261934 /// An array (e.g., `[a, b, c, d]`).
19271935 Array ( & ' hir [ Expr < ' hir > ] ) ,
19281936 /// A function call.
@@ -3641,6 +3649,7 @@ pub enum Node<'hir> {
36413649 Variant ( & ' hir Variant < ' hir > ) ,
36423650 Field ( & ' hir FieldDef < ' hir > ) ,
36433651 AnonConst ( & ' hir AnonConst ) ,
3652+ ConstBlock ( & ' hir ConstBlock ) ,
36443653 Expr ( & ' hir Expr < ' hir > ) ,
36453654 ExprField ( & ' hir ExprField < ' hir > ) ,
36463655 Stmt ( & ' hir Stmt < ' hir > ) ,
@@ -3695,6 +3704,7 @@ impl<'hir> Node<'hir> {
36953704 Node :: TypeBinding ( b) => Some ( b. ident ) ,
36963705 Node :: Param ( ..)
36973706 | Node :: AnonConst ( ..)
3707+ | Node :: ConstBlock ( ..)
36983708 | Node :: Expr ( ..)
36993709 | Node :: Stmt ( ..)
37003710 | Node :: Block ( ..)
@@ -3758,7 +3768,7 @@ impl<'hir> Node<'hir> {
37583768 } )
37593769 | Node :: Expr ( Expr {
37603770 kind :
3761- ExprKind :: ConstBlock ( AnonConst { body, .. } )
3771+ ExprKind :: ConstBlock ( ConstBlock { body, .. } )
37623772 | ExprKind :: Closure ( Closure { body, .. } )
37633773 | ExprKind :: Repeat ( _, ArrayLen :: Body ( AnonConst { body, .. } ) ) ,
37643774 ..
@@ -3878,6 +3888,13 @@ impl<'hir> Node<'hir> {
38783888 this
38793889 }
38803890
3891+ /// Expect a [`Node::ConstBlock`] or panic.
3892+ #[ track_caller]
3893+ pub fn expect_inline_const ( self ) -> & ' hir ConstBlock {
3894+ let Node :: ConstBlock ( this) = self else { self . expect_failed ( "an inline constant" ) } ;
3895+ this
3896+ }
3897+
38813898 /// Expect a [`Node::Expr`] or panic.
38823899 #[ track_caller]
38833900 pub fn expect_expr ( self ) -> & ' hir Expr < ' hir > {
0 commit comments