Skip to content

Commit 2548d93

Browse files
refactor: use const Option::unwrap (!)
1 parent 5342dc5 commit 2548d93

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

naga/src/proc/layouter.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ use crate::arena::{Handle, HandleVec};
99
pub struct Alignment(NonZeroU32);
1010

1111
impl Alignment {
12-
pub const ONE: Self = Self(unsafe { NonZeroU32::new_unchecked(1) });
13-
pub const TWO: Self = Self(unsafe { NonZeroU32::new_unchecked(2) });
14-
pub const FOUR: Self = Self(unsafe { NonZeroU32::new_unchecked(4) });
15-
pub const EIGHT: Self = Self(unsafe { NonZeroU32::new_unchecked(8) });
16-
pub const SIXTEEN: Self = Self(unsafe { NonZeroU32::new_unchecked(16) });
12+
pub const ONE: Self = Self(NonZeroU32::new(1).unwrap());
13+
pub const TWO: Self = Self(NonZeroU32::new(2).unwrap());
14+
pub const FOUR: Self = Self(NonZeroU32::new(4).unwrap());
15+
pub const EIGHT: Self = Self(NonZeroU32::new(8).unwrap());
16+
pub const SIXTEEN: Self = Self(NonZeroU32::new(16).unwrap());
1717

1818
pub const MIN_UNIFORM: Self = Self::SIXTEEN;
1919

wgpu-core/src/indirect_validation.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,12 @@ impl IndirectValidation {
8585
"
8686
);
8787

88-
// SAFETY: The value we are passing to `new_unchecked` is not zero, so this is safe.
89-
const SRC_BUFFER_SIZE: NonZeroU64 =
90-
unsafe { NonZeroU64::new_unchecked(size_of::<u32>() as u64 * 3) };
88+
const SRC_BUFFER_SIZE: NonZeroU64 = NonZeroU64::new(size_of::<u32>() as u64 * 3).unwrap();
9189

92-
// SAFETY: The value we are passing to `new_unchecked` is not zero, so this is safe.
93-
const DST_BUFFER_SIZE: NonZeroU64 = unsafe {
94-
NonZeroU64::new_unchecked(
95-
SRC_BUFFER_SIZE.get() * 2, // From above: `dst: array<u32, 6>`
96-
)
97-
};
90+
const DST_BUFFER_SIZE: NonZeroU64 = NonZeroU64::new(
91+
SRC_BUFFER_SIZE.get() * 2, // From above: `dst: array<u32, 6>`
92+
)
93+
.unwrap();
9894

9995
let module = naga::front::wgsl::parse_str(&src).map_err(|inner| {
10096
CreateShaderModuleError::Parsing(naga::error::ShaderError {

0 commit comments

Comments
 (0)