From 55aae6f48e8248342288ec3bfe2be0e0c370ee98 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Fri, 13 May 2016 22:27:09 +0300 Subject: [PATCH] mir: always allow &mut [...] in static mut regardless of the array length. --- src/librustc_mir/transform/qualify_consts.rs | 6 +++--- src/test/run-pass/check-static-mut-slices.rs | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 4eda1ed23b757..2e4400c834f23 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -652,9 +652,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { // In theory, any zero-sized value could be borrowed // mutably without consequences. However, only &mut [] // is allowed right now, and only in functions. - let allow = if let ty::TyArray(_, 0) = ty.sty { - self.mode == Mode::Fn - } else if self.mode == Mode::StaticMut { + let allow = if self.mode == Mode::StaticMut { // Inside a `static mut`, &mut [...] is also allowed. match ty.sty { ty::TyArray(..) | ty::TySlice(_) => { @@ -665,6 +663,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { } _ => false } + } else if let ty::TyArray(_, 0) = ty.sty { + self.mode == Mode::Fn } else { false }; diff --git a/src/test/run-pass/check-static-mut-slices.rs b/src/test/run-pass/check-static-mut-slices.rs index 5959dd4c389c8..1cfe5bdaebb7f 100644 --- a/src/test/run-pass/check-static-mut-slices.rs +++ b/src/test/run-pass/check-static-mut-slices.rs @@ -12,6 +12,7 @@ static mut TEST: &'static mut [isize] = &mut [1]; +static mut EMPTY: &'static mut [isize] = &mut []; pub fn main() { unsafe {