Skip to content

Commit

Permalink
Auto merge of #33620 - eddyb:oops-static-is-not-fn, r=dotdash
Browse files Browse the repository at this point in the history
mir: always allow &mut [...] in static mut regardless of the array length.
  • Loading branch information
bors committed May 15, 2016
2 parents 9f58fb7 + 55aae6f commit e7420fb
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 e7420fb

Please sign in to comment.