From b7c04d152b92f137cd452ea45dcb9d2568953c86 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 14 Nov 2012 19:28:43 -0800 Subject: [PATCH] Inherit mutability through fixed-length vectors. Fixes #3226. No review (one line bug fix). --- src/librustc/middle/mem_categorization.rs | 3 ++- ...tability-inherits-through-fixed-length-vec.rs | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/test/run-pass/mutability-inherits-through-fixed-length-vec.rs diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index a43dc0747de..2060eba7da6 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -797,7 +797,8 @@ impl &mem_categorization_ctxt { deref_comp(_) => { // fixed-length vectors have no deref - comp(expr, base_cmt, base_cmt.ty, mt.mutbl, mt.ty) + let m = self.inherited_mutability(base_cmt.mutbl, mt.mutbl); + comp(expr, base_cmt, base_cmt.ty, m, mt.ty) } }; diff --git a/src/test/run-pass/mutability-inherits-through-fixed-length-vec.rs b/src/test/run-pass/mutability-inherits-through-fixed-length-vec.rs new file mode 100644 index 00000000000..c51c4b20457 --- /dev/null +++ b/src/test/run-pass/mutability-inherits-through-fixed-length-vec.rs @@ -0,0 +1,16 @@ +fn test1() { + let mut ints = [0, ..32]; + ints[0] += 1; + assert ints[0] == 1; +} + +fn test2() { + let mut ints = [0, ..32]; + for vec::each_mut(ints) |i| { *i += 22; } + for ints.each |i| { assert *i == 22; } +} + +fn main() { + test1(); + test2(); +}