Skip to content

Parameter patterns are dropped *after* arguments #36088

Closed
@arielb1

Description

@arielb1

Meta

$ rustc -V
rustc 1.13.0-dev (528c6f3ed 2016-08-25)

STR

struct NoisyDrop(&'static str);
impl Drop for NoisyDrop {
    fn drop(&mut self) {
        println!("dropping {}", self.0);
    }
}

fn argument_buf((_,v,_): (NoisyDrop, NoisyDrop, NoisyDrop)) {
    println!("in argument_buf");
}
fn main() {
    argument_buf((NoisyDrop("x"), NoisyDrop("y"), NoisyDrop("z")));
}

Actual Result

in argument_buf
dropping x
dropping z
dropping y

Explanation

When the function exits, the argument arg0 is dropped first, followed by the variable var0 aka y. This is the reverse of what happened in old trans, and looks quite unnatural. OTOH, it is quite similar to let-bindings, so maybe that is for the best.

Relation to match statements

I don't think that lifetimes in match patterns are a good example for anything (see #46525), but a match statement drops the discriminant last:

    match (NoisyDrop("x"), NoisyDrop("y"), NoisyDrop("z")) {
        (_, v, _) => println!("in match")
    }

prints

in match
dropping y
dropping x
dropping z

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-destructorsArea: Destructors (`Drop`, …)C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions