Description
Currently, after const-eval is done, we first intern the result into tcx
and then validate that it matches the type. This is unfortunate because interning can go wrong (when there is a mutable pointer somewhere we did not expect), and in most cases that issue would also be detected by validation -- and validation shows a much nicer error, indicating where in the value the issue arises.
However, interning currently also does the job of adjusting the allocation's mutability to its final value. This has to be done before validation. So fixing this would end up with a final order of operations like:
- Adjust mutability
- Validation
- Interning
All that said, I'm not entirely sure whether this is worth it since triggering the interning error should be pretty rare. Our static const checks should largely prevent them.
Cc @rust-lang/wg-const-eval