-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Commit ed09cd9
Auto merge of #143764 - dianne:primary-binding-drop-order, r=Nadrieril,traviscross
lower pattern bindings in the order they're written and base drop order on primary bindings' order
To fix #142163, this PR does two things:
- Makes match arms base their drop order on the first sub-branch instead of the last sub-branch. Together with the second change, this makes bindings' drop order correspond to the relative order of when each binding first appears (i.e. the order of the "primary" bindings).
- Lowers pattern bindings in the order they're written (still treating the right-hand side of a ``@`` as coming before the binding on the left). In each sub-branch of a match arm, this is the order that would be obtained if the or-alternatives chosen in that sub-branch were inlined into the arm's pattern. This both affects drop order (making bindings in or-patterns not be dropped first) and fixes the issue in [this test](https://github.com/rust-lang/rust/blob/2a023bf80a6fbd6a06d5460a34eb247b986286ed/tests/ui/pattern/bindings-after-at/bind-by-copy-or-pat.rs) from #121716.
My approach to the second point is admittedly a bit trickier than may be necessary. To avoid passing around a counter when building `FlatPat`s, I've instead added just enough information to recover the original structure of the pattern's bindings from a `MatchTreeSubBranch`'s path through the `Candidate` tree. Some alternatives:
- We could use a counter, then sort bindings by their ordinals when making `MatchTreeSubBranch`es.
- I'd like to experiment with always merging sub-candidates and removing `test_remaining_match_pairs_after_or`; that would require lowering bindings and guards in a different way. That makes it a bigger change too, though, so I figure it might be simplest to start here.
- For a very big change, we could track which or-alternatives succeed at runtime to base drop order on the binding order in the particular alternatives matched.
This is a breaking change. It will need a crater run, language team sign-off, and likely updates to the Reference.
This will conflict with #143376 and probably also #143028, so they shouldn't be merged at the same time.
r? `@matthewjasper` or `@Nadrieril`File tree
10 files changed
+197
-139
lines changed- compiler/rustc_mir_build/src/builder/matches
- tests
- mir-opt
- ui
- dropck
- drop
- pattern/bindings-after-at
10 files changed
+197
-139
lines changedLines changed: 15 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
124 | 124 |
| |
125 | 125 |
| |
126 | 126 |
| |
127 | - | ||
128 | - | ||
129 | - | ||
127 | + | ||
128 | + | ||
129 | + | ||
130 | + | ||
131 | + | ||
132 | + | ||
133 | + | ||
134 | + | ||
135 | + | ||
136 | + | ||
137 | + | ||
138 | + | ||
139 | + | ||
130 | 140 |
| |
131 | 141 |
| |
132 | 142 |
| |
| |||
194 | 204 |
| |
195 | 205 |
| |
196 | 206 |
| |
197 | - | ||
207 | + | ||
198 | 208 |
| |
199 | 209 |
| |
200 | 210 |
| |
201 | 211 |
| |
202 | - | ||
212 | + | ||
203 | 213 |
| |
204 | 214 |
| |
205 | 215 |
| |
|
Lines changed: 97 additions & 36 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5 | 5 |
| |
6 | 6 |
| |
7 | 7 |
| |
8 | - | ||
9 | 8 |
| |
10 | 9 |
| |
11 | 10 |
| |
12 | 11 |
| |
12 | + | ||
13 | 13 |
| |
14 | 14 |
| |
15 | 15 |
| |
| |||
561 | 561 |
| |
562 | 562 |
| |
563 | 563 |
| |
564 | + | ||
565 | + | ||
564 | 566 |
| |
565 | - | ||
566 | - | ||
567 | - | ||
568 | - | ||
569 | - | ||
570 | - | ||
571 | - | ||
572 | - | ||
573 | - | ||
567 | + | ||
568 | + | ||
569 | + | ||
570 | + | ||
574 | 571 |
| |
575 | 572 |
| |
576 | 573 |
| |
| |||
579 | 576 |
| |
580 | 577 |
| |
581 | 578 |
| |
582 | - | ||
583 | - | ||
584 | - | ||
585 | 579 |
| |
586 | 580 |
| |
587 | 581 |
| |
| |||
996 | 990 |
| |
997 | 991 |
| |
998 | 992 |
| |
999 | - | ||
993 | + | ||
1000 | 994 |
| |
1001 | 995 |
| |
1002 | 996 |
| |
| |||
1011 | 1005 |
| |
1012 | 1006 |
| |
1013 | 1007 |
| |
1008 | + | ||
1009 | + | ||
1010 | + | ||
1011 | + | ||
1012 | + | ||
1013 | + | ||
1014 | + | ||
1015 | + | ||
1016 | + | ||
1014 | 1017 |
| |
1015 | 1018 |
| |
1016 | 1019 |
| |
| |||
1226 | 1229 |
| |
1227 | 1230 |
| |
1228 | 1231 |
| |
1229 | - | ||
1232 | + | ||
1230 | 1233 |
| |
1231 | 1234 |
| |
1232 | 1235 |
| |
| |||
1452 | 1455 |
| |
1453 | 1456 |
| |
1454 | 1457 |
| |
1455 | - | ||
1456 | - | ||
1457 | - | ||
1458 | - | ||
1459 | - | ||
1460 | - | ||
1458 | + | ||
1461 | 1459 |
| |
1462 | 1460 |
| |
1463 | 1461 |
| |
| |||
1490 | 1488 |
| |
1491 | 1489 |
| |
1492 | 1490 |
| |
1491 | + | ||
1492 | + | ||
1493 | + | ||
1494 | + | ||
1495 | + | ||
1496 | + | ||
1497 | + | ||
1498 | + | ||
1499 | + | ||
1500 | + | ||
1501 | + | ||
1502 | + | ||
1503 | + | ||
1504 | + | ||
1505 | + | ||
1506 | + | ||
1507 | + | ||
1508 | + | ||
1509 | + | ||
1510 | + | ||
1511 | + | ||
1512 | + | ||
1513 | + | ||
1514 | + | ||
1515 | + | ||
1516 | + | ||
1517 | + | ||
1518 | + | ||
1519 | + | ||
1520 | + | ||
1521 | + | ||
1522 | + | ||
1523 | + | ||
1524 | + | ||
1525 | + | ||
1526 | + | ||
1527 | + | ||
1528 | + | ||
1529 | + | ||
1530 | + | ||
1531 | + | ||
1532 | + | ||
1533 | + | ||
1534 | + | ||
1535 | + | ||
1536 | + | ||
1537 | + | ||
1538 | + | ||
1539 | + | ||
1540 | + | ||
1541 | + | ||
1542 | + | ||
1543 | + | ||
1544 | + | ||
1545 | + | ||
1546 | + | ||
1547 | + | ||
1548 | + | ||
1549 | + | ||
1550 | + | ||
1551 | + | ||
1552 | + | ||
1493 | 1553 |
| |
1494 | 1554 |
| |
1495 | 1555 |
| |
| |||
2453 | 2513 |
| |
2454 | 2514 |
| |
2455 | 2515 |
| |
2456 | - | ||
2457 | - | ||
2458 | - | ||
2459 | - | ||
2460 | - | ||
2516 | + | ||
2517 | + | ||
2461 | 2518 |
| |
2462 | 2519 |
| |
2463 | 2520 |
| |
| |||
2489 | 2546 |
| |
2490 | 2547 |
| |
2491 | 2548 |
| |
2549 | + | ||
2550 | + | ||
2551 | + | ||
2552 | + | ||
2553 | + | ||
2554 | + | ||
2555 | + | ||
2492 | 2556 |
| |
2493 | 2557 |
| |
2494 | 2558 |
| |
| |||
2538 | 2602 |
| |
2539 | 2603 |
| |
2540 | 2604 |
| |
2541 | - | ||
2542 | - | ||
2543 | - | ||
2544 | - | ||
2545 | - | ||
2605 | + | ||
2546 | 2606 |
| |
2547 | 2607 |
| |
2548 | - | ||
2608 | + | ||
2549 | 2609 |
| |
2550 | 2610 |
| |
2551 | 2611 |
| |
| |||
2671 | 2731 |
| |
2672 | 2732 |
| |
2673 | 2733 |
| |
2674 | - | ||
2675 | 2734 |
| |
2676 | 2735 |
| |
2677 | 2736 |
| |
| |||
2690 | 2749 |
| |
2691 | 2750 |
| |
2692 | 2751 |
| |
2752 | + | ||
2693 | 2753 |
| |
2694 | 2754 |
| |
2695 | 2755 |
| |
2696 | 2756 |
| |
2697 | 2757 |
| |
2698 | - | ||
2758 | + | ||
2699 | 2759 |
| |
2700 | 2760 |
| |
2701 | 2761 |
| |
| |||
2705 | 2765 |
| |
2706 | 2766 |
| |
2707 | 2767 |
| |
2708 | - | ||
2768 | + | ||
2769 | + | ||
2709 | 2770 |
| |
2710 | 2771 |
| |
2711 | 2772 |
| |
2712 | 2773 |
| |
2713 | 2774 |
| |
2714 | - | ||
2775 | + | ||
2715 | 2776 |
| |
2716 | 2777 |
| |
2717 | 2778 |
| |
|
Lines changed: 6 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
138 | 138 |
| |
139 | 139 |
| |
140 | 140 |
| |
141 | - | ||
141 | + | ||
142 | + | ||
143 | + | ||
142 | 144 |
| |
143 | 145 |
| |
144 | 146 |
| |
| |||
147 | 149 |
| |
148 | 150 |
| |
149 | 151 |
| |
150 | - | ||
152 | + | ||
153 | + | ||
154 | + | ||
151 | 155 |
| |
152 | 156 |
| |
153 | 157 |
| |
|
Lines changed: 16 additions & 16 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
85 | 85 |
| |
86 | 86 |
| |
87 | 87 |
| |
88 | - | ||
89 | - | ||
90 | - | ||
91 | - | ||
92 | - | ||
88 | + | ||
89 | + | ||
90 | + | ||
91 | + | ||
92 | + | ||
93 | 93 |
| |
94 | 94 |
| |
95 | 95 |
| |
| |||
100 | 100 |
| |
101 | 101 |
| |
102 | 102 |
| |
103 | - | ||
104 | - | ||
105 | - | ||
106 | - | ||
107 | - | ||
103 | + | ||
104 | + | ||
105 | + | ||
106 | + | ||
107 | + | ||
108 | 108 |
| |
109 | 109 |
| |
110 | 110 |
| |
| |||
139 | 139 |
| |
140 | 140 |
| |
141 | 141 |
| |
142 | - | ||
142 | + | ||
143 | 143 |
| |
144 | 144 |
| |
145 | 145 |
| |
| |||
152 | 152 |
| |
153 | 153 |
| |
154 | 154 |
| |
155 | - | ||
156 | - | ||
155 | + | ||
156 | + | ||
157 | 157 |
| |
158 | 158 |
| |
159 | 159 |
| |
| |||
181 | 181 |
| |
182 | 182 |
| |
183 | 183 |
| |
184 | - | ||
184 | + | ||
185 | 185 |
| |
186 | 186 |
| |
187 | 187 |
| |
| |||
194 | 194 |
| |
195 | 195 |
| |
196 | 196 |
| |
197 | - | ||
198 | - | ||
197 | + | ||
198 | + | ||
199 | 199 |
| |
200 | 200 |
| |
201 | 201 |
| |
|
0 commit comments