@@ -186,11 +186,7 @@ impl TypeRef {
186186 TypeRef :: RawPtr ( Box :: new ( inner_ty) , mutability)
187187 }
188188 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 ( ) ) ;
194190 TypeRef :: Array ( Box :: new ( TypeRef :: from_ast_opt ( ctx, inner. ty ( ) ) ) , len)
195191 }
196192 ast:: Type :: SliceType ( inner) => {
@@ -383,18 +379,18 @@ impl TypeBound {
383379pub enum ConstRef {
384380 Scalar ( LiteralConstRef ) ,
385381 Path ( Name ) ,
386- Complex ( AstId < ast:: Expr > ) ,
382+ Complex ( AstId < ast:: ConstArg > ) ,
387383}
388384
389385impl 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) ;
395391 }
396- None => Self :: Scalar ( LiteralConstRef :: Unknown ) ,
397392 }
393+ Self :: Scalar ( LiteralConstRef :: Unknown )
398394 }
399395
400396 pub fn display < ' a > ( & ' a self , db : & ' a dyn ExpandDatabase ) -> impl fmt:: Display + ' a {
@@ -412,7 +408,7 @@ impl ConstRef {
412408 }
413409
414410 // 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 {
416412 fn is_path_ident ( p : & ast:: PathExpr ) -> bool {
417413 let Some ( path) = p. path ( ) else {
418414 return false ;
0 commit comments