Skip to content

Commit

Permalink
mir: always allow &mut [...] in static mut regardless of the array le…
Browse files Browse the repository at this point in the history
…ngth.
  • Loading branch information
eddyb committed May 13, 2016
1 parent edb6f83 commit 55aae6f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {
Expand All @@ -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
};
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/check-static-mut-slices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@


static mut TEST: &'static mut [isize] = &mut [1];
static mut EMPTY: &'static mut [isize] = &mut [];

pub fn main() {
unsafe {
Expand Down

0 comments on commit 55aae6f

Please sign in to comment.