@@ -182,15 +182,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
182
182
}
183
183
ItemKind :: Static ( box ast:: StaticItem {
184
184
ident,
185
- ty : t ,
185
+ ty,
186
186
safety : _,
187
187
mutability : m,
188
188
expr : e,
189
189
define_opaque,
190
190
} ) => {
191
191
let ident = self . lower_ident ( * ident) ;
192
- let ( ty, body_id) =
193
- self . lower_const_item ( t, span, e. as_deref ( ) , ImplTraitPosition :: StaticTy ) ;
192
+ let ty =
193
+ self . lower_ty ( ty, ImplTraitContext :: Disallowed ( ImplTraitPosition :: StaticTy ) ) ;
194
+ let body_id = self . lower_const_body ( span, e. as_deref ( ) ) ;
194
195
self . lower_define_opaque ( hir_id, define_opaque) ;
195
196
hir:: ItemKind :: Static ( ident, ty, * m, body_id)
196
197
}
@@ -203,22 +204,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
203
204
..
204
205
} ) => {
205
206
let ident = self . lower_ident ( * ident) ;
206
- let ( generics, ( ty, body_id) ) = self . lower_generics (
207
+ let ( generics, ( ty, ( body_id, ct_arg ) ) ) = self . lower_generics (
207
208
generics,
208
209
id,
209
210
ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
210
211
|this| {
211
- this. lower_const_item ( ty, span, expr. as_deref ( ) , ImplTraitPosition :: ConstTy )
212
+ let ty = this
213
+ . lower_ty ( ty, ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ) ;
214
+ ( ty, this. lower_const_item ( span, expr. as_deref ( ) ) )
212
215
} ,
213
216
) ;
214
217
self . lower_define_opaque ( hir_id, & define_opaque) ;
215
- let ct_arg = if self . tcx . features ( ) . min_generic_const_args ( )
216
- && let Some ( expr) = expr
217
- {
218
- self . try_lower_as_const_path ( expr)
219
- } else {
220
- None
221
- } ;
222
218
hir:: ItemKind :: Const ( ident, ty, generics, body_id, ct_arg)
223
219
}
224
220
ItemKind :: Fn ( box Fn {
@@ -501,13 +497,23 @@ impl<'hir> LoweringContext<'_, 'hir> {
501
497
502
498
fn lower_const_item (
503
499
& mut self ,
504
- ty : & Ty ,
505
500
span : Span ,
506
501
body : Option < & Expr > ,
507
- impl_trait_position : ImplTraitPosition ,
508
- ) -> ( & ' hir hir:: Ty < ' hir > , hir:: BodyId ) {
509
- let ty = self . lower_ty ( ty, ImplTraitContext :: Disallowed ( impl_trait_position) ) ;
510
- ( ty, self . lower_const_body ( span, body) )
502
+ ) -> ( hir:: BodyId , Option < & ' hir hir:: ConstArg < ' hir > > ) {
503
+ let ct_arg = if self . tcx . features ( ) . min_generic_const_args ( )
504
+ && let Some ( expr) = body
505
+ {
506
+ self . try_lower_as_const_path ( expr)
507
+ } else {
508
+ None
509
+ } ;
510
+ let body_id = if body. is_some ( ) && ct_arg. is_none ( ) {
511
+ // TODO: lower as const block instead
512
+ self . lower_const_body ( span, body)
513
+ } else {
514
+ self . lower_const_body ( span, body)
515
+ } ;
516
+ ( body_id, ct_arg)
511
517
}
512
518
513
519
#[ instrument( level = "debug" , skip( self ) ) ]
@@ -819,15 +825,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
819
825
|this| {
820
826
let ty = this
821
827
. lower_ty ( ty, ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ) ;
822
- let body = expr. as_ref ( ) . map ( |x| this. lower_const_body ( i. span , Some ( x) ) ) ;
823
- let ct_arg = if this. tcx . features ( ) . min_generic_const_args ( )
824
- && let Some ( expr) = expr
825
- {
826
- this. try_lower_as_const_path ( expr)
827
- } else {
828
- None
829
- } ;
830
- hir:: TraitItemKind :: Const ( ty, body, ct_arg)
828
+ match expr. as_deref ( ) . map ( |e| this. lower_const_item ( i. span , Some ( e) ) ) {
829
+ Some ( ( body, ct_arg) ) => {
830
+ hir:: TraitItemKind :: Const ( ty, Some ( body) , ct_arg)
831
+ }
832
+ None => hir:: TraitItemKind :: Const ( ty, None , None ) ,
833
+ }
831
834
} ,
832
835
) ;
833
836
@@ -1018,15 +1021,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
1018
1021
|this| {
1019
1022
let ty = this
1020
1023
. lower_ty ( ty, ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ) ;
1021
- let body = this. lower_const_body ( i. span , expr. as_deref ( ) ) ;
1022
1024
this. lower_define_opaque ( hir_id, & define_opaque) ;
1023
- let ct_arg = if this. tcx . features ( ) . min_generic_const_args ( )
1024
- && let Some ( expr) = expr
1025
- {
1026
- this. try_lower_as_const_path ( expr)
1027
- } else {
1028
- None
1029
- } ;
1025
+ let ( body, ct_arg) = this. lower_const_item ( i. span , expr. as_deref ( ) ) ;
1030
1026
hir:: ImplItemKind :: Const ( ty, body, ct_arg)
1031
1027
} ,
1032
1028
) ,
0 commit comments