Repository navigation
Parameter patterns are dropped *after* arguments #36088
Description
Activity
- addedA-destructorsArea: Destructors (`Drop`, …)Area: Destructors (`Drop`, …)T-langRelevant to the language teamRelevant to the language teamT-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.
on Aug 28, 2016 Really, I'd expect
xandzto be dropped at the start of the function (same as let bindings).@arielb1 What's the status of this?
This does look somewhat expected to me -
_never binds anything, so the value is dropped as soon as the pattern is matched.vkeeps the only bound value alive until the function exits, sodropping yis printed later.This still exists. With NLL it can't cause any soundness problems, but it just feels weird to me. Whatever we choose, this needs to be documented in the reference near the temporary lifetimes documentation.
Not quite. The drop of both the arguments and the patterns happens at the function end, not at function start (see my edited post).
Reacted by Jonas SchievinkThis still exists. With NLL it can't cause any soundness problems, but it just feels weird to me. Whatever we choose, this needs to be documented in the reference near the temporary lifetimes documentation.
iirc @matthewjasper has a PR to document this, rust-lang/reference#514 (I need to get back to it soon).
Also, to fix a regression, we recently changed the drop semantics so that the drop order is
y x zrather thanx y z. This is seen in https://play.rust-lang.org/?version=beta&mode=debug&edition=2018&gist=9d2cd068bf948d37a988f70f7d1bce59. Is that what you expect?Reacted by Felix S Klock IISure enough, this was fixed in #56044, with a test. Closing.
Reacted by Mazdak Farrokhzad
Meta
STR
Actual Result
Explanation
When the function exits, the argument
arg0is dropped first, followed by the variablevar0akay. This is the reverse of what happened in old trans, and looks quite unnatural. OTOH, it is quite similar tolet-bindings, so maybe that is for the best.Relation to
matchstatementsI don't think that lifetimes in
matchpatterns are a good example for anything (see #46525), but amatchstatement drops the discriminant last:prints