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

incorrect borrow conflict with temporary borrow #7211

Closed
thestinger opened this issue Jun 18, 2013 · 6 comments
Closed

incorrect borrow conflict with temporary borrow #7211

thestinger opened this issue Jun 18, 2013 · 6 comments
Assignees
Labels
A-lifetimes Area: Lifetimes / regions P-low Low priority

Comments

@thestinger
Copy link
Contributor

    pub fn sub_free_region(&self, sub: FreeRegion, sup: FreeRegion) -> bool {
        /*!
         * Determines whether two free regions have a subregion relationship
         * by walking the graph encoded in `free_region_map`.  Note that
         * it is possible that `sub != sup` and `sub <= sup` and `sup <= sub`
         * (that is, the user can give two different names to the same lifetime).
         */

        if sub == sup {
            return true;
        }

        // Do a little breadth-first-search here.  The `queue` list
        // doubles as a way to detect if we've seen a particular FR
        // before.  Note that we expect this graph to be an *extremely
        // shallow* tree.
        let mut queue = ~[sub];
        let mut i = 0;
        while i < queue.len() {
            match self.free_region_map.find(&queue[i]) {
                Some(parents) => {
                    for parents.each |parent| {
                        if *parent == sup {
                            return true;
                        }

                        if !queue.iter().contains_(&parent) {
                            queue.push(*parent);
                        }
                    }
                }
                None => {}
            }
            i += 1;
        }
        return false;
    }
/home/strcat/projects/rust/src/librustc/middle/region.rs:206:28: 206:33 error: cannot borrow `queue` as mutable because it is also borrowed as immutable
/home/strcat/projects/rust/src/librustc/middle/region.rs:206                             queue.push(*parent);
                                                                                         ^~~~~
/home/strcat/projects/rust/src/librustc/middle/region.rs:205:28: 205:33 note: second borrow of `queue` occurs here
/home/strcat/projects/rust/src/librustc/middle/region.rs:205                         if !queue.iter().contains_(&parent) {
                                                                                         ^~~~~

This happens with the expression done in a block by itself with the bool result stored in a variable too. It's not related to it being in the if statement's conditional.

I'm finding it hard to reproduce a simple example, I'll get one here when I have time.

@ghost ghost assigned nikomatsakis Jun 18, 2013
@metajack
Copy link
Contributor

metajack commented Aug 8, 2013

visiting for triage. nominating production ready.

@catamorphism
Copy link
Contributor

Accepted for production-ready

@ezyang
Copy link
Contributor

ezyang commented Dec 17, 2013

It's hard to tell without more of the surrounding types, but isn't this Issue #6393? @metajack originally reported that "If you borrow immutably in an if test, the borrow lasts for the whole if expression”, but through my testing, this does not occur for simple examples (possibly the reason why @thestinger was having difficulty reproducing). I think the key is that a @mut has to show up somewhere in the borrow.

@nikomatsakis
Copy link
Contributor

I'm not sure if this is #6393 or not. However, I don't think @mut has anything to do with #6393 in particular. Moreover, @metajack's description was not 100% accurate; merely borrowing in an if does not necessarily extend the borrow to the entire if.

@pnkfelix
Copy link
Member

Assigning P-low, not a 1.0 blocker. (Also, we should revise the test case in the description to match something that we actually expect to compile. And we should test whether it still reproduces now.)

@alexcrichton
Copy link
Member

Lots of time has passed since this was opened, as well as lots of code changing in the meantime (including the borrow checker!). The code snippet isn't exactly standalone, so I'm going to close this out of age, but it can certainly be reopened if it can be reproduced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions P-low Low priority
Projects
None yet
Development

No branches or pull requests

7 participants