Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop can run impure code in pure functions #4170

Closed
14427 opened this issue Dec 12, 2012 · 3 comments
Closed

Drop can run impure code in pure functions #4170

14427 opened this issue Dec 12, 2012 · 3 comments
Labels
A-traits Area: Trait system

Comments

@14427
Copy link
Contributor

14427 commented Dec 12, 2012

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
@14427
Copy link
Contributor Author

14427 commented Dec 12, 2012

Not a 100% sure this is actually bad.

@catamorphism
Copy link
Contributor

Upon conferring with @nikomatsakis : This is not exactly a bug, but part of the general unsoundness to do with how we treat the Drop trait. It's not necessarily wrong that pure functions can implicitly call impure functions, but it is a problem that destructors are allowed to mutate non-owned memory.

@nikomatsakis said he would open a more general issue about Drop and unsoundness, so I'll close this.

@catamorphism
Copy link
Contributor

Follow #4301 for the more general issue!

flip1995 pushed a commit to flip1995/rust that referenced this issue Feb 10, 2023
`invalid_regex`: Show full error when string value doesn't match source

changelog: [`invalid_regex`]: Show full error when parsing non-literals or regular strings containing escape sequences

Fixes rust-lang#4170, the escape sequence there causes the span to be incorrect which will have caused most of the confusion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-traits Area: Trait system
Projects
None yet
Development

No branches or pull requests

2 participants