- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I have:
pub fn infer_defaults(&mut self, project_dir: &Path) -> CargoResult<()> {
    ....
    match &mut self.target_dir {
            Inferrable::Specified(Some(ref mut path)) if path.is_relative() => {
                *path = project_dir.join(&path);
            }
            _ => {},
        }
    ...
}
(from https://github.com/rust-lang-nursery/rls/blob/master/src/config.rs#L238-L277)
And I get the following warning:
warning[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
   --> src/config.rs:259:40
    |
257 |         match &mut self.target_dir {
    |               -------------------- immutable borrow occurs here
258 |             // We require an absolute path, so adjust a relative one if it's passed.
259 |             Inferrable::Specified(Some(ref mut path)) if path.is_relative() => {
    |                                        ^^^^^^^^^^^^ mutable borrow occurs here
...
262 |             _ => {},
    |             - borrow later used here
    |
    = warning: This error has been downgraded to a warning for backwards compatibility with previous releases.
            It represents potential unsoundness in your code.
            This warning will become a hard error in the future.
The warning is the same without the &mut.
It seems to me this code is fine and there should not be a warning.
Metadata
Metadata
Assignees
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.