rust/compiler/rustc_mir_transform
Matthias Krüger 434232f7b2
Rollup merge of #118426 - aDotInTheVoid:const-wat, r=compiler-errors,cjgillot
ConstProp: Correctly remove const if unknown value assigned to it.

Closes #118328

The problematic sequence of MIR is:

```rust
          _1 = const 0_usize;
          _1 = const _; // This is an associated constant we can't know before monomorphization.
          _0 = _1;
```

1. When `ConstProp::visit_assign` happens on `_1 = const 0_usize;`, it records that `0x0usize` is the value for `_1`.
2. Next `visit_assign` happens on `_1 = const _;`. Because the rvalue `.has_param()`, it can't be const evaled.
3. Finaly, `visit_assign` happens on `_0 = _1;`. Here it would think the value of `_1` was `0x0usize` from step 1.

The solution is to remove consts when checking the RValue fails, as they may have contained values that should now be invalidated, as that local was overwritten.

This should probably be back-ported to beta. Stable is more iffy, as it's gone unidentified since 1.70, so I only think it's worthwhile if there's another reason for a 1.74.1 release anyway.
2023-11-29 12:34:50 +01:00
..
src Rollup merge of #118426 - aDotInTheVoid:const-wat, r=compiler-errors,cjgillot 2023-11-29 12:34:50 +01:00
Cargo.toml Replace custom_encodable with encodable. 2023-11-22 18:37:14 +11:00
messages.ftl Print list of missing target features when calling a function with target features outside an unsafe block 2023-11-27 19:13:11 +01:00