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

librustc: Forbid partial reinitialization of uninitialized structures or enumerations that implement the Drop trait. #18963

Closed
wants to merge 1 commit into from

Conversation

pcwalton
Copy link
Contributor

This breaks code like:

struct Struct {
    f: String,
    g: String,
}

impl Drop for Struct { ... }

fn main() {
    let x = Struct { ... };
    drop(x);
    x.f = ...;
}

Change this code to not create partially-initialized structures. For
example:

struct Struct {
    f: String,
    g: String,
}

impl Drop for Struct { ... }

fn main() {
    let x = Struct { ... };
    drop(x);
    x = Struct {
        f: ...,
        g: ...,
    }
}

Closes #18571.

[breaking-change]

I suspect I may have missed some cases that I should have checked.

r? @nikomatsakis

enumerations that implement the `Drop` trait.

This breaks code like:

    struct Struct {
        f: String,
        g: String,
    }

    impl Drop for Struct { ... }

    fn main() {
        let x = Struct { ... };
        drop(x);
        x.f = ...;
    }

Change this code to not create partially-initialized structures. For
example:

    struct Struct {
        f: String,
        g: String,
    }

    impl Drop for Struct { ... }

    fn main() {
        let x = Struct { ... };
        drop(x);
        x = Struct {
            f: ...,
            g: ...,
        }
    }

Closes rust-lang#18571.

[breaking-change]
@pcwalton pcwalton changed the title librustc: Forbid partial reinitialization of uninitialized structures or librustc: Forbid partial reinitialization of uninitialized structures or enumerations that implement the Drop trait. Nov 14, 2014
@nikomatsakis
Copy link
Contributor

@pcwalton pnkfelix's fragments PR landed, so I think that loan-paths have easily accessible types now.

@alexcrichton
Copy link
Member

Closing out of inactivity (and to help clear out @bors's queue).

bors added a commit that referenced this pull request Feb 13, 2015
borrowck: Prevent partial reinitialization of uninitialized structures

This is a pnkfelix-swiped squash of #22079, which was a rebase and revision of #18963

Fixes #18571.
lnicola added a commit to lnicola/rust that referenced this pull request Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undetected use after move
3 participants