Skip to content

Commit 7e92607

Browse files
committed
Fix unwrapping usize issue in HasMutInterior
1 parent eb0afe1 commit 7e92607

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/librustc_mir/transform/qualify_consts.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,9 @@ impl Qualif for HasMutInterior {
316316
} else if let ty::Array(_, len) = ty.sty {
317317
// FIXME(eddyb) the `cx.mode == Mode::Fn` condition
318318
// seems unnecessary, given that this is merely a ZST.
319-
if !(len.unwrap_usize(cx.tcx) == 0 && cx.mode == Mode::Fn) {
320-
return true;
319+
match len.assert_usize(cx.tcx) {
320+
Some(0) if cx.mode == Mode::Fn => {},
321+
_ => return true,
321322
}
322323
} else {
323324
return true;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// run-pass
2+
3+
#![feature(const_generics)]
4+
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
5+
6+
use std::ops::AddAssign;
7+
8+
fn inc<T: AddAssign + Clone, const N: usize>(v: &mut [T; N]) -> &mut [T; N] {
9+
for x in v.iter_mut() {
10+
*x += x.clone();
11+
}
12+
v
13+
}
14+
15+
fn main() {
16+
let mut v = [1, 2, 3];
17+
inc(&mut v);
18+
assert_eq!(v, [2, 4, 6]);
19+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2+
--> $DIR/mut-ref-const-param-array.rs:3:12
3+
|
4+
LL | #![feature(const_generics)]
5+
| ^^^^^^^^^^^^^^
6+

0 commit comments

Comments
 (0)