Recover statics better by Noratrieb · Pull Request #125555 · rust-lang/rust (original) (raw)

The const interner uses the body to intern static allocations.
This means that an allocation will be mutable if the resulting type contains interior mutability.
Const eval contains an assertion that types that are Freeze do not have mutable allocations, which was failing for cases where the type was a type error.

The first two commits fix this by forwarding the inferred type through type_of, while the last commit disables the assertion for remaining cases where type errors are involved.

Note that the erased region mapping is not fully correct, and causes this spurious error now:

struct X<'a>(&'a ()); impl<'a> X<'a> { const A: &'a () = &(); const B = Self::A; }

error: lifetime may not live long enough
 --> uwu.rs:4:13
  |
2 | impl<'a> X<'a> {
  |      -- lifetime `'a` defined here
3 |   const A: &'a () = &();
4 |   const B = Self::A;
  |             ^^^^^^^ using this value as a constant requires that `'a` must outlive `'static`

I deem that acceptable, that you may disagree.

note: the commit messages contain more information

fixes #124164

r? oli-obk