Skip to content

Commit df39a92

Browse files
committed
Auto merge of #27011 - dotdash:issue-26996, r=luqmana
If we match a whole struct or tuple, the "field" for the reassignment checker will be "None" which means that mutating any field should count as a reassignment. Fixes #26996.
2 parents edf29a7 + 043d7b5 commit df39a92

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/librustc_trans/trans/_match.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,8 @@ impl<'tcx> euv::Delegate<'tcx> for ReassignmentChecker {
13841384
match base_cmt.cat {
13851385
mc::cat_upvar(mc::Upvar { id: ty::UpvarId { var_id: vid, .. }, .. }) |
13861386
mc::cat_local(vid) => {
1387-
self.reassigned |= self.node == vid && Some(field) == self.field
1387+
self.reassigned |= self.node == vid &&
1388+
(self.field.is_none() || Some(field) == self.field)
13881389
},
13891390
_ => {}
13901391
}

src/test/run-pass/issue-26996.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let mut c = (1, "".to_owned());
13+
match c {
14+
c2 => {
15+
c.0 = 2;
16+
assert_eq!(c2.0, 1);
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)