Skip to content

Commit 75ca545

Browse files
authored
Enable Clippy use_self lint (#147)
1 parent dbe8af6 commit 75ca545

File tree

8 files changed

+53
-52
lines changed

8 files changed

+53
-52
lines changed

spirv-std/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
clippy::enum_glob_use,
1212
clippy::pub_enum_variant_names,
1313
clippy::mem_forget,
14-
//clippy::use_self,
14+
clippy::use_self,
1515
clippy::filter_map_next,
1616
clippy::needless_continue,
1717
clippy::needless_borrow,

spirv-std/src/math/mat2.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl Mat2 {
4242
/// returned matrix.
4343
#[inline]
4444
pub fn from_cols_array(m: &[f32; 4]) -> Self {
45-
Mat2(Vec4::new(m[0], m[1], m[2], m[3]))
45+
Self(Vec4::new(m[0], m[1], m[2], m[3]))
4646
}
4747

4848
/// Creates a `[f32; 4]` storing data in column major order.
@@ -57,7 +57,7 @@ impl Mat2 {
5757
/// the returned matrix.
5858
#[inline]
5959
pub fn from_cols_array_2d(m: &[[f32; 2]; 2]) -> Self {
60-
Mat2(Vec4::new(m[0][0], m[0][1], m[1][0], m[1][1]))
60+
Self(Vec4::new(m[0][0], m[0][1], m[1][0], m[1][1]))
6161
}
6262

6363
/// Creates a `[[f32; 2]; 2]` storing data in column major order.
@@ -167,7 +167,7 @@ impl Mat2 {
167167
pub fn mul_mat2(&self, other: &Self) -> Self {
168168
// TODO: SSE2
169169
let (x0, y0, x1, y1) = other.0.into();
170-
Mat2::from_cols(
170+
Self::from_cols(
171171
self.mul_vec2(Vec2::new(x0, y0)),
172172
self.mul_vec2(Vec2::new(x1, y1)),
173173
)
@@ -176,20 +176,20 @@ impl Mat2 {
176176
/// Adds two 2x2 matrices.
177177
#[inline]
178178
pub fn add_mat2(&self, other: &Self) -> Self {
179-
Mat2(self.0 + other.0)
179+
Self(self.0 + other.0)
180180
}
181181

182182
/// Subtracts two 2x2 matrices.
183183
#[inline]
184184
pub fn sub_mat2(&self, other: &Self) -> Self {
185-
Mat2(self.0 - other.0)
185+
Self(self.0 - other.0)
186186
}
187187

188188
/// Multiplies a 2x2 matrix by a scalar.
189189
#[inline]
190190
pub fn mul_scalar(&self, other: f32) -> Self {
191191
let s = Vec4::splat(other);
192-
Mat2(self.0 * s)
192+
Self(self.0 * s)
193193
}
194194
}
195195

spirv-std/src/math/mat3.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Mat3 {
6262
/// returned matrix.
6363
#[inline]
6464
pub fn from_cols_array(m: &[f32; 9]) -> Self {
65-
Mat3 {
65+
Self {
6666
x_axis: Vec3::new(m[0], m[1], m[2]),
6767
y_axis: Vec3::new(m[3], m[4], m[5]),
6868
z_axis: Vec3::new(m[6], m[7], m[8]),
@@ -84,7 +84,7 @@ impl Mat3 {
8484
/// returned matrix.
8585
#[inline]
8686
pub fn from_cols_array_2d(m: &[[f32; 3]; 3]) -> Self {
87-
Mat3 {
87+
Self {
8888
x_axis: m[0].into(),
8989
y_axis: m[1].into(),
9090
z_axis: m[2].into(),
@@ -217,7 +217,7 @@ impl Mat3 {
217217
let det = self.z_axis.dot_as_vec3(tmp2);
218218
let inv_det = det.recip();
219219
// TODO: Work out if it's possible to get rid of the transpose
220-
Mat3::from_cols(tmp0 * inv_det, tmp1 * inv_det, tmp2 * inv_det).transpose()
220+
Self::from_cols(tmp0 * inv_det, tmp1 * inv_det, tmp2 * inv_det).transpose()
221221
}
222222

223223
/// Multiplies two 3x3 matrices.

spirv-std/src/math/mat4.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Mat4 {
3434
/// Creates a 4x4 matrix with all elements set to `0.0`.
3535
#[inline]
3636
pub const fn zero() -> Self {
37-
Mat4 {
37+
Self {
3838
x_axis: Vec4::zero(),
3939
y_axis: Vec4::zero(),
4040
z_axis: Vec4::zero(),
@@ -45,7 +45,7 @@ impl Mat4 {
4545
/// Creates a 4x4 identity matrix.
4646
#[inline]
4747
pub const fn identity() -> Self {
48-
Mat4 {
48+
Self {
4949
x_axis: Vec4::new(1.0, 0.0, 0.0, 0.0),
5050
y_axis: Vec4::new(0.0, 1.0, 0.0, 0.0),
5151
z_axis: Vec4::new(0.0, 0.0, 1.0, 0.0),
@@ -69,7 +69,7 @@ impl Mat4 {
6969
/// returned matrix.
7070
#[inline]
7171
pub fn from_cols_array(m: &[f32; 16]) -> Self {
72-
Mat4 {
72+
Self {
7373
x_axis: Vec4::new(m[0], m[1], m[2], m[3]),
7474
y_axis: Vec4::new(m[4], m[5], m[6], m[7]),
7575
z_axis: Vec4::new(m[8], m[9], m[10], m[11]),
@@ -89,7 +89,7 @@ impl Mat4 {
8989
/// the returned matrix.
9090
#[inline]
9191
pub fn from_cols_array_2d(m: &[[f32; 4]; 4]) -> Self {
92-
Mat4 {
92+
Self {
9393
x_axis: m[0].into(),
9494
y_axis: m[1].into(),
9595
z_axis: m[2].into(),

spirv-std/src/math/mod.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,44 +27,45 @@ pub trait MathExt {
2727
fn saturate(self) -> Self;
2828
}
2929

30+
#[allow(clippy::use_self)]
3031
impl MathExt for f32 {
31-
fn pow(self, factor: f32) -> f32 {
32+
fn pow(self, factor: Self) -> Self {
3233
unsafe { core::intrinsics::powf32(self, factor) }
3334
}
3435

35-
fn sqrt(self) -> f32 {
36+
fn sqrt(self) -> Self {
3637
unsafe { core::intrinsics::sqrtf32(self) }
3738
}
3839

39-
fn log2(self) -> f32 {
40+
fn log2(self) -> Self {
4041
unsafe { core::intrinsics::log2f32(self) }
4142
}
4243

43-
fn abs(self) -> f32 {
44+
fn abs(self) -> Self {
4445
unsafe { core::intrinsics::fabsf32(self) }
4546
}
4647

47-
fn cos(self) -> f32 {
48+
fn cos(self) -> Self {
4849
unsafe { core::intrinsics::cosf32(self) }
4950
}
5051

51-
fn round(self) -> f32 {
52+
fn round(self) -> Self {
5253
unsafe { core::intrinsics::roundf32(self) }
5354
}
5455

55-
fn floor(self) -> f32 {
56+
fn floor(self) -> Self {
5657
unsafe { core::intrinsics::floorf32(self) }
5758
}
5859

59-
fn ceil(self) -> f32 {
60+
fn ceil(self) -> Self {
6061
unsafe { core::intrinsics::ceilf32(self) }
6162
}
6263

63-
fn exp(self) -> f32 {
64+
fn exp(self) -> Self {
6465
unsafe { core::intrinsics::expf32(self) }
6566
}
6667

67-
fn saturate(self) -> f32 {
68+
fn saturate(self) -> Self {
6869
self.max(0.0).min(1.0)
6970
}
7071
}

spirv-std/src/math/vec2.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,38 +38,38 @@ impl Vec2 {
3838

3939
/// Creates a new `Vec2`.
4040
#[inline]
41-
pub fn new(x: f32, y: f32) -> Vec2 {
42-
Vec2(x, y)
41+
pub fn new(x: f32, y: f32) -> Self {
42+
Self(x, y)
4343
}
4444

4545
/// Creates a `Vec2` with all elements set to `0.0`.
4646
#[inline]
47-
pub fn zero() -> Vec2 {
47+
pub fn zero() -> Self {
4848
Self::splat(0.0)
4949
}
5050

5151
/// Creates a `Vec2` with all elements set to `1.0`.
5252
#[inline]
53-
pub fn one() -> Vec2 {
53+
pub fn one() -> Self {
5454
Self::splat(1.0)
5555
}
5656

5757
/// Creates a `Vec2` with values `[x: 1.0, y: 0.0]`.
5858
#[inline]
59-
pub fn unit_x() -> Vec2 {
59+
pub fn unit_x() -> Self {
6060
Self::new(1.0, 0.0)
6161
}
6262

6363
/// Creates a `Vec2` with values `[x: 0.0, y: 1.0]`.
6464
#[inline]
65-
pub fn unit_y() -> Vec2 {
65+
pub fn unit_y() -> Self {
6666
Self::new(0.0, 1.0)
6767
}
6868

6969
/// Creates a `Vec2` with all elements set to `v`.
7070
#[inline]
71-
pub fn splat(v: f32) -> Vec2 {
72-
Vec2(v, v)
71+
pub fn splat(v: f32) -> Self {
72+
Self(v, v)
7373
}
7474

7575
/// Creates a `Vec3` from `self` and the given `z` value.
@@ -116,7 +116,7 @@ impl Vec2 {
116116

117117
/// Computes the dot product of `self` and `other`.
118118
#[inline]
119-
pub fn dot(self, other: Vec2) -> f32 {
119+
pub fn dot(self, other: Self) -> f32 {
120120
(self.0 * other.0) + (self.1 * other.1)
121121
}
122122

@@ -153,7 +153,7 @@ impl Vec2 {
153153
///
154154
/// For valid results, `self` must _not_ be of length zero.
155155
#[inline]
156-
pub fn normalize(self) -> Vec2 {
156+
pub fn normalize(self) -> Self {
157157
self * self.length_recip()
158158
}
159159

@@ -163,8 +163,8 @@ impl Vec2 {
163163
/// `[x: min(x1, x2), y: min(y1, y2)]`,
164164
/// taking the minimum of each element individually.
165165
#[inline]
166-
pub fn min(self, other: Vec2) -> Vec2 {
167-
Vec2(self.0.min(other.0), self.1.min(other.1))
166+
pub fn min(self, other: Self) -> Self {
167+
Self(self.0.min(other.0), self.1.min(other.1))
168168
}
169169

170170
/// Returns the vertical maximum of `self` and `other`.
@@ -173,8 +173,8 @@ impl Vec2 {
173173
/// `[x: max(x1, x2), y: max(y1, y2)]`,
174174
/// taking the maximum of each element individually.
175175
#[inline]
176-
pub fn max(self, other: Vec2) -> Vec2 {
177-
Vec2(self.0.max(other.0), self.1.max(other.1))
176+
pub fn max(self, other: Self) -> Self {
177+
Self(self.0.max(other.0), self.1.max(other.1))
178178
}
179179

180180
/// Returns the horizontal minimum of `self`'s elements.
@@ -255,22 +255,22 @@ impl Vec2 {
255255

256256
/// The perpendicular dot product of the vector and `other`.
257257
#[inline]
258-
pub fn perp_dot(self, other: Vec2) -> f32 {
258+
pub fn perp_dot(self, other: Self) -> f32 {
259259
(self.0 * other.1) - (self.1 * other.0)
260260
}
261261
}
262262

263263
impl Div<Vec2> for Vec2 {
264264
type Output = Self;
265265
#[inline]
266-
fn div(self, other: Vec2) -> Self {
266+
fn div(self, other: Self) -> Self {
267267
Self(self.0 / other.0, self.1 / other.1)
268268
}
269269
}
270270

271271
impl DivAssign<Vec2> for Vec2 {
272272
#[inline]
273-
fn div_assign(&mut self, other: Vec2) {
273+
fn div_assign(&mut self, other: Self) {
274274
self.0 /= other.0;
275275
self.1 /= other.1;
276276
}
@@ -303,14 +303,14 @@ impl Div<Vec2> for f32 {
303303
impl Mul<Vec2> for Vec2 {
304304
type Output = Self;
305305
#[inline]
306-
fn mul(self, other: Vec2) -> Self {
306+
fn mul(self, other: Self) -> Self {
307307
Self(self.0 * other.0, self.1 * other.1)
308308
}
309309
}
310310

311311
impl MulAssign<Vec2> for Vec2 {
312312
#[inline]
313-
fn mul_assign(&mut self, other: Vec2) {
313+
fn mul_assign(&mut self, other: Self) {
314314
self.0 *= other.0;
315315
self.1 *= other.1;
316316
}
@@ -359,14 +359,14 @@ impl AddAssign for Vec2 {
359359
impl Sub for Vec2 {
360360
type Output = Self;
361361
#[inline]
362-
fn sub(self, other: Vec2) -> Self {
362+
fn sub(self, other: Self) -> Self {
363363
Self(self.0 - other.0, self.1 - other.1)
364364
}
365365
}
366366

367367
impl SubAssign for Vec2 {
368368
#[inline]
369-
fn sub_assign(&mut self, other: Vec2) {
369+
fn sub_assign(&mut self, other: Self) {
370370
self.0 -= other.0;
371371
self.1 -= other.1;
372372
}

spirv-std/src/math/vec3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl Vec3 {
155155
#[allow(dead_code)]
156156
pub(crate) fn dot_as_vec3(self, other: Self) -> Self {
157157
let dot = self.dot(other);
158-
Vec3::new(dot, dot, dot)
158+
Self::new(dot, dot, dot)
159159
}
160160

161161
/// Computes the cross product of `self` and `other`.

spirv-std/src/math/vec4.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,37 @@ impl Vec4 {
2727
/// Creates a `Vec4` with all elements set to `0.0`.
2828
#[inline]
2929
pub const fn zero() -> Self {
30-
Vec4::splat(0.0)
30+
Self::splat(0.0)
3131
}
3232

3333
/// Creates a `Vec4` with all elements set to `1.0`.
3434
#[inline]
3535
pub const fn one() -> Self {
36-
Vec4::splat(1.0)
36+
Self::splat(1.0)
3737
}
3838

3939
/// Creates a `Vec4` with values `[x: 1.0, y: 0.0, z: 0.0, w: 0.0]`.
4040
#[inline]
4141
pub const fn unit_x() -> Self {
42-
Vec4::new(1.0, 0.0, 0.0, 0.0)
42+
Self::new(1.0, 0.0, 0.0, 0.0)
4343
}
4444

4545
/// Creates a `Vec4` with values `[x: 0.0, y: 1.0, z: 0.0, w: 0.0]`.
4646
#[inline]
4747
pub const fn unit_y() -> Self {
48-
Vec4::new(0.0, 1.0, 0.0, 0.0)
48+
Self::new(0.0, 1.0, 0.0, 0.0)
4949
}
5050

5151
/// Creates a `Vec4` with values `[x: 0.0, y: 0.0, z: 1.0, w: 0.0]`.
5252
#[inline]
5353
pub const fn unit_z() -> Self {
54-
Vec4::new(0.0, 0.0, 1.0, 0.0)
54+
Self::new(0.0, 0.0, 1.0, 0.0)
5555
}
5656

5757
/// Creates a `Vec4` with values `[x: 0.0, y: 0.0, z: 0.0, w: 1.0]`.
5858
#[inline]
5959
pub const fn unit_w() -> Self {
60-
Vec4::new(0.0, 0.0, 0.0, 1.0)
60+
Self::new(0.0, 0.0, 0.0, 1.0)
6161
}
6262

6363
/// Creates a `Vec4` with all elements set to `v`.

0 commit comments

Comments
 (0)