@@ -2682,56 +2682,31 @@ impl<'hir> LoweringContext<'_, 'hir> {
26822682 fn lower_const_item_rhs (
26832683 & mut self ,
26842684 body : & Option < Box < Expr > > ,
2685- kind : ConstItemKind ,
26862685 span : Span ,
26872686 ) -> hir:: ConstItemRhs < ' hir > {
2688- match ( body, kind) {
2689- ( body, ConstItemKind :: Body ) => {
2690- let is_direct = |body| {
2691- if self . tcx . features ( ) . macroless_const_item_generic_const_args ( ) {
2692- self . can_lower_expr_to_const_arg_direct (
2693- body,
2694- DirectConstArgContext :: MacrolessMinGenericConstArgs ,
2695- )
2696- . is_ok ( )
2697- } else {
2698- // do not check can_lower_expr_to_const_arg_direct, but rather just
2699- // ExprKind::DirectConstArg, because we don't want e.g.
2700- // `impl<const N: u8> { const C: u8 = N; }` to be a direct-rhs const
2701- matches ! ( body, Expr { kind: ExprKind :: DirectConstArg ( _) , .. } )
2702- }
2703- } ;
2704- // N.B.: the feature gate for this is generic_const_args, not min_generic_const_args
2705- if self . tcx . features ( ) . generic_const_args ( )
2706- && let Some ( body) = body
2707- && is_direct ( body)
2708- {
2709- hir:: ConstItemRhs :: Direct (
2710- self . arena . alloc ( self . lower_expr_to_const_arg_direct ( & body, None ) ) ,
2711- )
2712- } else {
2713- hir:: ConstItemRhs :: Body ( self . lower_const_body ( span, body. as_deref ( ) ) )
2714- }
2715- }
2716- ( Some ( body) , ConstItemKind :: TypeConst ) => hir:: ConstItemRhs :: Direct ( self . arena . alloc (
2717- match self . can_lower_expr_to_const_arg_direct (
2718- & body,
2687+ let is_direct = |body| {
2688+ if self . tcx . features ( ) . macroless_const_item_generic_const_args ( ) {
2689+ self . can_lower_expr_to_const_arg_direct (
2690+ body,
27192691 DirectConstArgContext :: MacrolessMinGenericConstArgs ,
2720- ) {
2721- Ok ( ( ) ) => self . lower_expr_to_const_arg_direct ( & body, None ) ,
2722- Err ( err) => err. emit ( self ) ,
2723- } ,
2724- ) ) ,
2725- ( None , ConstItemKind :: TypeConst ) => {
2726- let const_arg = ConstArg {
2727- hir_id : self . next_id ( ) ,
2728- kind : hir:: ConstArgKind :: Error (
2729- self . dcx ( ) . span_delayed_bug ( DUMMY_SP , "no block" ) ,
2730- ) ,
2731- span : DUMMY_SP ,
2732- } ;
2733- hir:: ConstItemRhs :: Direct ( self . arena . alloc ( const_arg) )
2692+ )
2693+ . is_ok ( )
2694+ } else {
2695+ // do not check can_lower_expr_to_const_arg_direct, but rather just
2696+ // ExprKind::DirectConstArg, because we don't want e.g.
2697+ // `impl<const N: u8> { const C: u8 = N; }` to be a direct-rhs const
2698+ matches ! ( body, Expr { kind: ExprKind :: DirectConstArg ( _) , .. } )
27342699 }
2700+ } ;
2701+ if self . tcx . features ( ) . min_generic_const_args ( )
2702+ && let Some ( body) = body
2703+ && is_direct ( body)
2704+ {
2705+ hir:: ConstItemRhs :: Direct (
2706+ self . arena . alloc ( self . lower_expr_to_const_arg_direct ( & body, None ) ) ,
2707+ )
2708+ } else {
2709+ hir:: ConstItemRhs :: Body ( self . lower_const_body ( span, body. as_deref ( ) ) )
27352710 }
27362711 }
27372712
0 commit comments