Closed
Description
I tried this code:
struct S<'a> { x: &'a mut u8 }
impl<'a> S<'a> {
fn f(&self, y: &'a mut u8) -> &'a mut u8 { y }
}
fn main() {
let mut b = 5;
let c;
{
let mut a = 4;
let s = S{x: &mut a};
c = s.f(&mut b);
}
}
The compiler warns that the variable a
does not need to be mutable:
warning: variable does not need to be mutable
--> test.rs:11:7
|
11 | let mut a = 4;
| ----^
| |
| help: remove this `mut`
|
= note: #[warn(unused_mut)] on by default
I did not expect this warning because a reference as mutable to a
is taken later on.
(The other errors and warnings are expected.)
Meta
rustc --version --verbose
:
rustc 1.29.0-nightly (12ed235ad 2018-07-18)
binary: rustc
commit-hash: 12ed235adc62e63b16bb4f715b143c37a5efa00d
commit-date: 2018-07-18
host: x86_64-unknown-linux-gnu
release: 1.29.0-nightly
LLVM version: 7.0