rust/compiler/rustc_middle/src
bors 06e02d5b25 Auto merge of #118308 - Nadrieril:sound-exhaustive-patterns-take-3, r=compiler-errors
Don't warn an empty pattern unreachable if we're not sure the data is valid

Exhaustiveness checking used to be naive about the possibility of a place containing invalid data. This could cause it to emit an "unreachable pattern" lint on an arm that was in fact reachable, as in https://github.com/rust-lang/rust/issues/117119.

This PR fixes that. We now track whether a place that is matched on may hold invalid data. This also forced me to be extra precise about how exhaustiveness manages empty types.

Note that this now errs in the opposite direction: the following arm is truly unreachable (because the binding causes a read of the value) but not linted as such. I'd rather not recommend writing a `match ... {}` that has the implicit side-effect of loading the value. [Never patterns](https://github.com/rust-lang/rust/issues/118155) will solve this cleanly.
```rust
match union.value {
    _x => unreachable!(),
}
```

I recommend reviewing commit by commit. I went all-in on the test suite because this went through a lot of iterations and I kept everything. The bit I'm least confident in is `is_known_valid_scrutinee` in `check_match.rs`.

Fixes https://github.com/rust-lang/rust/issues/117119.
2023-12-09 19:03:03 +00:00
..
dep_graph Reduce exposure of things. 2023-11-16 16:49:22 +11:00
hir resolve: Feed the def_kind query immediately on DefId creation 2023-11-28 15:39:31 +03:00
hooks Rename hook. 2023-11-01 16:49:18 +00:00
infer Uplift CanonicalVarInfo and friends 2023-11-21 17:49:57 +00:00
middle Auto merge of #116170 - matthewjasper:remove-thir-destruction-scopes, r=cjgillot 2023-12-09 12:38:32 +00:00
mir Rollup merge of #118198 - Zalathar:if-not, r=cjgillot 2023-12-09 00:48:08 -08:00
query ctfe interpreter: extend provenance so that it can track whether a pointer is immutable 2023-12-07 17:46:36 +01:00
thir Add never_patterns feature gate 2023-11-29 03:58:29 +01:00
traits Implement async gen blocks 2023-12-08 17:23:25 +00:00
ty Auto merge of #118308 - Nadrieril:sound-exhaustive-patterns-take-3, r=compiler-errors 2023-12-09 19:03:03 +00:00
util Rename HandlerInner::delay_span_bug as HandlerInner::span_delayed_bug. 2023-12-02 09:01:19 +11:00
arena.rs Cache flags for ty::Const 2023-11-22 23:28:28 +00:00
error.rs don't point at const usage site for resolution-time errors 2023-09-14 22:34:05 +02:00
lib.rs Use rustc_fluent_macro::fluent_messages! directly. 2023-11-26 08:38:40 +11:00
lint.rs Remove support for compiler plugins. 2023-11-04 08:50:46 +11:00
macros.rs Rename HandlerInner::delay_span_bug as HandlerInner::span_delayed_bug. 2023-12-02 09:01:19 +11:00
metadata.rs rustc_metadata: Remove Span from ModChild 2023-04-18 17:25:04 +03:00
tests.rs
thir.rs Don't include destruction scopes in THIR 2023-12-04 16:31:13 +00:00
values.rs rustc: hir().local_def_id_to_hir_id() -> tcx.local_def_id_to_hir_id() cleanup 2023-11-26 12:41:21 +03:00