rust/compiler
Nicholas Nethercote 9f089e080c Add {ast,hir,thir}::PatKind::Missing variants.
"Missing" patterns are possible in bare fn types (`fn f(u32)`) and
similar places. Currently these are represented in the AST with
`ast::PatKind::Ident` with no `by_ref`, no `mut`, an empty ident, and no
sub-pattern. This flows through to `{hir,thir}::PatKind::Binding` for
HIR and THIR.

This is a bit nasty. It's very non-obvious, and easy to forget to check
for the exceptional empty identifier case.

This commit adds a new variant, `PatKind::Missing`, to do it properly.

The process I followed:
- Add a `Missing` variant to `{ast,hir,thir}::PatKind`.
- Chang `parse_param_general` to produce `ast::PatKind::Missing`
  instead of `ast::PatKind::Missing`.
- Look through `kw::Empty` occurrences to find functions where an
  existing empty ident check needs replacing with a `PatKind::Missing`
  check: `print_param`, `check_trait_item`, `is_named_param`.
- Add a `PatKind::Missing => unreachable!(),` arm to every exhaustive
  match identified by the compiler.
- Find which arms are actually reachable by running the test suite,
  changing them to something appropriate, usually by looking at what
  would happen to a `PatKind::Ident`/`PatKind::Binding` with no ref, no
  `mut`, an empty ident, and no subpattern.

Quite a few of the `unreachable!()` arms were never reached. This makes
sense because `PatKind::Missing` can't happen in every pattern, only
in places like bare fn tys and trait fn decls.

