@@ -186,11 +186,7 @@ impl TypeRef {
186
186
TypeRef :: RawPtr ( Box :: new ( inner_ty) , mutability)
187
187
}
188
188
ast:: Type :: ArrayType ( inner) => {
189
- // FIXME: This is a hack. We should probably reuse the machinery of
190
- // `hir_def::body::lower` to lower this into an `Expr` and then evaluate it at the
191
- // `hir_ty` level, which would allow knowing the type of:
192
- // let v: [u8; 2 + 2] = [0u8; 4];
193
- let len = ConstRef :: from_expr_opt ( ctx, inner. expr ( ) ) ;
189
+ let len = ConstRef :: from_const_arg ( ctx, inner. const_arg ( ) ) ;
194
190
TypeRef :: Array ( Box :: new ( TypeRef :: from_ast_opt ( ctx, inner. ty ( ) ) ) , len)
195
191
}
196
192
ast:: Type :: SliceType ( inner) => {
@@ -383,18 +379,18 @@ impl TypeBound {
383
379
pub enum ConstRef {
384
380
Scalar ( LiteralConstRef ) ,
385
381
Path ( Name ) ,
386
- Complex ( AstId < ast:: Expr > ) ,
382
+ Complex ( AstId < ast:: ConstArg > ) ,
387
383
}
388
384
389
385
impl ConstRef {
390
- pub ( crate ) fn from_expr_opt ( lower_ctx : & LowerCtx < ' _ > , expr : Option < ast:: Expr > ) -> Self {
391
- match expr {
392
- Some ( x ) => {
393
- let ast_id = lower_ctx . ast_id ( & x ) ;
394
- Self :: from_expr ( x , ast_id)
386
+ pub ( crate ) fn from_const_arg ( lower_ctx : & LowerCtx < ' _ > , arg : Option < ast:: ConstArg > ) -> Self {
387
+ if let Some ( arg ) = arg {
388
+ let ast_id = lower_ctx . ast_id ( & arg ) ;
389
+ if let Some ( expr ) = arg . expr ( ) {
390
+ return Self :: from_expr ( expr , ast_id) ;
395
391
}
396
- None => Self :: Scalar ( LiteralConstRef :: Unknown ) ,
397
392
}
393
+ Self :: Scalar ( LiteralConstRef :: Unknown )
398
394
}
399
395
400
396
pub fn display < ' a > ( & ' a self , db : & ' a dyn ExpandDatabase ) -> impl fmt:: Display + ' a {
@@ -412,7 +408,7 @@ impl ConstRef {
412
408
}
413
409
414
410
// We special case literals and single identifiers, to speed up things.
415
- fn from_expr ( expr : ast:: Expr , ast_id : Option < AstId < ast:: Expr > > ) -> Self {
411
+ fn from_expr ( expr : ast:: Expr , ast_id : Option < AstId < ast:: ConstArg > > ) -> Self {
416
412
fn is_path_ident ( p : & ast:: PathExpr ) -> bool {
417
413
let Some ( path) = p. path ( ) else {
418
414
return false ;
0 commit comments