@@ -66,8 +66,6 @@ fn eval_and_inline_recursively(
66
66
( true , ast:: Expr :: BlockExpr ( block) ) if block. is_standalone ( ) => {
67
67
eval_and_inline_recursively ( ctx, konst, & block. tail_expr ( ) ?, fuel - 1 )
68
68
}
69
- ( _, ast:: Expr :: Literal ( lit) ) => Some ( lit. to_string ( ) ) ,
70
-
71
69
// NOTE: For some expressions, `render_eval` will crash.
72
70
// e.g. `{ &[&[&[&[&[&[10, 20, 30]]]]]] }` will fail for `render_eval`.
73
71
//
@@ -85,6 +83,7 @@ fn eval_and_inline_recursively(
85
83
// > const A: &[u32] = { &[10] }; OK because we inline ref expression.
86
84
// > const B: &[u32] = { { &[10] } }; ERROR because we evaluate block.
87
85
( _, ast:: Expr :: BlockExpr ( _) )
86
+ | ( _, ast:: Expr :: Literal ( _) )
88
87
| ( _, ast:: Expr :: RefExpr ( _) )
89
88
| ( _, ast:: Expr :: ArrayExpr ( _) )
90
89
| ( _, ast:: Expr :: TupleExpr ( _) )
@@ -130,7 +129,7 @@ fn validate_type_recursively(
130
129
validate_type_recursively ( ctx, ty. as_slice ( ) . as_ref ( ) , false , fuel - 1 )
131
130
}
132
131
( _, 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.
134
133
Some ( builtin) if refed || ( !refed && !builtin. is_str ( ) ) => Some ( ( ) ) ,
135
134
_ => None ,
136
135
} ,
@@ -438,20 +437,35 @@ mod tests {
438
437
}
439
438
440
439
// 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
+ }
455
469
456
470
// #[test]
457
471
// fn inline_const_as_literal_block_array() {
0 commit comments