Skip to content

Commit 0adf9c8

Browse files
chore: remove std::mem::* imports now unnecessary with Rust 1.80
`std::mem::{size,align}_of{,_val}` was added to `std::prelude` in Rust 1.80; see [`rust`#123168](rust-lang/rust#123168).
1 parent 5cc0791 commit 0adf9c8

File tree

39 files changed

+90
-117
lines changed

39 files changed

+90
-117
lines changed

examples/src/boids/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// adapted from https://github.com/austinEng/webgpu-samples/blob/master/src/examples/computeBoids.ts
33

44
use nanorand::{Rng, WyRand};
5-
use std::{borrow::Cow, mem};
5+
use std::borrow::Cow;
66
use wgpu::util::DeviceExt;
77

88
// number of boid particles to simulate
@@ -82,7 +82,7 @@ impl crate::framework::Example for Example {
8282
ty: wgpu::BufferBindingType::Uniform,
8383
has_dynamic_offset: false,
8484
min_binding_size: wgpu::BufferSize::new(
85-
(sim_param_data.len() * mem::size_of::<f32>()) as _,
85+
(sim_param_data.len() * size_of::<f32>()) as _,
8686
),
8787
},
8888
count: None,

examples/src/cube/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bytemuck::{Pod, Zeroable};
2-
use std::{borrow::Cow, f32::consts, mem};
2+
use std::{borrow::Cow, f32::consts};
33
use wgpu::util::DeviceExt;
44

55
#[repr(C)]
@@ -114,7 +114,7 @@ impl crate::framework::Example for Example {
114114
queue: &wgpu::Queue,
115115
) -> Self {
116116
// Create the vertex and index buffers
117-
let vertex_size = mem::size_of::<Vertex>();
117+
let vertex_size = size_of::<Vertex>();
118118
let (vertex_data, index_data) = create_vertices();
119119

120120
let vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {

examples/src/hello_compute/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async fn execute_gpu_inner(
7272
});
7373

7474
// Gets the size in bytes of the buffer.
75-
let size = std::mem::size_of_val(numbers) as wgpu::BufferAddress;
75+
let size = size_of_val(numbers) as wgpu::BufferAddress;
7676

7777
// Instantiates buffer without data.
7878
// `usage` of buffer specifies how it can be used:

examples/src/hello_synchronization/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ async fn execute(
6161

6262
let storage_buffer = device.create_buffer(&wgpu::BufferDescriptor {
6363
label: None,
64-
size: std::mem::size_of_val(local_patient_workgroup_results.as_slice()) as u64,
64+
size: size_of_val(local_patient_workgroup_results.as_slice()) as u64,
6565
usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_SRC,
6666
mapped_at_creation: false,
6767
});
6868
let output_staging_buffer = device.create_buffer(&wgpu::BufferDescriptor {
6969
label: None,
70-
size: std::mem::size_of_val(local_patient_workgroup_results.as_slice()) as u64,
70+
size: size_of_val(local_patient_workgroup_results.as_slice()) as u64,
7171
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ,
7272
mapped_at_creation: false,
7373
});
@@ -182,7 +182,7 @@ async fn get_data<T: bytemuck::Pod>(
182182
0,
183183
staging_buffer,
184184
0,
185-
std::mem::size_of_val(output) as u64,
185+
size_of_val(output) as u64,
186186
);
187187
queue.submit(Some(command_encoder.finish()));
188188
let buffer_slice = staging_buffer.slice(..);

examples/src/mipmap/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bytemuck::{Pod, Zeroable};
2-
use std::{borrow::Cow, f32::consts, mem};
2+
use std::{borrow::Cow, f32::consts};
33
use wgpu::util::DeviceExt;
44

55
const TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb;
@@ -54,8 +54,7 @@ type TimestampQueries = [TimestampData; MIP_PASS_COUNT as usize];
5454
type PipelineStatisticsQueries = [u64; MIP_PASS_COUNT as usize];
5555

5656
fn pipeline_statistics_offset() -> wgpu::BufferAddress {
57-
(mem::size_of::<TimestampQueries>() as wgpu::BufferAddress)
58-
.max(wgpu::QUERY_RESOLVE_BUFFER_ALIGNMENT)
57+
(size_of::<TimestampQueries>() as wgpu::BufferAddress).max(wgpu::QUERY_RESOLVE_BUFFER_ALIGNMENT)
5958
}
6059

6160
struct Example {
@@ -363,7 +362,7 @@ impl crate::framework::Example for Example {
363362
// This databuffer has to store all of the query results, 2 * passes timestamp queries
364363
// and 1 * passes statistics queries. Each query returns a u64 value.
365364
let buffer_size = pipeline_statistics_offset()
366-
+ mem::size_of::<PipelineStatisticsQueries>() as wgpu::BufferAddress;
365+
+ size_of::<PipelineStatisticsQueries>() as wgpu::BufferAddress;
367366
let data_buffer = device.create_buffer(&wgpu::BufferDescriptor {
368367
label: Some("query buffer"),
369368
size: buffer_size,
@@ -420,7 +419,7 @@ impl crate::framework::Example for Example {
420419
// This is guaranteed to be ready.
421420
let timestamp_view = query_sets
422421
.mapping_buffer
423-
.slice(..mem::size_of::<TimestampQueries>() as wgpu::BufferAddress)
422+
.slice(..size_of::<TimestampQueries>() as wgpu::BufferAddress)
424423
.get_mapped_range();
425424
let pipeline_stats_view = query_sets
426425
.mapping_buffer

examples/src/repeated_compute/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
//! hello-compute example does not such as mapping buffers
66
//! and why use the async channels.
77
8-
use std::mem::size_of_val;
9-
108
const OVERFLOW: u32 = 0xffffffff;
119

1210
async fn run() {

examples/src/shadow/mod.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{borrow::Cow, f32::consts, iter, mem, ops::Range, sync::Arc};
1+
use std::{borrow::Cow, f32::consts, iter, ops::Range, sync::Arc};
22

33
use bytemuck::{Pod, Zeroable};
44
use wgpu::util::{align_to, DeviceExt};
@@ -219,7 +219,7 @@ impl crate::framework::Example for Example {
219219
&& device.limits().max_storage_buffers_per_shader_stage > 0;
220220

221221
// Create the vertex and index buffers
222-
let vertex_size = mem::size_of::<Vertex>();
222+
let vertex_size = size_of::<Vertex>();
223223
let (cube_vertex_data, cube_index_data) = create_cube();
224224
let cube_vertex_buf = Arc::new(device.create_buffer_init(
225225
&wgpu::util::BufferInitDescriptor {
@@ -283,7 +283,7 @@ impl crate::framework::Example for Example {
283283
},
284284
];
285285

286-
let entity_uniform_size = mem::size_of::<EntityUniforms>() as wgpu::BufferAddress;
286+
let entity_uniform_size = size_of::<EntityUniforms>() as wgpu::BufferAddress;
287287
let num_entities = 1 + cube_descs.len() as wgpu::BufferAddress;
288288
// Make the `uniform_alignment` >= `entity_uniform_size` and aligned to `min_uniform_buffer_offset_alignment`.
289289
let uniform_alignment = {
@@ -427,8 +427,7 @@ impl crate::framework::Example for Example {
427427
target_view: shadow_target_views[1].take().unwrap(),
428428
},
429429
];
430-
let light_uniform_size =
431-
(Self::MAX_LIGHTS * mem::size_of::<LightRaw>()) as wgpu::BufferAddress;
430+
let light_uniform_size = (Self::MAX_LIGHTS * size_of::<LightRaw>()) as wgpu::BufferAddress;
432431
let light_storage_buf = device.create_buffer(&wgpu::BufferDescriptor {
433432
label: None,
434433
size: light_uniform_size,
@@ -454,7 +453,7 @@ impl crate::framework::Example for Example {
454453
});
455454

456455
let shadow_pass = {
457-
let uniform_size = mem::size_of::<GlobalUniforms>() as wgpu::BufferAddress;
456+
let uniform_size = size_of::<GlobalUniforms>() as wgpu::BufferAddress;
458457
// Create pipeline layout
459458
let bind_group_layout =
460459
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
@@ -548,7 +547,7 @@ impl crate::framework::Example for Example {
548547
ty: wgpu::BufferBindingType::Uniform,
549548
has_dynamic_offset: false,
550549
min_binding_size: wgpu::BufferSize::new(
551-
mem::size_of::<GlobalUniforms>() as _,
550+
size_of::<GlobalUniforms>() as _,
552551
),
553552
},
554553
count: None,
@@ -737,7 +736,7 @@ impl crate::framework::Example for Example {
737736
for (i, light) in self.lights.iter().enumerate() {
738737
queue.write_buffer(
739738
&self.light_storage_buf,
740-
(i * mem::size_of::<LightRaw>()) as wgpu::BufferAddress,
739+
(i * size_of::<LightRaw>()) as wgpu::BufferAddress,
741740
bytemuck::bytes_of(&light.to_raw()),
742741
);
743742
}
@@ -757,7 +756,7 @@ impl crate::framework::Example for Example {
757756
// let's just copy it over to the shadow uniform buffer.
758757
encoder.copy_buffer_to_buffer(
759758
&self.light_storage_buf,
760-
(i * mem::size_of::<LightRaw>()) as wgpu::BufferAddress,
759+
(i * size_of::<LightRaw>()) as wgpu::BufferAddress,
761760
&self.shadow_pass.uniform_buf,
762761
0,
763762
64,

examples/src/skybox/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl crate::framework::Example for Example {
231231
entry_point: Some("vs_entity"),
232232
compilation_options: Default::default(),
233233
buffers: &[wgpu::VertexBufferLayout {
234-
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
234+
array_stride: size_of::<Vertex>() as wgpu::BufferAddress,
235235
step_mode: wgpu::VertexStepMode::Vertex,
236236
attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3],
237237
}],

examples/src/stencil_triangles/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use bytemuck::{Pod, Zeroable};
22
use std::borrow::Cow;
3-
use std::mem;
43
use wgpu::util::DeviceExt;
54

65
#[repr(C)]
@@ -31,7 +30,7 @@ impl crate::framework::Example for Example {
3130
_queue: &wgpu::Queue,
3231
) -> Self {
3332
// Create the vertex and index buffers
34-
let vertex_size = mem::size_of::<Vertex>();
33+
let vertex_size = size_of::<Vertex>();
3534
let outer_vertices = [vertex(-1.0, -1.0), vertex(1.0, -1.0), vertex(0.0, 1.0)];
3635
let mask_vertices = [vertex(-0.5, 0.0), vertex(0.0, -1.0), vertex(0.5, 0.0)];
3736

examples/src/texture_arrays/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl crate::framework::Example for Example {
124124

125125
println!("Using fragment entry point '{fragment_entry_point}'");
126126

127-
let vertex_size = std::mem::size_of::<Vertex>();
127+
let vertex_size = size_of::<Vertex>();
128128
let vertex_data = create_vertices();
129129
let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
130130
label: Some("Vertex Buffer"),

examples/src/timestamp_queries/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ impl Queries {
123123
}),
124124
resolve_buffer: device.create_buffer(&wgpu::BufferDescriptor {
125125
label: Some("query resolve buffer"),
126-
size: std::mem::size_of::<u64>() as u64 * num_queries,
126+
size: size_of::<u64>() as u64 * num_queries,
127127
usage: wgpu::BufferUsages::COPY_SRC | wgpu::BufferUsages::QUERY_RESOLVE,
128128
mapped_at_creation: false,
129129
}),
130130
destination_buffer: device.create_buffer(&wgpu::BufferDescriptor {
131131
label: Some("query dest buffer"),
132-
size: std::mem::size_of::<u64>() as u64 * num_queries,
132+
size: size_of::<u64>() as u64 * num_queries,
133133
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ,
134134
mapped_at_creation: false,
135135
}),
@@ -164,7 +164,7 @@ impl Queries {
164164
let timestamps = {
165165
let timestamp_view = self
166166
.destination_buffer
167-
.slice(..(std::mem::size_of::<u64>() as wgpu::BufferAddress * self.num_queries))
167+
.slice(..(size_of::<u64>() as wgpu::BufferAddress * self.num_queries))
168168
.get_mapped_range();
169169
bytemuck::cast_slice(&timestamp_view).to_vec()
170170
};

examples/src/uniform_values/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl WgpuContext {
132132
// (2)
133133
let uniform_buffer = device.create_buffer(&wgpu::BufferDescriptor {
134134
label: None,
135-
size: std::mem::size_of::<AppState>() as u64,
135+
size: size_of::<AppState>() as u64,
136136
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
137137
mapped_at_creation: false,
138138
});

examples/src/water/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod point_gen;
33
use bytemuck::{Pod, Zeroable};
44
use glam::Vec3;
55
use nanorand::{Rng, WyRand};
6-
use std::{borrow::Cow, f32::consts, iter, mem};
6+
use std::{borrow::Cow, f32::consts, iter};
77
use wgpu::util::DeviceExt;
88

99
///
@@ -273,12 +273,12 @@ impl crate::framework::Example for Example {
273273
queue: &wgpu::Queue,
274274
) -> Self {
275275
// Size of one water vertex
276-
let water_vertex_size = mem::size_of::<point_gen::WaterVertexAttributes>();
276+
let water_vertex_size = size_of::<point_gen::WaterVertexAttributes>();
277277

278278
let water_vertices = point_gen::HexWaterMesh::generate(SIZE).generate_points();
279279

280280
// Size of one terrain vertex
281-
let terrain_vertex_size = mem::size_of::<point_gen::TerrainVertexAttributes>();
281+
let terrain_vertex_size = size_of::<point_gen::TerrainVertexAttributes>();
282282

283283
// Noise generation
284284
let terrain_noise = noise::OpenSimplex::default();
@@ -359,7 +359,7 @@ impl crate::framework::Example for Example {
359359
ty: wgpu::BufferBindingType::Uniform,
360360
has_dynamic_offset: false,
361361
min_binding_size: wgpu::BufferSize::new(
362-
mem::size_of::<WaterUniforms>() as _,
362+
size_of::<WaterUniforms>() as _,
363363
),
364364
},
365365
count: None,
@@ -415,7 +415,7 @@ impl crate::framework::Example for Example {
415415
ty: wgpu::BufferBindingType::Uniform,
416416
has_dynamic_offset: false,
417417
min_binding_size: wgpu::BufferSize::new(
418-
mem::size_of::<TerrainUniforms>() as _,
418+
size_of::<TerrainUniforms>() as _
419419
),
420420
},
421421
count: None,
@@ -440,21 +440,21 @@ impl crate::framework::Example for Example {
440440

441441
let water_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
442442
label: Some("Water Uniforms"),
443-
size: mem::size_of::<WaterUniforms>() as _,
443+
size: size_of::<WaterUniforms>() as _,
444444
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
445445
mapped_at_creation: false,
446446
});
447447

448448
let terrain_normal_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
449449
label: Some("Normal Terrain Uniforms"),
450-
size: mem::size_of::<TerrainUniforms>() as _,
450+
size: size_of::<TerrainUniforms>() as _,
451451
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
452452
mapped_at_creation: false,
453453
});
454454

455455
let terrain_flipped_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
456456
label: Some("Flipped Terrain Uniforms"),
457-
size: mem::size_of::<TerrainUniforms>() as _,
457+
size: size_of::<TerrainUniforms>() as _,
458458
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
459459
mapped_at_creation: false,
460460
});
@@ -712,7 +712,7 @@ impl crate::framework::Example for Example {
712712
let (water_sin, water_cos) = ((self.current_frame as f32) / 600.0).sin_cos();
713713
queue.write_buffer(
714714
&self.water_uniform_buf,
715-
mem::size_of::<[f32; 16]>() as wgpu::BufferAddress * 2,
715+
size_of::<[f32; 16]>() as wgpu::BufferAddress * 2,
716716
bytemuck::cast_slice(&[water_sin, water_cos]),
717717
);
718718

naga/src/back/msl/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,6 @@ pub fn write_string(
668668

669669
#[test]
670670
fn test_error_size() {
671-
use std::mem::size_of;
671+
use size_of;
672672
assert_eq!(size_of::<Error>(), 32);
673673
}

player/tests/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl ExpectedData {
3535
fn len(&self) -> usize {
3636
match self {
3737
ExpectedData::Raw(vec) => vec.len(),
38-
ExpectedData::U64(vec) => vec.len() * std::mem::size_of::<u64>(),
38+
ExpectedData::U64(vec) => vec.len() * size_of::<u64>(),
3939
ExpectedData::File(_, size) => *size,
4040
}
4141
}

tests/tests/compute_pass_ownership.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup {
253253
source: wgpu::ShaderSource::Wgsl(SHADER_SRC.into()),
254254
});
255255

256-
let buffer_size = 4 * std::mem::size_of::<f32>() as u64;
256+
let buffer_size = 4 * size_of::<f32>() as u64;
257257

258258
let bgl = ctx
259259
.device

tests/tests/occlusion_query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static OCCLUSION_QUERY: GpuTestConfiguration = GpuTestConfiguration::new()
100100
// Resolve query set to buffer
101101
let query_buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor {
102102
label: Some("Query buffer"),
103-
size: std::mem::size_of::<u64>() as u64 * 3,
103+
size: size_of::<u64>() as u64 * 3,
104104
usage: wgpu::BufferUsages::QUERY_RESOLVE | wgpu::BufferUsages::COPY_SRC,
105105
mapped_at_creation: false,
106106
});

tests/tests/render_pass_ownership.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup {
367367
source: wgpu::ShaderSource::Wgsl(SHADER_SRC.into()),
368368
});
369369

370-
let buffer_size = 4 * std::mem::size_of::<f32>() as u64;
370+
let buffer_size = 4 * size_of::<f32>() as u64;
371371

372372
let bgl = ctx
373373
.device
@@ -418,7 +418,7 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup {
418418
let vertex_buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor {
419419
label: Some("vertex_buffer"),
420420
usage: wgpu::BufferUsages::VERTEX,
421-
size: std::mem::size_of::<u32>() as u64 * vertex_count as u64,
421+
size: size_of::<u32>() as u64 * vertex_count as u64,
422422
mapped_at_creation: false,
423423
});
424424

tests/tests/subgroup_operations/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static SUBGROUP_OPERATIONS: GpuTestConfiguration = GpuTestConfiguration::new()
3535

3636
let storage_buffer = device.create_buffer(&wgpu::BufferDescriptor {
3737
label: None,
38-
size: THREAD_COUNT * std::mem::size_of::<u32>() as u64,
38+
size: THREAD_COUNT * size_of::<u32>() as u64,
3939
usage: wgpu::BufferUsages::STORAGE
4040
| wgpu::BufferUsages::COPY_DST
4141
| wgpu::BufferUsages::COPY_SRC,
@@ -50,9 +50,7 @@ static SUBGROUP_OPERATIONS: GpuTestConfiguration = GpuTestConfiguration::new()
5050
ty: wgpu::BindingType::Buffer {
5151
ty: wgpu::BufferBindingType::Storage { read_only: false },
5252
has_dynamic_offset: false,
53-
min_binding_size: NonZeroU64::new(
54-
THREAD_COUNT * std::mem::size_of::<u32>() as u64,
55-
),
53+
min_binding_size: NonZeroU64::new(THREAD_COUNT * size_of::<u32>() as u64),
5654
},
5755
count: None,
5856
}],

0 commit comments

Comments
 (0)