Skip to content

Drop can run impure code in pure functions #4170

Description

@14427

See the following code for an example:

struct Goodbye { msg: ~str }

impl Goodbye: Drop {
    fn finalize(&self) {
        io::println(self.msg);
    }
}

pure fn test() -> Goodbye {
    let x = Goodbye { msg: ~"Good" };
    let _y = Goodbye { msg: ~"Bad" };
    return x;
}

fn main() {
    io::println("Before");
    let _z = test();
    io::println("After");
}

Result:

Before
Bad
After
Good

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions