@@ -66,8 +66,6 @@ fn eval_and_inline_recursively(
6666 ( true , ast:: Expr :: BlockExpr ( block) ) if block. is_standalone ( ) => {
6767 eval_and_inline_recursively ( ctx, konst, & block. tail_expr ( ) ?, fuel - 1 )
6868 }
69- ( _, ast:: Expr :: Literal ( lit) ) => Some ( lit. to_string ( ) ) ,
70-
7169 // NOTE: For some expressions, `render_eval` will crash.
7270 // e.g. `{ &[&[&[&[&[&[10, 20, 30]]]]]] }` will fail for `render_eval`.
7371 //
@@ -85,6 +83,7 @@ fn eval_and_inline_recursively(
8583 // > const A: &[u32] = { &[10] }; OK because we inline ref expression.
8684 // > const B: &[u32] = { { &[10] } }; ERROR because we evaluate block.
8785 ( _, ast:: Expr :: BlockExpr ( _) )
86+ | ( _, ast:: Expr :: Literal ( _) )
8887 | ( _, ast:: Expr :: RefExpr ( _) )
8988 | ( _, ast:: Expr :: ArrayExpr ( _) )
9089 | ( _, ast:: Expr :: TupleExpr ( _) )
@@ -130,7 +129,7 @@ fn validate_type_recursively(
130129 validate_type_recursively ( ctx, ty. as_slice ( ) . as_ref ( ) , false , fuel - 1 )
131130 }
132131 ( _, Some ( ty) ) => match ty. as_builtin ( ) {
133- // `const A: str` is not correct, `const A: &builtin` is always correct .
132+ // `const A: str` is not correct, but `const A: &builtin` is.
134133 Some ( builtin) if refed || ( !refed && !builtin. is_str ( ) ) => Some ( ( ) ) ,
135134 _ => None ,
136135 } ,
@@ -438,20 +437,35 @@ mod tests {
438437 }
439438
440439 // FIXME: These won't work with `konst.render_eval(ctx.sema.db)`
441- // #[test]
442- // fn inline_const_as_literal_block_slice() {
443- // check_assist(
444- // inline_const_as_literal,
445- // r#"
446- // const ABC: &[&[&[&[&[&[i32]]]]]] = { &[&[&[&[&[&[10, 20, 30]]]]]] };
447- // fn a() { A$0BC }
448- // "#,
449- // r#"
450- // const ABC: &[&[&[&[&[&[i32]]]]]] = { &[&[&[&[&[&[10, 20, 30]]]]]] };
451- // fn a() { &[&[&[&[&[&[10, 20, 30]]]]]] }
452- // "#,
453- // );
454- // }
440+ #[ test]
441+ fn inline_const_as_literal_block_slice ( ) {
442+ check_assist (
443+ inline_const_as_literal,
444+ r#"
445+ const ABC: &[&[&[&[&[&[i32]]]]]] = { &[&[&[&[&[&[10, 20, 30]]]]]] };
446+ fn a() { A$0BC }
447+ "# ,
448+ r#"
449+ const ABC: &[&[&[&[&[&[i32]]]]]] = { &[&[&[&[&[&[10, 20, 30]]]]]] };
450+ fn a() { &[&[&[&[&[&[10, 20, 30]]]]]] }
451+ "# ,
452+ ) ;
453+ }
454+
455+ #[ test]
456+ fn inline_const_as_literal_block_slice_single ( ) {
457+ check_assist (
458+ inline_const_as_literal,
459+ r#"
460+ const ABC: [i32; 1] = { [10] };
461+ fn a() { A$0BC }
462+ "# ,
463+ r#"
464+ const ABC: [i32; 1] = { [10] };
465+ fn a() { [10] }
466+ "# ,
467+ ) ;
468+ }
455469
456470 // #[test]
457471 // fn inline_const_as_literal_block_array() {
0 commit comments