Commit 704a024
authored
Rollup merge of rust-lang#137269 - dianne:fix-ref-pat-label-span, r=davidtwco
Pattern Migration 2024: properly label `&` patterns whose subpatterns are from macro expansions
See the failing test output in the first commit for an example of what this going wrong looks like. The error/lint diagnostic tries to point to just the `&` or `&mut` of reference patterns when labeling the causes, to make the output clearer (rust-lang#134394). The trimming there wasn't quite right though: it used the interior of the reference pattern as a cutoff and extended backwards to find where to trim the pattern's span, but this breaks if the `&` and the interior are from different sources. This PR instead trims by starting at the start of the pattern and ending at the final character of the `&` (or `&mut`, `ref`, `ref mut`, or `mut`, depending on what the error/lint is labeling); that way, there's no opportunity for failure from mixing sources.
I'm not 100% happy with this approach, but I'm also not sure what the best practices are as far as hacky `SourceMap` munching goes, so please let me know if something else would be preferred.
Since `SourceMap::span_through_char` can't change the syntax context of the span, I've also removed a call to `Span::with_ctxt` (we care about the edition of the span in question since this is a hard error in Rust 2024). If we want to be extra safe in case that changes, I can re-add it or track error hardness separately in the `rust_2024_migration_desugared_pats` table.File tree
4 files changed
+52
-15
lines changed- compiler/rustc_hir_typeck/src
- tests/ui/pattern/rfc-3627-match-ergonomics-2024
4 files changed
+52
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
835 | 835 | | |
836 | 836 | | |
837 | 837 | | |
838 | | - | |
| 838 | + | |
839 | 839 | | |
840 | 840 | | |
841 | 841 | | |
842 | 842 | | |
843 | 843 | | |
844 | 844 | | |
845 | | - | |
| 845 | + | |
846 | 846 | | |
847 | 847 | | |
848 | 848 | | |
849 | 849 | | |
850 | 850 | | |
851 | | - | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
852 | 855 | | |
853 | 856 | | |
854 | 857 | | |
| |||
2387 | 2390 | | |
2388 | 2391 | | |
2389 | 2392 | | |
2390 | | - | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
2391 | 2397 | | |
2392 | 2398 | | |
2393 | 2399 | | |
| |||
2779 | 2785 | | |
2780 | 2786 | | |
2781 | 2787 | | |
2782 | | - | |
| 2788 | + | |
2783 | 2789 | | |
2784 | 2790 | | |
2785 | 2791 | | |
2786 | | - | |
2787 | | - | |
2788 | | - | |
2789 | | - | |
2790 | | - | |
2791 | | - | |
2792 | | - | |
2793 | | - | |
| 2792 | + | |
| 2793 | + | |
| 2794 | + | |
| 2795 | + | |
| 2796 | + | |
| 2797 | + | |
| 2798 | + | |
| 2799 | + | |
| 2800 | + | |
| 2801 | + | |
2794 | 2802 | | |
2795 | 2803 | | |
2796 | 2804 | | |
| |||
2824 | 2832 | | |
2825 | 2833 | | |
2826 | 2834 | | |
2827 | | - | |
2828 | 2835 | | |
2829 | 2836 | | |
2830 | 2837 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
247 | 253 | | |
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
247 | 253 | | |
Lines changed: 19 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
580 | 580 | | |
581 | 581 | | |
582 | 582 | | |
583 | | - | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
584 | 602 | | |
0 commit comments