Skip to content

Borrowck doesn't handle &mut correctly anymore #3765

Closed
@nikomatsakis

Description

@nikomatsakis

This USED to be an error, but doesn't seem to be anymore:

use core::either::{Either, Left, Right};

    fn f(x: &mut Either<int,float>, y: &Either<int,float>) -> int {
        match *y {
            Left(ref z) => {
                *x = Right(1.0);
                *z
            }
            _ => fail
        }
    }

    fn main() {
        let mut x: Either<int,float> = Left(3);
        io::println(f(&mut x, &x).to_str());
    } 

In particular it should not be allowed to simultaneously have an &mut and an & in scope. I recall that I changed the rules at some point around the creation of &mut pointers—that used to be considered equivalent to writing to the variable in question. I should not have changed that rule!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsI-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions