Auto merge of #33620 - eddyb:oops-static-is-not-fn, r=dotdash

mir: always allow &mut [...] in static mut regardless of the array length.
This commit is contained in:
bors 2016-05-15 11:01:03 -07:00
commit e7420fbbae
2 changed files with 4 additions and 3 deletions

View File

@ -652,9 +652,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
// In theory, any zero-sized value could be borrowed // In theory, any zero-sized value could be borrowed
// mutably without consequences. However, only &mut [] // mutably without consequences. However, only &mut []
// is allowed right now, and only in functions. // is allowed right now, and only in functions.
let allow = if let ty::TyArray(_, 0) = ty.sty { let allow = if self.mode == Mode::StaticMut {
self.mode == Mode::Fn
} else if self.mode == Mode::StaticMut {
// Inside a `static mut`, &mut [...] is also allowed. // Inside a `static mut`, &mut [...] is also allowed.
match ty.sty { match ty.sty {
ty::TyArray(..) | ty::TySlice(_) => { ty::TyArray(..) | ty::TySlice(_) => {
@ -665,6 +663,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
} }
_ => false _ => false
} }
} else if let ty::TyArray(_, 0) = ty.sty {
self.mode == Mode::Fn
} else { } else {
false false
}; };

View File

@ -12,6 +12,7 @@
static mut TEST: &'static mut [isize] = &mut [1]; static mut TEST: &'static mut [isize] = &mut [1];
static mut EMPTY: &'static mut [isize] = &mut [];
pub fn main() { pub fn main() {
unsafe { unsafe {