Skip to content

Regioned destructors don't run in the right order #3164

Closed

Description

@bblum

I believe the issue is simply that destructors are run in regardless order of borrows. Instead, the destructors with borrows should run first.

This code prints, rust: ~"bye \xffffff91"

class defer {
    x: &str;
    new(x: &str) { self.x = x; }
    drop { #error["%s", self.x]; }
}

fn main() {
    let _x = defer(~"Goodbye world!");
    #error["..."];
}

and this code segfaults:

class defer {
    x: &[&str];
    new(x: &[&str]) { self.x = x; }
    drop { #error["%?", self.x]; }
}

fn main() {
    let _x = defer(~["Goodbye", "world!"]);
}

Activity

  1. bblum commented on Aug 9, 2012

    @bblum
    ContributorAuthor

    Dup of #2977

  2. nikomatsakis commented on Aug 17, 2012

    @nikomatsakis
    Contributor

    This currently fails with "illegal borrow", as of ea549e7

  3. added a commit that references this issue on Nov 17, 2023
  4. added a commit that references this issue on Aug 21, 2026
    dcdbbdd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-destructorsArea: Destructors (`Drop`, …)A-lifetimesArea: Lifetimes / regionsI-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions