]> git.lizzy.rs Git - rust.git/commit
librustc: Forbid partial reinitialization of uninitialized structures or
authorKevin Butler <haqkrs@gmail.com>
Fri, 14 Nov 2014 23:14:52 +0000 (15:14 -0800)
committerFelix S. Klock II <pnkfelix@pnkfx.org>
Thu, 12 Feb 2015 12:55:08 +0000 (13:55 +0100)
commit32d0dbd49a372b9d2e000587497de6ffca9e1cca
tree4bcd232997be2f001ab5f26a9dda894c36936d2c
parent0fdca30fcb2303966ad2529b7a3b0599088c105d
librustc: Forbid partial reinitialization of uninitialized structures or
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 #18571.

[breaking-change]

----

(Joint authorship by pcwalton and Ryman; thanks all!)
src/librustc_borrowck/borrowck/check_loans.rs
src/librustc_borrowck/borrowck/mod.rs
src/test/compile-fail/borrowck-partial-reinit-1.rs [new file with mode: 0644]
src/test/compile-fail/borrowck-partial-reinit-2.rs [new file with mode: 0644]
src/test/compile-fail/borrowck-partial-reinit-3.rs [new file with mode: 0644]
src/test/compile-fail/borrowck-partial-reinit-4.rs [new file with mode: 0644]