rust/compiler/rustc_passes/src
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
..
liveness compiler: Use size_of from the prelude instead of imported 2025-03-07 13:37:04 -08:00
abi_test.rs compiler: die immediately instead of handling unknown target codegen 2025-02-10 11:04:31 -08:00
check_attr.rs Rollup merge of #138786 - bjorn3:driver_code_move, r=compiler-errors 2025-03-22 21:34:39 +01:00
dead.rs Rollup merge of #138384 - nnethercote:hir-ItemKind-idents, r=fmease 2025-03-17 22:49:04 +01:00
debugger_visualizer.rs Use SourceMap to load debugger visualizer files 2024-12-08 18:57:04 +00:00
diagnostic_items.rs Move methods from Map to TyCtxt, part 4. 2025-03-12 08:55:37 +11:00
entry.rs Move methods from Map to TyCtxt, part 4. 2025-03-12 08:55:37 +11:00
errors.rs Use Option<Symbol> in DuplicateLangItem. 2025-03-25 16:20:43 +11:00
hir_id_validator.rs Adjust Map's to_string functionality. 2025-03-12 08:30:03 +11:00
input_stats.rs Add {ast,hir,thir}::PatKind::Missing variants. 2025-03-28 09:18:57 +11:00
lang_items.rs Use Option<Symbol> in DuplicateLangItem. 2025-03-25 16:20:43 +11:00
layout_test.rs Teach structured errors to display short Ty 2025-02-25 16:56:03 +00:00
lib.rs Auto merge of #138414 - matthiaskrgr:rollup-9ablqdb, r=matthiaskrgr 2025-03-12 17:27:43 +00:00
lib_features.rs Introduce new-style attribute parsers for several attributes 2025-02-24 14:31:17 +01:00
liveness.rs Move methods from Map to TyCtxt, part 4. 2025-03-12 08:55:37 +11:00
loops.rs Move methods from Map to TyCtxt, part 4. 2025-03-12 08:55:37 +11:00
naked_functions.rs Implement .use keyword as an alias of clone 2025-03-06 17:58:32 -03:00
reachable.rs Auto merge of #138630 - matthiaskrgr:rollup-kk1gogr, r=matthiaskrgr 2025-03-18 05:58:46 +00:00
stability.rs Move hir::Item::ident into hir::ItemKind. 2025-03-18 06:29:50 +11:00
upvars.rs Move methods from Map to TyCtxt, part 2. 2025-02-18 10:17:44 +11:00
weak_lang_items.rs Add support for wasm exception handling to Emscripten target 2025-01-06 10:29:54 +01:00