Skip to content

Conversation

pcwalton
Copy link
Contributor

This fixes borrow checking for closures. Code like this will break:

struct Foo {
    x: int,
}

pub fn main() {
    let mut this = &mut Foo {
        x: 1,
    };
    let r = || {
        let p = &this.x;
        &mut this.x;
    };
    r()
}

Change this code to not take multiple mutable references to the same value. For
example:

struct Foo {
    x: int,
}

pub fn main() {
    let mut this = &mut Foo {
        x: 1,
    };
    let r = || {
        &mut this.x;
    };
    r()
}

Closes #16361.

[breaking-change]

r? @nikomatsakis

This fixes borrow checking for closures. Code like this will break:

    struct Foo {
        x: int,
    }

    pub fn main() {
        let mut this = &mut Foo {
            x: 1,
        };
        let r = || {
            let p = &this.x;
            &mut this.x;
        };
        r()
    }

Change this code to not take multiple mutable references to the same value. For
example:

    struct Foo {
        x: int,
    }

    pub fn main() {
        let mut this = &mut Foo {
            x: 1,
        };
        let r = || {
            &mut this.x;
        };
        r()
    }

Closes rust-lang#16361.

[breaking-change]
bors added a commit that referenced this pull request Aug 13, 2014
…tsakis

This fixes borrow checking for closures. Code like this will break:

    struct Foo {
        x: int,
    }

    pub fn main() {
        let mut this = &mut Foo {
            x: 1,
        };
        let r = || {
            let p = &this.x;
            &mut this.x;
        };
        r()
    }

Change this code to not take multiple mutable references to the same value. For
example:

    struct Foo {
        x: int,
    }

    pub fn main() {
        let mut this = &mut Foo {
            x: 1,
        };
        let r = || {
            &mut this.x;
        };
        r()
    }

Closes #16361.

[breaking-change]

r? @nikomatsakis
@bors bors closed this Aug 13, 2014
@bors bors merged commit f1799fd into rust-lang:master Aug 13, 2014
matthiaskrgr pushed a commit to matthiaskrgr/rust that referenced this pull request Feb 11, 2024
…tic, r=Veykril

feat: Add diagnostic with fix to replace trailing `return <val>;` with `<val>`

Works for functions and closures.
Ignores desugared return expressions (e.g. from desugared try operators).

Fixes: rust-lang#10970
Completes: rust-lang#11020
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.

Incomplete borrow checking with closures
3 participants