Skip to content

Commit b7c04d1

Browse files
committed
Inherit mutability through fixed-length vectors.
Fixes #3226. No review (one line bug fix).
1 parent f4a5a76 commit b7c04d1

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/librustc/middle/mem_categorization.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,8 @@ impl &mem_categorization_ctxt {
797797

798798
deref_comp(_) => {
799799
// fixed-length vectors have no deref
800-
comp(expr, base_cmt, base_cmt.ty, mt.mutbl, mt.ty)
800+
let m = self.inherited_mutability(base_cmt.mutbl, mt.mutbl);
801+
comp(expr, base_cmt, base_cmt.ty, m, mt.ty)
801802
}
802803
};
803804

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
fn test1() {
2+
let mut ints = [0, ..32];
3+
ints[0] += 1;
4+
assert ints[0] == 1;
5+
}
6+
7+
fn test2() {
8+
let mut ints = [0, ..32];
9+
for vec::each_mut(ints) |i| { *i += 22; }
10+
for ints.each |i| { assert *i == 22; }
11+
}
12+
13+
fn main() {
14+
test1();
15+
test2();
16+
}

0 commit comments

Comments
 (0)