Skip to content

Commit e7420fb

Browse files
committed
Auto merge of #33620 - eddyb:oops-static-is-not-fn, r=dotdash
mir: always allow &mut [...] in static mut regardless of the array length.
2 parents 9f58fb7 + 55aae6f commit e7420fb

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/librustc_mir/transform/qualify_consts.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
652652
// In theory, any zero-sized value could be borrowed
653653
// mutably without consequences. However, only &mut []
654654
// is allowed right now, and only in functions.
655-
let allow = if let ty::TyArray(_, 0) = ty.sty {
656-
self.mode == Mode::Fn
657-
} else if self.mode == Mode::StaticMut {
655+
let allow = if self.mode == Mode::StaticMut {
658656
// Inside a `static mut`, &mut [...] is also allowed.
659657
match ty.sty {
660658
ty::TyArray(..) | ty::TySlice(_) => {
@@ -665,6 +663,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
665663
}
666664
_ => false
667665
}
666+
} else if let ty::TyArray(_, 0) = ty.sty {
667+
self.mode == Mode::Fn
668668
} else {
669669
false
670670
};

src/test/run-pass/check-static-mut-slices.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
static mut TEST: &'static mut [isize] = &mut [1];
15+
static mut EMPTY: &'static mut [isize] = &mut [];
1516

1617
pub fn main() {
1718
unsafe {

0 commit comments

Comments
 (0)