Closed
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.