I also tried an alternative approach: modifying `ast::Param::pat` to
hold an `Option<P<Pat>>` instead of a `P<Pat>`, but that quickly turned
into a very large and painful change. Adding `PatKind::Missing` is much
easier.
2025-03-28 09:18:57 +11:00
..
rustc Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
rustc_abi Use {Decodable,Encodable}_NoContext in type_ir 2025-03-15 06:34:36 +00:00
rustc_arena Remove #![warn(unreachable_pub)] from all compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_ast Add {ast,hir,thir}::PatKind::Missing variants. 2025-03-28 09:18:57 +11:00
rustc_ast_ir Use -Wunused_crate_dependencies for compiler crates. 2025-03-20 08:59:43 +11:00
rustc_ast_lowering Add {ast,hir,thir}::PatKind::Missing variants. 2025-03-28 09:18:57 +11:00
rustc_ast_passes Add {ast,hir,thir}::PatKind::Missing variants. 2025-03-28 09:18:57 +11:00
rustc_ast_pretty Add {ast,hir,thir}::PatKind::Missing variants. 2025-03-28 09:18:57 +11:00
rustc_attr_data_structures add rustc_macro_edition_2021 2025-03-19 17:37:35 +01:00
rustc_attr_parsing Avoid kw::Empty when dealing with rustc_allowed_through_unstable_modules. 2025-03-25 16:48:03 +11:00
rustc_baked_icu_data Add unreachable_pub to RUSTC_LINT_FLAGS for compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_borrowck Add environment variable tracking in places where it was convenient 2025-03-26 15:46:40 +01:00
rustc_builtin_macros Rollup merge of #138898 - fmease:decrustify-parser-post-ty-ascr, r=compiler-errors 2025-03-26 19:40:28 +11:00
rustc_codegen_cranelift Update compiler-builtins to 0.1.152 2025-03-24 00:29:21 +00:00
rustc_codegen_gcc Remove implicit #[no_mangle] for #[rustc_std_internal_symbol] 2025-03-17 14:08:09 +00:00
rustc_codegen_llvm Auto merge of #138893 - klensy:thorin-0.9, r=Mark-Simulacrum 2025-03-26 07:54:26 +00:00
rustc_codegen_ssa Always emit native-static-libs note, even if it is empty 2025-03-26 21:59:00 +01:00
rustc_const_eval Rollup merge of #138713 - RalfJung:memory-hook-pointers, r=oli-obk 2025-03-21 06:56:47 +01:00
rustc_data_structures Add TyCtx::env_var_os 2025-03-26 15:46:05 +01:00
rustc_driver Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
rustc_driver_impl Implement supported-crate-types print request 2025-03-23 19:08:54 +08:00
rustc_error_codes Avoid kw::Empty when dealing with rustc_allowed_through_unstable_modules. 2025-03-25 16:48:03 +11:00
rustc_error_messages Rollup merge of #138404 - bjorn3:sysroot_handling_cleanup, r=petrochenkov,jieyouxu 2025-03-13 11:28:35 +01:00
rustc_errors Do not suggest using -Zmacro-backtrace for builtin macros 2025-03-14 19:50:03 +00:00
rustc_expand Rollup merge of #138898 - fmease:decrustify-parser-post-ty-ascr, r=compiler-errors 2025-03-26 19:40:28 +11:00
rustc_feature Stabilize precise_capturing_in_traits 2025-03-23 14:11:04 +00:00
rustc_fluent_macro Remove #![warn(unreachable_pub)] from all compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_fs_util Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
rustc_graphviz Remove #![warn(unreachable_pub)] from all compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_hashes Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
rustc_hir Add {ast,hir,thir}::PatKind::Missing variants. 2025-03-28 09:18:57 +11:00
rustc_hir_analysis Add {ast,hir,thir}::PatKind::Missing variants. 2025-03-28 09:18:57 +11:00
rustc_hir_pretty Add {ast,hir,thir}::PatKind::Missing variants. 2025-03-28 09:18:57 +11:00
rustc_hir_typeck Add {ast,hir,thir}::PatKind::Missing variants. 2025-03-28 09:18:57 +11:00
rustc_incremental Auto merge of #138629 - Zoxc:graph-anon-hashmap, r=oli-obk 2025-03-24 15:02:09 +00:00
rustc_index Use {Decodable,Encodable}_NoContext in type_ir 2025-03-15 06:34:36 +00:00
rustc_index_macros Add unreachable_pub to RUSTC_LINT_FLAGS for compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_infer Obligation::as_goal 2025-03-23 18:18:47 +00:00
rustc_interface Rollup merge of #138672 - Zoxc:deferred-queries-in-deadlock-handler, r=oli-obk 2025-03-27 15:57:22 +11:00
rustc_lexer Revert "Rollup merge of #136355 - GuillaumeGomez:proc-macro_add_value_retrieval_methods, r=Amanieu" 2025-03-18 13:28:56 +01:00
rustc_lint Add {ast,hir,thir}::PatKind::Missing variants. 2025-03-28 09:18:57 +11:00
rustc_lint_defs add FCW to warn about wasm ABI transition 2025-03-25 08:22:35 +01:00
rustc_llvm coverage: Add LLVM plumbing for expansion regions 2025-03-20 12:40:36 +11:00
rustc_log Use -Wunused_crate_dependencies for compiler crates. 2025-03-20 08:59:43 +11:00
rustc_macros Move codec module back into middle 2025-03-15 06:42:48 +00:00
rustc_metadata Rollup merge of #138483 - azhogin:azhogin/target-modifiers-bool-fix, r=fee1-dead 2025-03-26 19:40:27 +11:00
rustc_middle Add {ast,hir,thir}::PatKind::Missing variants. 2025-03-28 09:18:57 +11:00
rustc_mir_build Add {ast,hir,thir}::PatKind::Missing variants. 2025-03-28 09:18:57 +11:00
rustc_mir_dataflow Auto merge of #138414 - matthiaskrgr:rollup-9ablqdb, r=matthiaskrgr 2025-03-12 17:27:43 +00:00
rustc_mir_transform coverage: Defer the filtering of hole spans 2025-03-21 21:23:50 +11:00
rustc_monomorphize Rollup merge of #138980 - tmiasko:collect-var-debug-info, r=compiler-errors 2025-03-27 15:57:25 +11:00
rustc_next_trait_solver Implement lint against using Interner and InferCtxtLike in random compiler crates 2025-03-26 04:39:38 +00:00
rustc_parse Add {ast,hir,thir}::PatKind::Missing variants. 2025-03-28 09:18:57 +11:00
rustc_parse_format Slim rustc_parse_format dependencies down 2025-03-23 07:30:18 +01:00
rustc_passes Add {ast,hir,thir}::PatKind::Missing variants. 2025-03-28 09:18:57 +11:00
rustc_pattern_analysis Add {ast,hir,thir}::PatKind::Missing variants. 2025-03-28 09:18:57 +11:00
rustc_privacy privacy: Visit types and traits in impls in type privacy lints 2025-03-25 12:40:02 +03:00
rustc_query_impl Use a function to create QueryStackDeferred to ensure context is Copy 2025-03-26 13:09:36 +01:00
rustc_query_system Rollup merge of #138672 - Zoxc:deferred-queries-in-deadlock-handler, r=oli-obk 2025-03-27 15:57:22 +11:00
rustc_resolve Rollup merge of #138985 - oli-obk:push-mvlqmtmyozro, r=compiler-errors 2025-03-27 15:57:25 +11:00
rustc_sanitizers Use -Wunused_crate_dependencies for compiler crates. 2025-03-20 08:59:43 +11:00
rustc_serialize Convert rustc_serialize integration tests to unit tests. 2025-03-20 08:59:50 +11:00
rustc_session Rollup merge of #138483 - azhogin:azhogin/target-modifiers-bool-fix, r=fee1-dead 2025-03-26 19:40:27 +11:00
rustc_smir Use -Wunused_crate_dependencies for compiler crates. 2025-03-20 08:59:43 +11:00
rustc_span Rollup merge of #138964 - compiler-errors:usage-of-interner, r=lcnr 2025-03-27 15:57:24 +11:00
rustc_symbol_mangling Use -Wunused_crate_dependencies for compiler crates. 2025-03-20 08:59:43 +11:00
rustc_target Auto merge of #138601 - RalfJung:wasm-abi-fcw, r=alexcrichton 2025-03-26 00:06:46 +00:00
rustc_trait_selection Auto merge of #139012 - Zalathar:rollup-qgt5yfo, r=Zalathar 2025-03-27 07:47:39 +00:00
rustc_traits Rollup merge of #138394 - lcnr:yeet-variant, r=compiler-errors 2025-03-12 10:19:32 -07:00
rustc_transmute Add #[cfg(test)] for Transition in dfa 2025-03-18 07:17:16 +00:00
rustc_ty_utils Don't ICE when encountering placeholders in layout computation 2025-03-24 16:57:07 +00:00
rustc_type_ir Implement lint against using Interner and InferCtxtLike in random compiler crates 2025-03-26 04:39:38 +00:00
rustc_type_ir_macros Fold visit into ty 2025-03-15 06:34:36 +00:00
stable_mir Rollup merge of #138536 - makai410:mut-mir-visitor, r=celinval 2025-03-22 11:59:17 +01:00