Skip to content

Commit d9cc727

Browse files
Use more Rust features allowed under REPO_MSRV (#6887)
* chore: remove `std::mem::*` imports now unnecessary with `REPO_MSRV` `std::mem::{size,align}_of{,_val}` was added to `std::prelude` in Rust 1.80; see [`rust`#123168](rust-lang/rust#123168). * refactor(benches): s/once_cell::Lazy/std::sync::LazyLock Weaken our dependence on the `once_cell` crate by using functionality from `std` instead that was upstreamed from `once_cell`, this time with what's available in Rust 1.80+. It's not yet possible to eliminate this dependency entirely, but do what we can with `REPO_MSRV` for now. * chore: remove unnecessarily `allow`'d lint rules under `REPO_MSRV` * chore: migrate easy `allow`s to `expect` under `REPO_MSRV` Remove or `expect` clear-cut `allow` statements that were easy for me to figure out. * chore: `warn` on `clippy::allow_attributes` under `REPO_MSRV`
1 parent 450ac2d commit d9cc727

File tree

51 files changed

+103
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+103
-105
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benches/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ naga = { workspace = true, features = [
4343
"wgsl-out",
4444
] }
4545
nanorand.workspace = true
46-
once_cell.workspace = true
4746
pollster.workspace = true
4847
profiling.workspace = true
4948
rayon.workspace = true

benches/benches/bind_groups.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55

66
use criterion::{criterion_group, Criterion, Throughput};
77
use nanorand::{Rng, WyRand};
8-
use once_cell::sync::Lazy;
8+
use std::sync::LazyLock;
99

1010
use crate::DeviceState;
1111

@@ -60,7 +60,7 @@ impl BindGroupState {
6060
}
6161

6262
fn run_bench(ctx: &mut Criterion) {
63-
let state = Lazy::new(BindGroupState::new);
63+
let state = LazyLock::new(BindGroupState::new);
6464

6565
if !state
6666
.device_state

benches/benches/computepass.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::{
55

66
use criterion::{criterion_group, Criterion, Throughput};
77
use nanorand::{Rng, WyRand};
8-
use once_cell::sync::Lazy;
98
use rayon::iter::{IntoParallelIterator, ParallelIterator};
9+
use std::sync::LazyLock;
1010

1111
use crate::DeviceState;
1212

@@ -424,7 +424,7 @@ impl ComputepassState {
424424
}
425425

426426
fn run_bench(ctx: &mut Criterion) {
427-
let state = Lazy::new(ComputepassState::new);
427+
let state = LazyLock::new(ComputepassState::new);
428428

429429
let dispatch_count = dispatch_count();
430430
let dispatch_count_bindless = dispatch_count_bindless();
@@ -449,7 +449,7 @@ fn run_bench(ctx: &mut Criterion) {
449449
group.bench_function(
450450
format!("{cpasses} computepasses x {dispatch_per_pass} dispatches ({label})"),
451451
|b| {
452-
Lazy::force(&state);
452+
LazyLock::force(&state);
453453

454454
b.iter_custom(|iters| {
455455
profiling::scope!("benchmark invocation");
@@ -498,7 +498,7 @@ fn run_bench(ctx: &mut Criterion) {
498498
group.bench_function(
499499
format!("{threads} threads x {dispatch_per_pass} dispatch"),
500500
|b| {
501-
Lazy::force(&state);
501+
LazyLock::force(&state);
502502

503503
b.iter_custom(|iters| {
504504
profiling::scope!("benchmark invocation");
@@ -538,7 +538,7 @@ fn run_bench(ctx: &mut Criterion) {
538538
group.throughput(Throughput::Elements(dispatch_count_bindless as _));
539539

540540
group.bench_function(format!("{dispatch_count_bindless} dispatch"), |b| {
541-
Lazy::force(&state);
541+
LazyLock::force(&state);
542542

543543
b.iter_custom(|iters| {
544544
profiling::scope!("benchmark invocation");
@@ -579,7 +579,7 @@ fn run_bench(ctx: &mut Criterion) {
579579
texture_count + storage_texture_count + storage_buffer_count
580580
),
581581
|b| {
582-
Lazy::force(&state);
582+
LazyLock::force(&state);
583583

584584
b.iter(|| state.device_state.queue.submit([]));
585585
},

benches/benches/renderpass.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::{
55

66
use criterion::{criterion_group, Criterion, Throughput};
77
use nanorand::{Rng, WyRand};
8-
use once_cell::sync::Lazy;
98
use rayon::iter::{IntoParallelIterator, ParallelIterator};
9+
use std::sync::LazyLock;
1010

1111
use crate::DeviceState;
1212

@@ -427,7 +427,7 @@ impl RenderpassState {
427427
}
428428

429429
fn run_bench(ctx: &mut Criterion) {
430-
let state = Lazy::new(RenderpassState::new);
430+
let state = LazyLock::new(RenderpassState::new);
431431

432432
let draw_count = draw_count();
433433
let vertex_buffer_count = draw_count * VERTEX_BUFFERS_PER_DRAW;
@@ -450,7 +450,7 @@ fn run_bench(ctx: &mut Criterion) {
450450
group.bench_function(
451451
format!("{rpasses} renderpasses x {draws_per_pass} draws ({label})"),
452452
|b| {
453-
Lazy::force(&state);
453+
LazyLock::force(&state);
454454

455455
b.iter_custom(|iters| {
456456
profiling::scope!("benchmark invocation");
@@ -502,7 +502,7 @@ fn run_bench(ctx: &mut Criterion) {
502502
for threads in [2, 4, 8] {
503503
let draws_per_pass = draw_count / threads;
504504
group.bench_function(format!("{threads} threads x {draws_per_pass} draws"), |b| {
505-
Lazy::force(&state);
505+
LazyLock::force(&state);
506506

507507
b.iter_custom(|iters| {
508508
profiling::scope!("benchmark invocation");
@@ -541,7 +541,7 @@ fn run_bench(ctx: &mut Criterion) {
541541
group.throughput(Throughput::Elements(draw_count as _));
542542

543543
group.bench_function(format!("{draw_count} draws"), |b| {
544-
Lazy::force(&state);
544+
LazyLock::force(&state);
545545

546546
b.iter_custom(|iters| {
547547
profiling::scope!("benchmark invocation");
@@ -577,7 +577,7 @@ fn run_bench(ctx: &mut Criterion) {
577577
texture_count + vertex_buffer_count
578578
),
579579
|b| {
580-
Lazy::force(&state);
580+
LazyLock::force(&state);
581581

582582
b.iter(|| state.device_state.queue.submit([]));
583583
},

benches/benches/resource_creation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use std::time::{Duration, Instant};
22

33
use criterion::{criterion_group, Criterion, Throughput};
4-
use once_cell::sync::Lazy;
54
use rayon::iter::{IntoParallelIterator, ParallelIterator};
5+
use std::sync::LazyLock;
66

77
use crate::DeviceState;
88

99
fn run_bench(ctx: &mut Criterion) {
10-
let state = Lazy::new(DeviceState::new);
10+
let state = LazyLock::new(DeviceState::new);
1111

1212
const RESOURCES_TO_CREATE: usize = 8;
1313

@@ -19,7 +19,7 @@ fn run_bench(ctx: &mut Criterion) {
1919
group.bench_function(
2020
format!("{threads} threads x {resources_per_thread} resource"),
2121
|b| {
22-
Lazy::force(&state);
22+
LazyLock::force(&state);
2323

2424
b.iter_custom(|iters| {
2525
profiling::scope!("benchmark invocation");

examples/src/boids/mod.rs

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

44
use nanorand::{Rng, WyRand};
5-
use std::mem::size_of;
65
use wgpu::util::DeviceExt;
76

87
// number of boid particles to simulate

examples/src/bunnymark/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bytemuck::{Pod, Zeroable};
22
use nanorand::{Rng, WyRand};
3-
use std::{borrow::Cow, mem::size_of};
3+
use std::borrow::Cow;
44
use wgpu::util::DeviceExt;
55
use winit::{
66
event::{ElementState, KeyEvent},

examples/src/cube/mod.rs

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

55
#[repr(C)]

examples/src/framework.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,7 @@ async fn start<E: Example>(title: &str) {
362362
}
363363

364364
log::info!("Entering event loop...");
365-
// On native this is a result, but on wasm it's a unit type.
366-
#[allow(clippy::let_unit_value)]
365+
#[cfg_attr(target_arch = "wasm32", expect(clippy::let_unit_value))]
367366
let _ = (event_loop_function)(
368367
window_loop.event_loop,
369368
move |event: Event<()>, target: &EventLoopWindowTarget<()>| {

examples/src/hello/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/// This example shows how to describe the adapter in use.
22
async fn run() {
3-
#[cfg_attr(target_arch = "wasm32", allow(unused_variables))]
43
let adapter = {
54
let instance = wgpu::Instance::default();
65
#[cfg(not(target_arch = "wasm32"))]

examples/src/hello_compute/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use std::{mem::size_of_val, str::FromStr};
1+
use std::str::FromStr;
22
use wgpu::util::DeviceExt;
33

44
// Indicates a u32 overflow in an intermediate Collatz value
55
const OVERFLOW: u32 = 0xffffffff;
66

7-
#[cfg_attr(test, allow(dead_code))]
87
async fn run() {
98
let numbers = if std::env::args().len() <= 2 {
109
let default = vec![1, 2, 3, 4];
@@ -32,7 +31,6 @@ async fn run() {
3231
log::info!("Steps: [{}]", disp_steps.join(", "));
3332
}
3433

35-
#[cfg_attr(test, allow(dead_code))]
3634
async fn execute_gpu(numbers: &[u32]) -> Option<Vec<u32>> {
3735
// Instantiates instance of WebGPU
3836
let instance = wgpu::Instance::default();

examples/src/hello_synchronization/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
use std::mem::size_of_val;
2-
31
const ARR_SIZE: usize = 128;
42

53
struct ExecuteResults {
64
patient_workgroup_results: Vec<u32>,
7-
#[cfg_attr(test, allow(unused))]
85
hasty_workgroup_results: Vec<u32>,
96
}
107

11-
#[cfg_attr(test, allow(unused))]
128
async fn run() {
139
let instance = wgpu::Instance::default();
1410
let adapter = instance

examples/src/hello_triangle/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
147147

148148
pub fn main() {
149149
let event_loop = EventLoop::new().unwrap();
150-
#[allow(unused_mut)]
150+
#[cfg_attr(
151+
not(target_arch = "wasm32"),
152+
expect(unused_mut, reason = "`wasm32` re-assigns to specify canvas")
153+
)]
151154
let mut builder = winit::window::WindowBuilder::new();
152155
#[cfg(target_arch = "wasm32")]
153156
{

examples/src/hello_workgroups/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
//!
88
//! Only parts specific to this example will be commented.
99
10-
use std::mem::size_of_val;
11-
1210
use wgpu::util::DeviceExt;
1311

1412
async fn run() {

examples/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![allow(clippy::arc_with_non_send_sync)] // False positive on wasm
2+
#![warn(clippy::allow_attributes)]
23

34
pub mod framework;
45
pub mod utils;

examples/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
struct ExampleDesc {
22
name: &'static str,
33
function: fn(),
4-
#[allow(dead_code)] // isn't used on native
4+
#[cfg_attr(not(target_arch = "wasm32"), expect(dead_code))]
55
webgl: bool,
6-
#[allow(dead_code)] // isn't used on native
6+
#[cfg_attr(not(target_arch = "wasm32"), expect(dead_code))]
77
webgpu: bool,
88
}
99

examples/src/mipmap/mod.rs

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

55
const TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb;

examples/src/msaa_line/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! * Set the primitive_topology to PrimitiveTopology::LineList.
88
//! * Vertices and Indices describe the two points that make up a line.
99
10-
use std::{iter, mem::size_of};
10+
use std::iter;
1111

1212
use bytemuck::{Pod, Zeroable};
1313
use wgpu::util::DeviceExt;
@@ -214,7 +214,7 @@ impl crate::framework::Example for Example {
214214
}
215215
}
216216

217-
#[allow(clippy::single_match)]
217+
#[expect(clippy::single_match)]
218218
fn update(&mut self, event: winit::event::WindowEvent) {
219219
match event {
220220
WindowEvent::KeyboardInput {

examples/src/ray_cube_compute/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,17 @@ impl<F: Future<Output = Option<wgpu::Error>>> Future for ErrorFuture<F> {
118118
}
119119
}
120120

121-
#[allow(dead_code)]
122121
struct Example {
123122
rt_target: wgpu::Texture,
123+
#[expect(dead_code)]
124124
rt_view: wgpu::TextureView,
125+
#[expect(dead_code)]
125126
sampler: wgpu::Sampler,
127+
#[expect(dead_code)]
126128
uniform_buf: wgpu::Buffer,
129+
#[expect(dead_code)]
127130
vertex_buf: wgpu::Buffer,
131+
#[expect(dead_code)]
128132
index_buf: wgpu::Buffer,
129133
tlas_package: wgpu::TlasPackage,
130134
compute_pipeline: wgpu::ComputePipeline,

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{f32::consts, iter, mem::size_of, ops::Range, sync::Arc};
1+
use std::{f32::consts, iter, ops::Range, sync::Arc};
22

33
use bytemuck::{Pod, Zeroable};
44
use wgpu::util::{align_to, DeviceExt};

examples/src/skybox/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::{f32::consts, mem::size_of};
2+
use std::f32::consts;
33
use wgpu::{util::DeviceExt, AstcBlock, AstcChannel};
44

55
const IMAGE_SIZE: u32 = 256;
@@ -379,7 +379,7 @@ impl crate::framework::Example for Example {
379379
}
380380
}
381381

382-
#[allow(clippy::single_match)]
382+
#[expect(clippy::single_match)]
383383
fn update(&mut self, event: winit::event::WindowEvent) {
384384
match event {
385385
winit::event::WindowEvent::CursorMoved { position, .. } => {

examples/src/srgb_blend/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use bytemuck::{Pod, Zeroable};
2-
use std::mem::size_of;
32
use wgpu::util::DeviceExt;
43

54
#[repr(C)]

examples/src/stencil_triangles/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use bytemuck::{Pod, Zeroable};
2-
use std::mem::size_of;
32
use wgpu::util::DeviceExt;
43

54
#[repr(C)]

examples/src/storage_texture/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
//! A lot of things aren't explained here via comments. See hello-compute and
1515
//! repeated-compute for code that is more thoroughly commented.
1616
17-
use std::mem::size_of_val;
18-
1917
#[cfg(not(target_arch = "wasm32"))]
2018
use crate::utils::output_image_native;
2119
#[cfg(target_arch = "wasm32")]

examples/src/texture_arrays/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use bytemuck::{Pod, Zeroable};
2-
use std::{
3-
mem::size_of,
4-
num::{NonZeroU32, NonZeroU64},
5-
};
2+
use std::num::{NonZeroU32, NonZeroU64};
63
use wgpu::util::DeviceExt;
74

85
#[repr(C)]

0 commit comments

Comments
 (0)