Skip to content

Borrow checker should exploit information provided by match alternatives #13956

Closed
@zwarich

Description

@zwarich

The following code gives a borrow checker error because the borrow of a in the result of a.foo() overlaps with the mutable borrow of a.bar():

struct A<S>;

impl<S> A<S> {
    fn foo<'a>(&'a self) -> Option<&'a uint> { None }
    fn bar(&mut self) { }
}

fn baz<S>(a: &mut A<S>) -> bool {
    match a.foo() {
        Some(i) => true,
        None => { a.bar(); false }
    }
}

The borrow checker should be able to recognize that the None alternative of matching an Option<&T> can't contain a borrowed pointer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions