Skip to content

Commit a87c8d7

Browse files
kornelskiteoxoy
authored andcommitted
chore: #[must_use] annotations on getters and ctors
1 parent 3178ffb commit a87c8d7

File tree

10 files changed

+149
-16
lines changed

10 files changed

+149
-16
lines changed

deno_webgpu/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,31 @@ pub struct WebGpuResult {
6868
}
6969

7070
impl WebGpuResult {
71+
#[must_use]
7172
pub fn rid(rid: ResourceId) -> Self {
7273
Self {
7374
rid: Some(rid),
7475
err: None,
7576
}
7677
}
7778

79+
#[must_use]
7880
pub fn rid_err<T: Into<WebGpuError>>(rid: ResourceId, err: Option<T>) -> Self {
7981
Self {
8082
rid: Some(rid),
8183
err: err.map(Into::into),
8284
}
8385
}
8486

87+
#[must_use]
8588
pub fn maybe_err<T: Into<WebGpuError>>(err: Option<T>) -> Self {
8689
Self {
8790
rid: None,
8891
err: err.map(Into::into),
8992
}
9093
}
9194

95+
#[must_use]
9296
pub fn empty() -> Self {
9397
Self {
9498
rid: None,
@@ -307,6 +311,7 @@ pub struct DomExceptionOperationError {
307311
}
308312

309313
impl DomExceptionOperationError {
314+
#[must_use]
310315
pub fn new(msg: &str) -> Self {
311316
DomExceptionOperationError {
312317
msg: msg.to_string(),
@@ -322,6 +327,7 @@ impl fmt::Display for DomExceptionOperationError {
322327

323328
impl std::error::Error for DomExceptionOperationError {}
324329

330+
#[must_use]
325331
pub fn get_error_class_name(e: &AnyError) -> Option<&'static str> {
326332
e.downcast_ref::<DomExceptionOperationError>()
327333
.map(|_| "DOMExceptionOperationError")

naga/hlsl-snapshots/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub struct Config {
5353
}
5454

5555
impl Config {
56+
#[must_use]
5657
pub fn empty() -> Self {
5758
Self {
5859
vertex: Default::default(),
@@ -78,6 +79,7 @@ impl Config {
7879
fs::write(path, &s).map_err(|e| anyhow!("failed to write to {}: {e}", path.display()))
7980
}
8081

82+
#[must_use]
8183
pub fn is_empty(&self) -> bool {
8284
let Self {
8385
vertex,

tests/tests/bind_groups.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn try_sampler_nonfiltering_layout(
2222
let sampler = ctx.device.create_sampler(descriptor);
2323

2424
let create_bind_group = || {
25-
ctx.device.create_bind_group(&wgpu::BindGroupDescriptor {
25+
let _ = ctx.device.create_bind_group(&wgpu::BindGroupDescriptor {
2626
label,
2727
layout: &bind_group_layout,
2828
entries: &[wgpu::BindGroupEntry {

tests/tests/buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static MINIMUM_BUFFER_BINDING_SIZE_LAYOUT: GpuTestConfiguration = GpuTestConfigu
220220
wgpu_test::fail(
221221
&ctx.device,
222222
|| {
223-
ctx.device
223+
let _ = ctx.device
224224
.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
225225
label: None,
226226
layout: Some(&pipeline_layout),

tests/tests/device.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
295295
fail(
296296
&ctx.device,
297297
|| {
298-
ctx.device
298+
let _ = ctx
299+
.device
299300
.create_command_encoder(&wgpu::CommandEncoderDescriptor::default());
300301
},
301302
Some("device with '' label is invalid"),
@@ -305,7 +306,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
305306
fail(
306307
&ctx.device,
307308
|| {
308-
ctx.device.create_buffer(&wgpu::BufferDescriptor {
309+
let _ = ctx.device.create_buffer(&wgpu::BufferDescriptor {
309310
label: None,
310311
size: 256,
311312
usage: wgpu::BufferUsages::MAP_WRITE | wgpu::BufferUsages::COPY_SRC,
@@ -319,7 +320,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
319320
fail(
320321
&ctx.device,
321322
|| {
322-
ctx.device.create_texture(&wgpu::TextureDescriptor {
323+
let _ = ctx.device.create_texture(&wgpu::TextureDescriptor {
323324
label: None,
324325
size: wgpu::Extent3d {
325326
width: 512,
@@ -458,7 +459,8 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
458459
fail(
459460
&ctx.device,
460461
|| {
461-
ctx.device
462+
let _ = ctx
463+
.device
462464
.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
463465
label: None,
464466
entries: &[],
@@ -471,7 +473,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
471473
fail(
472474
&ctx.device,
473475
|| {
474-
ctx.device.create_bind_group(&wgpu::BindGroupDescriptor {
476+
let _ = ctx.device.create_bind_group(&wgpu::BindGroupDescriptor {
475477
label: None,
476478
layout: &bind_group_layout,
477479
entries: &[wgpu::BindGroupEntry {
@@ -489,7 +491,8 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
489491
fail(
490492
&ctx.device,
491493
|| {
492-
ctx.device
494+
let _ = ctx
495+
.device
493496
.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
494497
label: None,
495498
bind_group_layouts: &[],
@@ -503,7 +506,8 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
503506
fail(
504507
&ctx.device,
505508
|| {
506-
ctx.device
509+
let _ = ctx
510+
.device
507511
.create_shader_module(wgpu::ShaderModuleDescriptor {
508512
label: None,
509513
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed("")),
@@ -516,7 +520,8 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
516520
fail(
517521
&ctx.device,
518522
|| unsafe {
519-
ctx.device
523+
let _ = ctx
524+
.device
520525
.create_shader_module_spirv(&wgpu::ShaderModuleDescriptorSpirV {
521526
label: None,
522527
source: std::borrow::Cow::Borrowed(&[]),
@@ -529,7 +534,8 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
529534
fail(
530535
&ctx.device,
531536
|| {
532-
ctx.device
537+
let _ = ctx
538+
.device
533539
.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
534540
label: None,
535541
layout: None,
@@ -554,7 +560,8 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
554560
fail(
555561
&ctx.device,
556562
|| {
557-
ctx.device
563+
let _ = ctx
564+
.device
558565
.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
559566
label: None,
560567
layout: None,
@@ -571,7 +578,8 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
571578
fail(
572579
&ctx.device,
573580
|| {
574-
ctx.device
581+
let _ = ctx
582+
.device
575583
.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
576584
label: None,
577585
layout: None,
@@ -852,7 +860,7 @@ static DIFFERENT_BGL_ORDER_BW_SHADER_AND_API: GpuTestConfiguration = GpuTestConf
852860

853861
// fail(&ctx.device, || {
854862
// }, "");
855-
ctx.device.create_bind_group(&wgpu::BindGroupDescriptor {
863+
let _ = ctx.device.create_bind_group(&wgpu::BindGroupDescriptor {
856864
label: None,
857865
layout: &render_pipeline.get_bind_group_layout(0),
858866
entries: &[

tests/tests/pipeline.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ static NO_TARGETLESS_RENDER: GpuTestConfiguration = GpuTestConfiguration::new()
5858
// tries to compile code in an unsupported multisample count. Failing to validate here
5959
// has historically resulted in requesting the back end to compile code.
6060
for power_of_two in [1, 2, 4, 8, 16, 32, 64] {
61-
ctx.device
61+
let _ = ctx
62+
.device
6263
.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
6364
label: None,
6465
layout: None,

tests/tests/regression/issue_5553.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ static ALLOW_INPUT_NOT_CONSUMED: GpuTestConfiguration =
2424
push_constant_ranges: &[],
2525
});
2626

27-
ctx.device
27+
let _ = ctx
28+
.device
2829
.create_render_pipeline(&RenderPipelineDescriptor {
2930
label: Some("Pipeline"),
3031
layout: Some(&pipeline_layout),

wgpu-types/src/counters.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub struct InternalCounter {
1414
impl InternalCounter {
1515
/// Creates a counter with value 0.
1616
#[inline]
17+
#[must_use]
1718
pub const fn new() -> Self {
1819
InternalCounter {
1920
#[cfg(feature = "counters")]
@@ -33,6 +34,7 @@ impl InternalCounter {
3334
/// Always returns 0 if the `counters` feature is not enabled.
3435
#[cfg(not(feature = "counters"))]
3536
#[inline]
37+
#[must_use]
3638
pub fn read(&self) -> isize {
3739
0
3840
}
@@ -51,6 +53,7 @@ impl InternalCounter {
5153
/// Always returns 0 if the `counters` feature is not enabled.
5254
#[cfg(not(feature = "counters"))]
5355
#[inline]
56+
#[must_use]
5457
pub fn take(&self) -> isize {
5558
0
5659
}

0 commit comments

Comments
 (0)