rust/tests/ui/dropck
Stuart Cook 5e781d05f6
Rollup 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 rust-lang/rust#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](2a023bf80a/tests/ui/pattern/bindings-after-at/bind-by-copy-or-pat.rs) from rust-lang/rust#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 rust-lang/rust#143376 and probably also rust-lang/rust#143028, so they shouldn't be merged at the same time.

r? `@matthewjasper` or `@Nadrieril`
2025-08-07 20:49:39 +10:00
..
auxiliary
cleanup-arm-conditional.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
constrained_by_assoc_type_equality.rs Rewrite dropck 2024-07-02 02:30:38 +01:00
constrained_by_assoc_type_equality_and_self_ty.rs Rewrite dropck 2024-07-02 02:30:38 +01:00
constrained_by_assoc_type_equality_and_self_ty.stderr Rewrite dropck 2024-07-02 02:30:38 +01:00
coroutine-liveness-1.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
coroutine-liveness-2.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
drop-on-non-struct.rs
drop-on-non-struct.stderr Make new information notes instead of labels 2024-09-26 17:17:11 +00:00
drop-with-active-borrows-1.rs
drop-with-active-borrows-1.stderr Peel off explicit (or implicit) deref before suggesting clone on move error in borrowck 2024-07-26 14:41:56 -04:00
drop-with-active-borrows-2.rs
drop-with-active-borrows-2.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
dropck-after-failed-type-lowering.rs Don't immediately panic if dropck fails without returning errors 2025-02-24 16:41:18 +00:00
dropck-after-failed-type-lowering.stderr Don't immediately panic if dropck fails without returning errors 2025-02-24 16:41:18 +00:00
dropck-empty-array.rs Add special-case for [T, 0] in dropck 2024-07-31 16:15:05 +03:00
dropck-eyepatch-extern-crate.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
dropck-eyepatch-extern-crate.stderr Tweak E0597 2023-01-15 19:46:20 +00:00
dropck-eyepatch-implies-unsafe-impl.rs
dropck-eyepatch-implies-unsafe-impl.stderr
dropck-eyepatch-reorder.rs
dropck-eyepatch-reorder.stderr Tweak E0597 2023-01-15 19:46:20 +00:00
dropck-eyepatch.rs
dropck-eyepatch.stderr Tweak E0597 2023-01-15 19:46:20 +00:00
dropck-only-error-ambiguity.rs Update tests for dropck normalization errors 2025-02-17 11:33:07 +00:00
dropck-only-error-ambiguity.stderr Update tests for dropck normalization errors 2025-02-17 11:33:07 +00:00
dropck-only-error-async.rs Update tests for dropck normalization errors 2025-02-17 11:33:07 +00:00
dropck-only-error-async.stderr Update tests for dropck normalization errors 2025-02-17 11:33:07 +00:00
dropck-only-error-gat.rs Update tests for dropck normalization errors 2025-02-17 11:33:07 +00:00
dropck-only-error-gat.stderr Update tests for dropck normalization errors 2025-02-17 11:33:07 +00:00
dropck-only-error.rs Update tests for dropck normalization errors 2025-02-17 11:33:07 +00:00
dropck-only-error.stderr Update tests for dropck normalization errors 2025-02-17 11:33:07 +00:00
dropck-union.rs
dropck-union.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
dropck_fn_type.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
dropck_no_diverge_on_nonregular_1.rs Tweak E0320 overflow error wording 2024-11-05 21:54:45 +00:00
dropck_no_diverge_on_nonregular_1.stderr Tweak E0320 overflow error wording 2024-11-05 21:54:45 +00:00
dropck_no_diverge_on_nonregular_2.rs Tweak E0320 overflow error wording 2024-11-05 21:54:45 +00:00
dropck_no_diverge_on_nonregular_2.stderr Tweak E0320 overflow error wording 2024-11-05 21:54:45 +00:00
dropck_no_diverge_on_nonregular_3.rs Tweak E0320 overflow error wording 2024-11-05 21:54:45 +00:00
dropck_no_diverge_on_nonregular_3.stderr Tweak E0320 overflow error wording 2024-11-05 21:54:45 +00:00
dropck_trait_cycle_checked.rs Use non-2015 edition paths in tests that do not test for their resolution 2025-06-03 10:13:33 +02:00
dropck_trait_cycle_checked.stderr replace "cast" with "coercion" where applicable 2024-09-24 22:20:46 +02:00
dropck_traits.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
eager-by-ref-binding-for-guards.rs base drop order on the first sub-branch 2025-08-06 12:13:12 -07:00
eager-by-ref-binding-for-guards.stderr base drop order on the first sub-branch 2025-08-06 12:13:12 -07:00
explicit-drop-bounds.bad1.stderr Unconditionally run check_item_type on all items 2025-06-30 08:06:08 +00:00
explicit-drop-bounds.bad2.stderr Unconditionally run check_item_type on all items 2025-06-30 08:06:08 +00:00
explicit-drop-bounds.rs Remove manual WF hack 2025-05-07 16:29:59 +00:00
explicit-implied-outlives.bad1.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
explicit-implied-outlives.bad2.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
explicit-implied-outlives.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-24805-dropck-itemless.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-28498-ugeh-with-lifetime-param.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-28498-ugeh-with-passed-to-fn.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-28498-ugeh-with-trait-bound.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-29844.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-34053.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-38868.rs
issue-38868.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-54943-1.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-54943-2.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
let-else-more-permissive.rs emit StorageLive and schedule StorageDead for let-else after matching 2025-06-25 13:02:15 -07:00
let-else-more-permissive.stderr emit StorageLive and schedule StorageDead for let-else after matching 2025-06-25 13:02:15 -07:00
negative.rs Explicitly reject negative and reservation drop impls 2023-04-27 17:02:17 +00:00
negative.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
reject-specialized-drops-8142.rs Rewrite dropck 2024-07-02 02:30:38 +01:00
reject-specialized-drops-8142.stderr Rewrite dropck 2024-07-02 02:30:38 +01:00
relate_lt_in_type_outlives_bound.rs
relate_lt_in_type_outlives_bound.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
reservation.rs Explicitly reject negative and reservation drop impls 2023-04-27 17:02:17 +00:00
reservation.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
transitive-outlives-2.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
transitive-outlives.bad.stderr Rewrite dropck 2024-07-02 02:30:38 +01:00
transitive-outlives.rs Rewrite dropck 2024-07-02 02:30:38 +01:00
trivial-impl-bounds.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
unconstrained_const_param_on_drop.rs Unconditionally run check_item_type on all items 2025-06-30 08:06:08 +00:00
unconstrained_const_param_on_drop.stderr Unconditionally run check_item_type on all items 2025-06-30 08:06:08 +00:00