diff options
| author | bors <bors@rust-lang.org> | 2016-05-15 11:01:03 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-05-15 11:01:03 -0700 |
| commit | e7420fbbae85a62a62163a2ac5c947b76a8eb62d (patch) | |
| tree | 3d7bda9d966eac91a44de8d7f1cfcf9c68b39047 | |
| parent | 9f58fb776a74a44f4fcc2cb57084d33c55530aa4 (diff) | |
| parent | 55aae6f48e8248342288ec3bfe2be0e0c370ee98 (diff) | |
| download | rust-e7420fbbae85a62a62163a2ac5c947b76a8eb62d.tar.gz rust-e7420fbbae85a62a62163a2ac5c947b76a8eb62d.zip | |
Auto merge of #33620 - eddyb:oops-static-is-not-fn, r=dotdash
mir: always allow &mut [...] in static mut regardless of the array length.
| -rw-r--r-- | src/librustc_mir/transform/qualify_consts.rs | 6 | ||||
| -rw-r--r-- | 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 4eda1ed23b7..2e4400c834f 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 5959dd4c389..1cfe5bdaebb 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 { |
