From 119f5ec524dca42403db2aa07569baa349793e9b Mon Sep 17 00:00:00 2001 From: DasEtwas <18222134+DasEtwas@users.noreply.github.com> Date: Wed, 18 Mar 2020 20:42:58 +0100 Subject: [PATCH] use MaybeUninit properly, updated cgmath --- Cargo.toml | 2 +- src/array.rs | 32 +++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index eedb02c..b4f08f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ edition = "2018" bigger-arrays = [] [dependencies] -cgmath = { version = "0.16", optional = true } +cgmath = { version = "0.17", optional = true } nalgebra = { version = "0.20", optional = true } glsl-layout-derive = { path = "glsl-layout-derive" } diff --git a/src/array.rs b/src/array.rs index ab38c03..965e176 100644 --- a/src/array.rs +++ b/src/array.rs @@ -185,12 +185,16 @@ macro_rules! impl_array { // Each element of `values` read once and then forgotten. // Hence safe in case `f` never panics. // TODO: Make it panic-safe. - let mut result: [U; $size] = ::std::mem::MaybeUninit::zeroed().assume_init(); + let mut result: ::std::mem::MaybeUninit<[U; $size]> = + ::std::mem::MaybeUninit::zeroed(); for i in 0..$size { - write(&mut result[i], f(read(&mut values[i]))); + write( + result.as_mut_ptr().cast::().add(i), + f(read(&mut values[i])), + ); } forget(values); - result + result.assume_init() } } } @@ -226,12 +230,15 @@ macro_rules! impl_array { use std::ptr::write; unsafe { // All elements of `result` is written. - let mut result: [Element; $size] = - ::std::mem::MaybeUninit::zeroed().assume_init(); + let mut result: ::std::mem::MaybeUninit<[Element; $size]> = + ::std::mem::MaybeUninit::zeroed(); for i in 0..$size { - write(&mut result[i], self[i].std140().into()); + write( + result.as_mut_ptr().cast::>().add(i), + self[i].std140().into(), + ); } - Array(result, PhantomData) + Array(result.assume_init(), PhantomData) } } } @@ -247,12 +254,15 @@ macro_rules! impl_array { use std::ptr::write; unsafe { // All elements of `result` is written. - let mut result: [Element; $size] = - ::std::mem::MaybeUninit::zeroed().assume_init(); + let mut result: ::std::mem::MaybeUninit<[Element; $size]> = + ::std::mem::MaybeUninit::zeroed(); for i in 0..$size { - write(&mut result[i], self.0[i].0.std140().into()); + write( + result.as_mut_ptr().cast::>().add(i), + self.0[i].0.std140().into(), + ); } - Array(result, PhantomData) + Array(result.assume_init(), PhantomData) } } }