From 8788f924cbc8aa67bd9f9ba0627a6fb5693bc411 Mon Sep 17 00:00:00 2001 From: Firestar99 Date: Fri, 20 Dec 2024 14:37:06 +0100 Subject: [PATCH 1/2] make vector and scalar traits imply `Send + Sync + 'static` --- crates/spirv-std/src/vector.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/spirv-std/src/vector.rs b/crates/spirv-std/src/vector.rs index 668f40bd32..25204302fe 100644 --- a/crates/spirv-std/src/vector.rs +++ b/crates/spirv-std/src/vector.rs @@ -9,7 +9,7 @@ use glam::{Vec3Swizzles, Vec4Swizzles}; /// # Safety /// Implementing this trait on non-scalar or non-vector types may break assumptions about other /// unsafe code, and should not be done. -pub unsafe trait VectorOrScalar: Default { +pub unsafe trait VectorOrScalar: Default + Send + Sync + 'static { /// Either the scalar component type of the vector or the scalar itself. type Scalar: Scalar; From 14c03e554101b5ce0ae0434a186d424ad417471e Mon Sep 17 00:00:00 2001 From: Firestar99 Date: Fri, 20 Dec 2024 15:15:18 +0100 Subject: [PATCH 2/2] make vector and scalar traits also imply `Copy` --- crates/spirv-std/src/scalar.rs | 5 +---- crates/spirv-std/src/vector.rs | 2 +- tests/ui/arch/all.rs | 1 + tests/ui/arch/all.stderr | 4 ++-- tests/ui/arch/any.rs | 1 + tests/ui/arch/any.stderr | 4 ++-- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/crates/spirv-std/src/scalar.rs b/crates/spirv-std/src/scalar.rs index 72e0d8dfaf..bff86b6964 100644 --- a/crates/spirv-std/src/scalar.rs +++ b/crates/spirv-std/src/scalar.rs @@ -8,10 +8,7 @@ use core::num::NonZeroUsize; /// # Safety /// Implementing this trait on non-scalar types breaks assumptions of other unsafe code, and should /// not be done. -pub unsafe trait Scalar: - VectorOrScalar + Copy + Default + crate::sealed::Sealed -{ -} +pub unsafe trait Scalar: VectorOrScalar + crate::sealed::Sealed {} macro_rules! impl_scalar { ($($ty:ty),+) => { diff --git a/crates/spirv-std/src/vector.rs b/crates/spirv-std/src/vector.rs index 25204302fe..0385db83ac 100644 --- a/crates/spirv-std/src/vector.rs +++ b/crates/spirv-std/src/vector.rs @@ -9,7 +9,7 @@ use glam::{Vec3Swizzles, Vec4Swizzles}; /// # Safety /// Implementing this trait on non-scalar or non-vector types may break assumptions about other /// unsafe code, and should not be done. -pub unsafe trait VectorOrScalar: Default + Send + Sync + 'static { +pub unsafe trait VectorOrScalar: Copy + Default + Send + Sync + 'static { /// Either the scalar component type of the vector or the scalar itself. type Scalar: Scalar; diff --git a/tests/ui/arch/all.rs b/tests/ui/arch/all.rs index 18967b0d87..088e07f0a5 100644 --- a/tests/ui/arch/all.rs +++ b/tests/ui/arch/all.rs @@ -12,6 +12,7 @@ use spirv_std::{scalar::Scalar, vector::Vector, vector::VectorOrScalar}; /// Fortunately, this requirement isn't checked on generic structs, so we have a way to work around /// it (for now at least) #[repr(simd)] +#[derive(Copy, Clone, Debug)] struct Vec2(T, T); unsafe impl VectorOrScalar for Vec2 { type Scalar = T; diff --git a/tests/ui/arch/all.stderr b/tests/ui/arch/all.stderr index 8226745fbd..beed8baf22 100644 --- a/tests/ui/arch/all.stderr +++ b/tests/ui/arch/all.stderr @@ -1,7 +1,7 @@ warning: [Rust-GPU] temporarily re-allowing old-style `#[repr(simd)]` (with fields) - --> $DIR/all.rs:15:1 + --> $DIR/all.rs:16:1 | -15 | struct Vec2(T, T); +16 | struct Vec2(T, T); | ^^^^^^^^^^^^^^ | = note: removed upstream by https://github.com/rust-lang/rust/pull/129403 diff --git a/tests/ui/arch/any.rs b/tests/ui/arch/any.rs index 7d03403c77..9e8e1d2f3f 100644 --- a/tests/ui/arch/any.rs +++ b/tests/ui/arch/any.rs @@ -12,6 +12,7 @@ use spirv_std::{scalar::Scalar, vector::Vector, vector::VectorOrScalar}; /// Fortunately, this requirement isn't checked on generic structs, so we have a way to work around /// it (for now at least) #[repr(simd)] +#[derive(Copy, Clone, Debug)] struct Vec2(T, T); unsafe impl VectorOrScalar for Vec2 { type Scalar = T; diff --git a/tests/ui/arch/any.stderr b/tests/ui/arch/any.stderr index ff776148f5..c01af8f3ba 100644 --- a/tests/ui/arch/any.stderr +++ b/tests/ui/arch/any.stderr @@ -1,7 +1,7 @@ warning: [Rust-GPU] temporarily re-allowing old-style `#[repr(simd)]` (with fields) - --> $DIR/any.rs:15:1 + --> $DIR/any.rs:16:1 | -15 | struct Vec2(T, T); +16 | struct Vec2(T, T); | ^^^^^^^^^^^^^^ | = note: removed upstream by https://github.com/rust-lang/rust/pull/129403