Skip to content

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