-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
inconsistent drop order for pattern bindings in the presence of or-patterns #142163
Copy link
Copy link
Closed
Closed
Copy link
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-destructorsArea: Destructors (`Drop`, …)Area: Destructors (`Drop`, …)A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-destructorsArea: Destructors (`Drop`, …)Area: Destructors (`Drop`, …)A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
When or-patterns are present in a pattern, the drop order for its bindings depends on the particular language construct used. To see it in action, see this test (#142193), but in short:
let pat;treats the bindings inpatas being in the order they first appear in the pattern, and drops them in reverse order. This is the behavior I would expect.let pat = expr;,if let, andlet-elsesee bindings in or-patterns as being after other bindings, thus they're dropped first. i.e.matcharms see bindings in or-patterns as being after other bindings, and use the final or-pattern alternative's binding order, rather than the first. i.e.Implementation-wise, this is due to differences in how pattern bindings are lowered to MIR.
let pat;, we traverse the pattern in a natural order and schedule drops for bindings here.matchusing the final or-pattern alternative's binding order is a detail of how match guards are currently implemented here.If this should change, I imagine it will need a T-lang decision on what the correct behavior should be, so cc @rust-lang/lang
@rustbot label: +T-compiler +T-lang +A-MIR +A-patterns +A-destructors