Don't trigger while_immutable_condition for mutable fields of tuples/structs

This commit is contained in:
flip1995 2018-04-03 16:41:30 +02:00
parent b7f5871aa0
commit cecfdeab19
No known key found for this signature in database
GPG Key ID: 6757AB26F72F0084
3 changed files with 24 additions and 18 deletions

View File

@ -2237,7 +2237,7 @@ struct MutVarsDelegate {
} }
impl<'tcx> MutVarsDelegate { impl<'tcx> MutVarsDelegate {
fn update(&mut self, cat: &'tcx Categorization, sp: Span) { fn update(&mut self, cat: &'tcx Categorization) {
match *cat { match *cat {
Categorization::Local(id) => Categorization::Local(id) =>
if let Some(used) = self.used_mutably.get_mut(&id) { if let Some(used) = self.used_mutably.get_mut(&id) {
@ -2249,7 +2249,7 @@ impl<'tcx> MutVarsDelegate {
//`while`-body, not just the ones in the condition. //`while`-body, not just the ones in the condition.
self.skip = true self.skip = true
}, },
Categorization::Deref(ref cmt, _) => self.update(&cmt.cat, sp), Categorization::Deref(ref cmt, _) | Categorization::Interior(ref cmt, _) => self.update(&cmt.cat),
_ => {} _ => {}
} }
} }
@ -2263,14 +2263,14 @@ impl<'tcx> Delegate<'tcx> for MutVarsDelegate {
fn consume_pat(&mut self, _: &Pat, _: cmt<'tcx>, _: ConsumeMode) {} fn consume_pat(&mut self, _: &Pat, _: cmt<'tcx>, _: ConsumeMode) {}
fn borrow(&mut self, _: NodeId, sp: Span, cmt: cmt<'tcx>, _: ty::Region, bk: ty::BorrowKind, _: LoanCause) { fn borrow(&mut self, _: NodeId, _: Span, cmt: cmt<'tcx>, _: ty::Region, bk: ty::BorrowKind, _: LoanCause) {
if let ty::BorrowKind::MutBorrow = bk { if let ty::BorrowKind::MutBorrow = bk {
self.update(&cmt.cat, sp) self.update(&cmt.cat)
} }
} }
fn mutate(&mut self, _: NodeId, sp: Span, cmt: cmt<'tcx>, _: MutateMode) { fn mutate(&mut self, _: NodeId, _: Span, cmt: cmt<'tcx>, _: MutateMode) {
self.update(&cmt.cat, sp) self.update(&cmt.cat)
} }
fn decl_without_init(&mut self, _: NodeId, _: Span) {} fn decl_without_init(&mut self, _: NodeId, _: Span) {}

View File

@ -55,6 +55,12 @@ fn immutable_condition() {
} }
}; };
c(); c();
let mut tup = (0, 0);
while tup.0 < 5 {
tup.0 += 1;
println!("OK - tup.0 gets mutated")
}
} }
fn unused_var() { fn unused_var() {

View File

@ -19,39 +19,39 @@ error: Variable in the condition are not mutated in the loop body. This either l
| ^^^^^ | ^^^^^
error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop. error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop.
--> $DIR/infinite_loop.rs:64:11 --> $DIR/infinite_loop.rs:70:11
| |
64 | while i < 3 { 70 | while i < 3 {
| ^^^^^ | ^^^^^
error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop. error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop.
--> $DIR/infinite_loop.rs:69:11 --> $DIR/infinite_loop.rs:75:11
| |
69 | while i < 3 && j > 0 { 75 | while i < 3 && j > 0 {
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop. error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop.
--> $DIR/infinite_loop.rs:73:11 --> $DIR/infinite_loop.rs:79:11
| |
73 | while i < 3 { 79 | while i < 3 {
| ^^^^^ | ^^^^^
error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop. error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop.
--> $DIR/infinite_loop.rs:88:11 --> $DIR/infinite_loop.rs:94:11
| |
88 | while i < 3 { 94 | while i < 3 {
| ^^^^^ | ^^^^^
error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop. error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop.
--> $DIR/infinite_loop.rs:93:11 --> $DIR/infinite_loop.rs:99:11
| |
93 | while i < 3 { 99 | while i < 3 {
| ^^^^^ | ^^^^^
error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop. error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop.
--> $DIR/infinite_loop.rs:156:15 --> $DIR/infinite_loop.rs:162:15
| |
156 | while self.count < n { 162 | while self.count < n {
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
error: aborting due to 9 previous errors error: aborting due to 9 previous errors