Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Borrowck doesn't handle &mut correctly anymore #3765

Closed
nikomatsakis opened this issue Oct 14, 2012 · 1 comment
Closed

Borrowck doesn't handle &mut correctly anymore #3765

nikomatsakis opened this issue Oct 14, 2012 · 1 comment
Labels
A-lifetimes Area: lifetime related I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Milestone

Comments

@nikomatsakis
Copy link
Contributor

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!

@nikomatsakis
Copy link
Contributor Author

Oh, this isn't quite the bug I thought it was. This has to do with the compatible loan check. It checks that new loans are compatible with old loans but not that new loans are compatible with each other. Got a fix, testing now.

nikomatsakis added a commit to nikomatsakis/rust that referenced this issue Oct 14, 2012
Along the way, convert from dvec-of-dvec representation to track loans in scope
to just a single flattened list.  It's more convenient.

No review: small bug fix.

Fixes rust-lang#3765.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: lifetime related I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Projects
None yet
Development

No branches or pull requests

1 participant