sdleffler / qp-trie-rs

An idiomatic and fast QP-trie implementation in pure Rust.
Mozilla Public License 2.0
94 stars 24 forks source link

compilation warning #18

Closed jsen- closed 4 years ago

jsen- commented 5 years ago

Rustc complains about multiple mutable borrows at the same time. I'm a bit worried about the "warning will become a hard error in the future" part.

rustc 1.36.0-nightly (e305df184 2019-04-24)

warning[E0499]: cannot borrow `*self` as mutable more than once at a time
   --> /home/vagrant/.cargo/registry/src/github.com-1ecc6299db9ec823/qp-trie-0.7.3/src/node.rs:502:41
    |
479 |           &mut self,
    |           - let's call the lifetime of this reference `'1`
...
485 | /         match *self {
486 | |             Node::Branch(ref mut branch) if branch.choice <= graft => {
    | |                          -------------- first mutable borrow occurs here
487 | |                 let index = branch.index(key.borrow());
488 | |
...   |
502 | |                 let node = mem::replace(self, Node::Branch(Branch::new(graft)));
    | |                                         ^^^^ second mutable borrow occurs here
...   |
517 | |             }
518 | |         }
    | |_________- returning this value requires that `self.0` is borrowed for `'1`
    |
    = warning: this error has been downgraded to a warning for backwards compatibility with previous releases
    = warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future

warning[E0499]: cannot borrow `*self` as mutable more than once at a time
   --> /home/vagrant/.cargo/registry/src/github.com-1ecc6299db9ec823/qp-trie-0.7.3/src/node.rs:505:45
    |
479 |           &mut self,
    |           - let's call the lifetime of this reference `'1`

...
485 | /         match *self {
486 | |             Node::Branch(ref mut branch) if branch.choice <= graft => {
    | |                          -------------- first mutable borrow occurs here
487 | |                 let index = branch.index(key.borrow());
488 | |
...   |
505 | |                 let graft_branch = unsafe { self.unwrap_branch_mut() };
    | |                                             ^^^^ second mutable borrow occurs here
...   |
517 | |             }
518 | |         }
    | |_________- returning this value requires that `self.0` is borrowed for `'1`
    |
    = warning: this error has been downgraded to a warning for backwards compatibility with previous releases
    = warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future
frankwillis42 commented 5 years ago

I got the same exact warning here. Is there a plan to address this warning?

messense commented 5 years ago

This is a hard error now.