Commit 9f089e0
committed
Add
"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.{ast,hir,thir}::PatKind::Missing variants.1 parent 217693a commit 9f089e0
File tree
40 files changed
+86
-46
lines changed- compiler
- rustc_ast_lowering/src
- rustc_ast_passes/src
- rustc_ast_pretty/src/pprust
- rustc_ast/src
- rustc_hir_analysis/src/check
- rustc_hir_pretty/src
- rustc_hir_typeck/src
- rustc_hir/src
- rustc_lint/src
- rustc_middle/src
- thir
- rustc_mir_build/src
- builder/matches
- thir
- pattern
- rustc_parse/src/parser
- rustc_passes/src
- rustc_pattern_analysis/src
- src
- librustdoc/clean
- tools
- clippy
- clippy_lints/src
- matches
- utils
- clippy_utils/src
- ast_utils
- rustfmt/src
- tests/ui
- macros
- unpretty
40 files changed
+86
-46
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
563 | 563 | | |
564 | 564 | | |
565 | 565 | | |
| 566 | + | |
566 | 567 | | |
567 | 568 | | |
568 | 569 | | |
| |||
625 | 626 | | |
626 | 627 | | |
627 | 628 | | |
628 | | - | |
| 629 | + | |
| 630 | + | |
629 | 631 | | |
630 | 632 | | |
631 | 633 | | |
| |||
676 | 678 | | |
677 | 679 | | |
678 | 680 | | |
| 681 | + | |
679 | 682 | | |
680 | 683 | | |
681 | 684 | | |
| |||
769 | 772 | | |
770 | 773 | | |
771 | 774 | | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
772 | 778 | | |
773 | 779 | | |
774 | 780 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1572 | 1572 | | |
1573 | 1573 | | |
1574 | 1574 | | |
1575 | | - | |
| 1575 | + | |
1576 | 1576 | | |
1577 | 1577 | | |
1578 | 1578 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
727 | 727 | | |
728 | 728 | | |
729 | 729 | | |
730 | | - | |
| 730 | + | |
731 | 731 | | |
732 | 732 | | |
733 | 733 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1495 | 1495 | | |
1496 | 1496 | | |
1497 | 1497 | | |
| 1498 | + | |
1498 | 1499 | | |
1499 | 1500 | | |
1500 | 1501 | | |
| |||
1506 | 1507 | | |
1507 | 1508 | | |
1508 | 1509 | | |
1509 | | - | |
| 1510 | + | |
1510 | 1511 | | |
1511 | 1512 | | |
1512 | 1513 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
242 | | - | |
| 242 | + | |
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1622 | 1622 | | |
1623 | 1623 | | |
1624 | 1624 | | |
1625 | | - | |
1626 | | - | |
| 1625 | + | |
1627 | 1626 | | |
| 1627 | + | |
1628 | 1628 | | |
1629 | 1629 | | |
1630 | 1630 | | |
| |||
1946 | 1946 | | |
1947 | 1947 | | |
1948 | 1948 | | |
1949 | | - | |
1950 | | - | |
1951 | | - | |
1952 | | - | |
1953 | | - | |
1954 | | - | |
| 1949 | + | |
1955 | 1950 | | |
1956 | 1951 | | |
1957 | 1952 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1516 | 1516 | | |
1517 | 1517 | | |
1518 | 1518 | | |
| 1519 | + | |
1519 | 1520 | | |
1520 | 1521 | | |
1521 | 1522 | | |
| |||
1543 | 1544 | | |
1544 | 1545 | | |
1545 | 1546 | | |
1546 | | - | |
| 1547 | + | |
1547 | 1548 | | |
1548 | 1549 | | |
1549 | 1550 | | |
| |||
1681 | 1682 | | |
1682 | 1683 | | |
1683 | 1684 | | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
1684 | 1688 | | |
1685 | 1689 | | |
1686 | 1690 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
744 | 744 | | |
745 | 745 | | |
746 | 746 | | |
747 | | - | |
| 747 | + | |
748 | 748 | | |
749 | 749 | | |
750 | 750 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
701 | 701 | | |
702 | 702 | | |
703 | 703 | | |
| 704 | + | |
704 | 705 | | |
705 | 706 | | |
706 | 707 | | |
| |||
0 commit comments