Compiling t v0.1.0 (/tmp/t)
error[E0493]: destructor of `[IA<()>; 1]` cannot be evaluated at compile-time
--> src/main.rs:15:30
|
15 | const y: IA<IA<()>> = IA::L(&[IA::new(&[])]);
| ^^^^^^^^^^^^^^- value is dropped here
| |
| the destructor for this type cannot be evaluated in constants
For more information about this error, try `rustc --explain E0493`.
error: could not compile `t` (bin "t") due to 1 previous error
The goal of IA is to allow constructing constants when it is possible. In this example it doesn't look like using const fn makes any difference to code but in real code the IA is parameterized by more complex type thus using const fn new to construct the instance of the type significantly simplifies the notation.
Is this behavior inevitable or may be some workaround exists?
My best guess so far is it thinks the outer variant constructor might panic and have to drop the value, which is not constant-promoted without some prodding.
I guess &[IA] doesn't automatically constant promote because IA has a destructor, even though it's possible to create a const one. That part is acting as expected.
Thanks for help @quinedot, @theemathas. I finally used const block const {} to make it work. Yeah, it is strange that some alternatives compile and other not. I also found that splitting expression on few constants work but didn't found "const block" solution. Thank you for finding related issues.