diff options
| author | varkor <github@varkor.com> | 2019-05-31 00:12:24 +0100 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2019-06-02 01:50:06 +0100 |
| commit | c2b663c6669e68f00644b8402ebd177c0ba925b8 (patch) | |
| tree | dff98193c6a896f26b00934aacf6e17ea4bd0437 | |
| parent | 7e92607f5a622e6fd9b32492a70217762cb709c4 (diff) | |
| download | rust-c2b663c6669e68f00644b8402ebd177c0ba925b8.tar.gz rust-c2b663c6669e68f00644b8402ebd177c0ba925b8.zip | |
Fix unwrapping usize issue with transparent MaybeUnit array wrapper
| -rw-r--r-- | src/librustc/ty/layout.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/const-generics/transparent-maybeunit-array-wrapper.rs | 11 | ||||
| -rw-r--r-- | src/test/ui/const-generics/transparent-maybeunit-array-wrapper.stderr | 6 |
3 files changed, 18 insertions, 1 deletions
diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 6d7b0926c7a..6415122dd39 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -549,8 +549,8 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> { } } + let count = count.assert_usize(tcx).ok_or(LayoutError::Unknown(ty))?; let element = self.layout_of(element)?; - let count = count.unwrap_usize(tcx); let size = element.size.checked_mul(count, dl) .ok_or(LayoutError::SizeOverflow(ty))?; diff --git a/src/test/ui/const-generics/transparent-maybeunit-array-wrapper.rs b/src/test/ui/const-generics/transparent-maybeunit-array-wrapper.rs new file mode 100644 index 00000000000..794048174f9 --- /dev/null +++ b/src/test/ui/const-generics/transparent-maybeunit-array-wrapper.rs @@ -0,0 +1,11 @@ +// run-pass + +#![feature(const_generics)] +//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash + +use std::mem::MaybeUninit; + +#[repr(transparent)] +pub struct MaybeUninitWrapper<const N: usize>(MaybeUninit<[u64; N]>); + +fn main() {} diff --git a/src/test/ui/const-generics/transparent-maybeunit-array-wrapper.stderr b/src/test/ui/const-generics/transparent-maybeunit-array-wrapper.stderr new file mode 100644 index 00000000000..661bbd113bc --- /dev/null +++ b/src/test/ui/const-generics/transparent-maybeunit-array-wrapper.stderr @@ -0,0 +1,6 @@ +warning: the feature `const_generics` is incomplete and may cause the compiler to crash + --> $DIR/transparent-maybeunit-array-wrapper.rs:3:12 + | +LL | #![feature(const_generics)] + | ^^^^^^^^^^^^^^ + |
