Skip to content

Commit

Permalink
refactor: use const Option::unwrap (!)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Jan 31, 2025
1 parent cfd5504 commit 5073de7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
10 changes: 5 additions & 5 deletions naga/src/proc/layouter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use std::{fmt::Display, num::NonZeroU32, ops};
pub struct Alignment(NonZeroU32);

impl Alignment {
pub const ONE: Self = Self(unsafe { NonZeroU32::new_unchecked(1) });
pub const TWO: Self = Self(unsafe { NonZeroU32::new_unchecked(2) });
pub const FOUR: Self = Self(unsafe { NonZeroU32::new_unchecked(4) });
pub const EIGHT: Self = Self(unsafe { NonZeroU32::new_unchecked(8) });
pub const SIXTEEN: Self = Self(unsafe { NonZeroU32::new_unchecked(16) });
pub const ONE: Self = Self(NonZeroU32::new(1).unwrap());
pub const TWO: Self = Self(NonZeroU32::new(2).unwrap());
pub const FOUR: Self = Self(NonZeroU32::new(4).unwrap());
pub const EIGHT: Self = Self(NonZeroU32::new(8).unwrap());
pub const SIXTEEN: Self = Self(NonZeroU32::new(16).unwrap());

pub const MIN_UNIFORM: Self = Self::SIXTEEN;

Expand Down
14 changes: 5 additions & 9 deletions wgpu-core/src/indirect_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,12 @@ impl IndirectValidation {
"
);

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

// SAFETY: The value we are passing to `new_unchecked` is not zero, so this is safe.
const DST_BUFFER_SIZE: NonZeroU64 = unsafe {
NonZeroU64::new_unchecked(
SRC_BUFFER_SIZE.get() * 2, // From above: `dst: array<u32, 6>`
)
};
const DST_BUFFER_SIZE: NonZeroU64 = NonZeroU64::new(
SRC_BUFFER_SIZE.get() * 2, // From above: `dst: array<u32, 6>`
)
.unwrap();

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

0 comments on commit 5073de7

Please sign in to comment.