@@ -102,17 +102,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
102
102
103
103
let kind = match & e. kind {
104
104
ExprKind :: Array ( exprs) => hir:: ExprKind :: Array ( self . lower_exprs ( exprs) ) ,
105
- ExprKind :: ConstBlock ( c) => {
106
- let c = self . with_new_scopes ( c. value . span , |this| {
107
- let def_id = this. local_def_id ( c. id ) ;
108
- hir:: ConstBlock {
109
- def_id,
110
- hir_id : this. lower_node_id ( c. id ) ,
111
- body : this. lower_const_body ( c. value . span , Some ( & c. value ) ) ,
112
- }
113
- } ) ;
114
- hir:: ExprKind :: ConstBlock ( c)
115
- }
105
+ ExprKind :: ConstBlock ( c) => hir:: ExprKind :: ConstBlock ( self . lower_const_block ( c) ) ,
116
106
ExprKind :: Repeat ( expr, count) => {
117
107
let expr = self . lower_expr ( expr) ;
118
108
let count = self . lower_array_length_to_const_arg ( count) ;
@@ -153,18 +143,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
153
143
let ohs = self . lower_expr ( ohs) ;
154
144
hir:: ExprKind :: Unary ( op, ohs)
155
145
}
156
- ExprKind :: Lit ( token_lit) => {
157
- let lit_kind = match LitKind :: from_token_lit ( * token_lit) {
158
- Ok ( lit_kind) => lit_kind,
159
- Err ( err) => {
160
- let guar =
161
- report_lit_error ( & self . tcx . sess . psess , err, * token_lit, e. span ) ;
162
- LitKind :: Err ( guar)
163
- }
164
- } ;
165
- let lit = self . arena . alloc ( respan ( self . lower_span ( e. span ) , lit_kind) ) ;
166
- hir:: ExprKind :: Lit ( lit)
167
- }
146
+ ExprKind :: Lit ( token_lit) => hir:: ExprKind :: Lit ( self . lower_lit ( token_lit, e. span ) ) ,
168
147
ExprKind :: IncludedBytes ( bytes) => {
169
148
let lit = self . arena . alloc ( respan (
170
149
self . lower_span ( e. span ) ,
@@ -403,6 +382,32 @@ impl<'hir> LoweringContext<'_, 'hir> {
403
382
} )
404
383
}
405
384
385
+ pub ( crate ) fn lower_const_block ( & mut self , c : & AnonConst ) -> hir:: ConstBlock {
386
+ self . with_new_scopes ( c. value . span , |this| {
387
+ let def_id = this. local_def_id ( c. id ) ;
388
+ hir:: ConstBlock {
389
+ def_id,
390
+ hir_id : this. lower_node_id ( c. id ) ,
391
+ body : this. lower_const_body ( c. value . span , Some ( & c. value ) ) ,
392
+ }
393
+ } )
394
+ }
395
+
396
+ pub ( crate ) fn lower_lit (
397
+ & mut self ,
398
+ token_lit : & token:: Lit ,
399
+ span : Span ,
400
+ ) -> & ' hir Spanned < LitKind > {
401
+ let lit_kind = match LitKind :: from_token_lit ( * token_lit) {
402
+ Ok ( lit_kind) => lit_kind,
403
+ Err ( err) => {
404
+ let guar = report_lit_error ( & self . tcx . sess . psess , err, * token_lit, span) ;
405
+ LitKind :: Err ( guar)
406
+ }
407
+ } ;
408
+ self . arena . alloc ( respan ( self . lower_span ( span) , lit_kind) )
409
+ }
410
+
406
411
fn lower_unop ( & mut self , u : UnOp ) -> hir:: UnOp {
407
412
match u {
408
413
UnOp :: Deref => hir:: UnOp :: Deref ,
0 commit comments