rust/compiler
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
..
rustc Clean up rustc_*/Cargo.toml. 2023-10-30 08:46:02 +11:00
rustc_abi Rename LayoutCalculator::delay_bug as LayoutCalculator::delayed_bug. 2023-12-02 09:01:34 +11:00
rustc_arena rustc_arena: add alloc_str 2023-12-05 17:52:51 -08:00
rustc_ast Introduce closure_id method on CoroutineKind 2023-12-08 21:46:39 +00:00
rustc_ast_lowering Rollup merge of #118766 - compiler-errors:lower-spans, r=spastorino 2023-12-09 14:05:11 +01:00
rustc_ast_passes Rename some more coro_kind -> coroutine_kind 2023-12-08 21:46:40 +00:00
rustc_ast_pretty Auto merge of #118420 - compiler-errors:async-gen, r=eholk 2023-12-08 19:13:57 +00:00
rustc_attr Use Session::diagnostic in more places. 2023-12-02 09:01:35 +11:00
rustc_baked_icu_data Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_borrowck Rollup merge of #118638 - nnethercote:rustc_mir_dataflow-more, r=cjgillot 2023-12-09 14:05:10 +01:00
rustc_builtin_macros Rename some more coro_kind -> coroutine_kind 2023-12-08 21:46:40 +00:00
rustc_codegen_cranelift Add simd_masked_{load,store} platform-intrinsics 2023-12-09 12:36:08 +01:00
rustc_codegen_gcc Auto merge of #117873 - quininer:android-emutls, r=Amanieu 2023-12-09 05:32:35 +00:00
rustc_codegen_llvm Rollup merge of #117953 - farnoy:masked-load-store, r=workingjubilee 2023-12-09 14:05:09 +01:00
rustc_codegen_ssa Rollup merge of #118610 - krasimirgg:llvm-18-dec, r=nikic 2023-12-09 00:48:09 -08:00
rustc_const_eval Auto merge of #118689 - compiler-errors:const-drop, r=fee1-dead 2023-12-08 13:43:12 +00:00
rustc_data_structures 1. fix jobserver GLOBAL_CLIENT_CHECKED uninitialized before use 2023-12-08 09:50:28 +08:00
rustc_driver Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_driver_impl rustc_driver_impl: Address all rustc::potential_query_instability lints 2023-12-05 06:19:14 +01:00
rustc_error_codes Yeet E0744 2023-11-28 20:40:38 +00:00
rustc_error_messages Remove rustc_error_messages/messages.ftl. 2023-11-26 08:37:27 +11:00
rustc_errors Rollup merge of #118057 - bvanjoi:fix-118048, r=cjgillot 2023-12-09 14:05:09 +01:00
rustc_expand Auto merge of #118420 - compiler-errors:async-gen, r=eholk 2023-12-08 19:13:57 +00:00
rustc_feature Auto merge of #118605 - fee1-dead-contrib:rm-rustc_host, r=compiler-errors 2023-12-06 16:00:24 +00:00
rustc_fluent_macro Add a useful comment. 2023-11-26 08:38:02 +11:00
rustc_fs_util Clean up rustc_*/Cargo.toml. 2023-10-30 08:46:02 +11:00
rustc_graphviz remove unused pub fn 2023-11-23 14:11:02 +03:00
rustc_hir Auto merge of #118420 - compiler-errors:async-gen, r=eholk 2023-12-08 19:13:57 +00:00
rustc_hir_analysis Add simd_masked_{load,store} platform-intrinsics 2023-12-09 12:36:08 +01:00
rustc_hir_pretty Remove #[rustc_host], use internal desugaring 2023-12-05 01:15:21 +00:00
rustc_hir_typeck Rollup merge of #118502 - Young-Flash:fix, r=compiler-errors 2023-12-08 23:15:12 +01:00
rustc_incremental Rename HandlerInner::delayed_span_bugs as HandlerInner::span_delayed_bugs. 2023-12-02 09:01:34 +11:00
rustc_index Replace no_ord_impl with orderable. 2023-11-22 18:38:17 +11:00
rustc_index_macros Put backticks around some attributes in doc comments. 2023-11-27 09:37:01 +11:00
rustc_infer Rollup merge of #118730 - jyn514:cmp_refs, r=estebank,compiler-errors 2023-12-08 23:15:13 +01:00
rustc_interface 1. fix jobserver GLOBAL_CLIENT_CHECKED uninitialized before use 2023-12-08 09:50:28 +08:00
rustc_lexer Tweak Mode. 2023-12-09 09:30:32 +11:00
rustc_lint Rename some more coro_kind -> coroutine_kind 2023-12-08 21:46:40 +00:00
rustc_lint_defs Auto merge of #118324 - RalfJung:ctfe-read-only-pointers, r=saethlin 2023-12-07 18:11:01 +00:00
rustc_llvm Auto merge of #117873 - quininer:android-emutls, r=Amanieu 2023-12-09 05:32:35 +00:00
rustc_log rustc_log: provide a way to init logging based on the values, not names, of the env vars 2023-11-11 15:24:33 +01:00
rustc_macros Unify HashStable implementations 2023-11-21 05:49:45 +00:00
rustc_metadata Auto merge of #118488 - andjo403:remove_deadlock, r=SparrowLii 2023-12-05 14:02:15 +00:00
rustc_middle Auto merge of #118308 - Nadrieril:sound-exhaustive-patterns-take-3, r=compiler-errors 2023-12-09 19:03:03 +00:00
rustc_mir_build Auto merge of #118308 - Nadrieril:sound-exhaustive-patterns-take-3, r=compiler-errors 2023-12-09 19:03:03 +00:00
rustc_mir_dataflow Tweak GenKillAnalysis. 2023-12-08 09:49:11 +11:00
rustc_mir_transform Rollup merge of #118764 - compiler-errors:fused-async-iterator, r=eholk 2023-12-09 00:48:11 -08:00
rustc_monomorphize Rollup merge of #118693 - saethlin:alignment-check-symbol-reachable, r=bjorn3 2023-12-08 06:44:42 +01:00
rustc_next_trait_solver Make it not depend on nightly conditionally 2023-12-08 17:44:01 +00:00
rustc_parse Auto merge of #118420 - compiler-errors:async-gen, r=eholk 2023-12-08 19:13:57 +00:00
rustc_parse_format Auto merge of #117819 - fmease:rustc_parse_format-stable-rustc, r=Nilstrieb 2023-11-15 14:55:35 +00:00
rustc_passes Remove #[rustc_host], use internal desugaring 2023-12-05 01:15:21 +00:00
rustc_privacy privacy: visit trait def id of projections 2023-12-08 14:26:03 +00:00
rustc_query_impl QueryContext: rename try_collect_active_jobs -> collect_active_jobs and change it's return type from Option<QueryMap> to QueryMap 2023-11-27 18:13:15 +03:00
rustc_query_system Rollup merge of #118123 - RalfJung:internal-lib-features, r=compiler-errors 2023-12-05 14:52:41 -05:00
rustc_resolve Introduce closure_id method on CoroutineKind 2023-12-08 21:46:39 +00:00
rustc_serialize Call FileEncoder::finish in rmeta encoding 2023-11-22 22:49:22 -05:00
rustc_session Strengthen well known check-cfg names and values test 2023-12-09 11:59:46 +01:00
rustc_smir Rollup merge of #118694 - celinval:smir-alloc-methods, r=ouz-a 2023-12-08 23:15:12 +01:00
rustc_span Add simd_masked_{load,store} platform-intrinsics 2023-12-09 12:36:08 +01:00
rustc_symbol_mangling CFI: Add char to CFI integer normalization 2023-12-07 11:28:16 -08:00
rustc_target Auto merge of #118150 - roblabla:new-win7-targets, r=davidtwco 2023-12-09 08:41:50 +00:00
rustc_trait_selection Rollup merge of #118762 - compiler-errors:gen-nits, r=eholk 2023-12-09 00:48:11 -08:00
rustc_traits add unused NormalizesTo predicate 2023-12-07 17:52:51 +01:00
rustc_transmute Update itertools to 0.11. 2023-11-22 08:13:21 +11:00
rustc_ty_utils Implement async gen blocks 2023-12-08 17:23:25 +00:00
rustc_type_ir Feedback 2023-12-08 17:44:01 +00:00
stable_mir Add tests to allocation methods and fix is_null() 2023-12-07 17:01:29 -08:00