@@ -1675,6 +1675,14 @@ pub struct AnonConst {
1675
1675
pub body : BodyId ,
1676
1676
}
1677
1677
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
+
1678
1686
/// An expression.
1679
1687
#[ derive( Debug , Clone , Copy , HashStable_Generic ) ]
1680
1688
pub struct Expr < ' hir > {
@@ -1922,7 +1930,7 @@ pub fn is_range_literal(expr: &Expr<'_>) -> bool {
1922
1930
#[ derive( Debug , Clone , Copy , HashStable_Generic ) ]
1923
1931
pub enum ExprKind < ' hir > {
1924
1932
/// Allow anonymous constants from an inline `const` block
1925
- ConstBlock ( AnonConst ) ,
1933
+ ConstBlock ( ConstBlock ) ,
1926
1934
/// An array (e.g., `[a, b, c, d]`).
1927
1935
Array ( & ' hir [ Expr < ' hir > ] ) ,
1928
1936
/// A function call.
@@ -3641,6 +3649,7 @@ pub enum Node<'hir> {
3641
3649
Variant ( & ' hir Variant < ' hir > ) ,
3642
3650
Field ( & ' hir FieldDef < ' hir > ) ,
3643
3651
AnonConst ( & ' hir AnonConst ) ,
3652
+ ConstBlock ( & ' hir ConstBlock ) ,
3644
3653
Expr ( & ' hir Expr < ' hir > ) ,
3645
3654
ExprField ( & ' hir ExprField < ' hir > ) ,
3646
3655
Stmt ( & ' hir Stmt < ' hir > ) ,
@@ -3695,6 +3704,7 @@ impl<'hir> Node<'hir> {
3695
3704
Node :: TypeBinding ( b) => Some ( b. ident ) ,
3696
3705
Node :: Param ( ..)
3697
3706
| Node :: AnonConst ( ..)
3707
+ | Node :: ConstBlock ( ..)
3698
3708
| Node :: Expr ( ..)
3699
3709
| Node :: Stmt ( ..)
3700
3710
| Node :: Block ( ..)
@@ -3758,7 +3768,7 @@ impl<'hir> Node<'hir> {
3758
3768
} )
3759
3769
| Node :: Expr ( Expr {
3760
3770
kind :
3761
- ExprKind :: ConstBlock ( AnonConst { body, .. } )
3771
+ ExprKind :: ConstBlock ( ConstBlock { body, .. } )
3762
3772
| ExprKind :: Closure ( Closure { body, .. } )
3763
3773
| ExprKind :: Repeat ( _, ArrayLen :: Body ( AnonConst { body, .. } ) ) ,
3764
3774
..
@@ -3878,6 +3888,13 @@ impl<'hir> Node<'hir> {
3878
3888
this
3879
3889
}
3880
3890
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
+
3881
3898
/// Expect a [`Node::Expr`] or panic.
3882
3899
#[ track_caller]
3883
3900
pub fn expect_expr ( self ) -> & ' hir Expr < ' hir > {
0 commit comments