rust/tests
Chris Denton 5d2375f789
Rollup merge of #139042 - compiler-errors:do-not-optimize-switchint, r=saethlin
Do not remove trivial `SwitchInt` in analysis MIR

This PR ensures that we don't prematurely remove trivial `SwitchInt` terminators which affects both the borrow-checking and runtime semantics (i.e. UB) of the code. Previously the `SimplifyCfg` optimization was removing `SwitchInt` terminators when they was "trivial", i.e. when all arms branched to the same basic block, even if that `SwitchInt` terminator had the side-effect of reading an operand which (for example) may not be initialized or may point to an invalid place in memory.

This behavior is unlike all other optimizations, which are only applied after "analysis" (i.e. borrow-checking) is finished, and which Miri disables to make sure the compiler doesn't silently remove UB.

Fixing this code "breaks" (i.e. unmasks) code that used to borrow-check but no longer does, like:

```rust
fn foo() {
    let x;
    let (0 | _) = x;
}
```

This match expression should perform a read because `_` does not shadow the `0` literal pattern, and the compiler should have to read the match scrutinee to compare it to 0. I've checked that this behavior does not actually manifest in practice via a crater run which came back clean: https://github.com/rust-lang/rust/pull/139042#issuecomment-2767436367

As a side-note, it may be tempting to suggest that this is actually a good thing or that we should preserve this behavior. If we wanted to make this work (i.e. trivially optimize out reads from matches that are redundant like `0 | _`), then we should be enabling this behavior *after* fixing this. However, I think it's kinda unprincipled, and for example other variations of the code don't even work today, e.g.:

```rust
fn foo() {
    let x;
    let (0.. | _) = x;
}
```
2025-04-19 19:30:46 +00:00
..
assembly Rollup merge of #139971 - LukasWoodtli:gardena/lw/fix-cstring-merging-test, r=wesleywiser 2025-04-17 21:53:26 +02:00
auxiliary
codegen Rollup merge of #139989 - durin42:llvm-21-issue-101082, r=cuviper 2025-04-18 05:17:54 +02:00
codegen-units
coverage Update the minimum external LLVM to 19 2025-04-05 11:44:38 -07:00
coverage-run-rustdoc Update coverage-run-rustdoc output 2025-03-28 10:35:53 +01:00
crashes Rollup merge of #138599 - adwinwhite:recursive-overflow, r=wesleywiser 2025-04-18 05:17:53 +02:00
debuginfo Rollup merge of #138599 - adwinwhite:recursive-overflow, r=wesleywiser 2025-04-18 05:17:53 +02:00
incremental UI tests: migrate remaining compile time error-patterns to line annotations 2025-04-13 21:48:53 +03:00
mir-opt Rollup merge of #139042 - compiler-errors:do-not-optimize-switchint, r=saethlin 2025-04-19 19:30:46 +00:00
pretty Auto merge of #139114 - m-ou-se:super-let-pin, r=davidtwco 2025-04-19 08:01:53 +00:00
run-make Rollup merge of #139976 - jieyouxu:plumbing, r=Kobzol 2025-04-18 05:17:54 +02:00
rustdoc Rollup merge of #139913 - fmease:rustdoc-fix-fn-param-handling, r=GuillaumeGomez 2025-04-18 05:16:31 +02:00
rustdoc-gui Add regression test for #139282 2025-04-07 17:28:46 +02:00
rustdoc-js rustdoc-search: add unbox flag to Result aliases 2025-04-11 11:36:40 -07:00
rustdoc-js-std rustdoc-search: add unbox flag to Result aliases 2025-04-11 11:36:40 -07:00
rustdoc-json Add regression test for span 1-indexed check 2025-04-18 20:32:40 +02:00
rustdoc-ui Rollup merge of #138632 - clubby789:stabilize-cfg-boolean-lit, r=davidtwco,Urgau,traviscross 2025-04-17 06:25:15 +02:00
ui Rollup merge of #139042 - compiler-errors:do-not-optimize-switchint, r=saethlin 2025-04-19 19:30:46 +00:00
ui-fulldeps Move eager translation to a method on Diag 2025-04-16 21:38:59 -04:00
COMPILER_TESTS.md