fix false negative for unused_mut
This commit is contained in:
parent
43a78029b4
commit
69c71dacda
3 changed files with 23 additions and 6 deletions
|
@ -935,6 +935,7 @@ enum InitializationRequiringAction {
|
||||||
PartialAssignment,
|
PartialAssignment,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct RootPlace<'tcx> {
|
struct RootPlace<'tcx> {
|
||||||
place_local: Local,
|
place_local: Local,
|
||||||
place_projection: &'tcx [PlaceElem<'tcx>],
|
place_projection: &'tcx [PlaceElem<'tcx>],
|
||||||
|
@ -1848,11 +1849,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
// is allowed, remove this match arm.
|
// is allowed, remove this match arm.
|
||||||
ty::Adt(..) | ty::Tuple(..) => {
|
ty::Adt(..) | ty::Tuple(..) => {
|
||||||
check_parent_of_field(self, location, place_base, span, flow_state);
|
check_parent_of_field(self, location, place_base, span, flow_state);
|
||||||
|
|
||||||
// rust-lang/rust#21232, #54499, #54986: during period where we reject
|
|
||||||
// partial initialization, do not complain about unnecessary `mut` on
|
|
||||||
// an attempt to do a partial initialization.
|
|
||||||
self.used_mut.insert(place.local);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -1940,6 +1936,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
(prefix, base, span),
|
(prefix, base, span),
|
||||||
mpi,
|
mpi,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// rust-lang/rust#21232, #54499, #54986: during period where we reject
|
||||||
|
// partial initialization, do not complain about unnecessary `mut` on
|
||||||
|
// an attempt to do a partial initialization.
|
||||||
|
this.used_mut.insert(base.local);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,3 +205,11 @@ fn bar() {
|
||||||
let mut b = vec![2]; //~ ERROR: variable does not need to be mutable
|
let mut b = vec![2]; //~ ERROR: variable does not need to be mutable
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Arg(i32);
|
||||||
|
|
||||||
|
// Regression test for https://github.com/rust-lang/rust/issues/110849
|
||||||
|
fn write_through_reference(mut arg: &mut Arg) {
|
||||||
|
//~^ WARN: variable does not need to be mutable
|
||||||
|
arg.0 = 1
|
||||||
|
}
|
||||||
|
|
|
@ -218,5 +218,13 @@ note: the lint level is defined here
|
||||||
LL | #[deny(unused_mut)]
|
LL | #[deny(unused_mut)]
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error; 25 warnings emitted
|
warning: variable does not need to be mutable
|
||||||
|
--> $DIR/lint-unused-mut-variables.rs:212:28
|
||||||
|
|
|
||||||
|
LL | fn write_through_reference(mut arg: &mut Arg) {
|
||||||
|
| ----^^^
|
||||||
|
| |
|
||||||
|
| help: remove this `mut`
|
||||||
|
|
||||||
|
error: aborting due to previous error; 26 warnings emitted
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue