Skip to content

Commit

Permalink
chore: #[must_use] annotations on getters and ctors
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski authored and teoxoy committed Aug 19, 2024
1 parent 3178ffb commit a87c8d7
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 16 deletions.
6 changes: 6 additions & 0 deletions deno_webgpu/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,31 @@ pub struct WebGpuResult {
}

impl WebGpuResult {
#[must_use]
pub fn rid(rid: ResourceId) -> Self {
Self {
rid: Some(rid),
err: None,
}
}

#[must_use]
pub fn rid_err<T: Into<WebGpuError>>(rid: ResourceId, err: Option<T>) -> Self {
Self {
rid: Some(rid),
err: err.map(Into::into),
}
}

#[must_use]
pub fn maybe_err<T: Into<WebGpuError>>(err: Option<T>) -> Self {
Self {
rid: None,
err: err.map(Into::into),
}
}

#[must_use]
pub fn empty() -> Self {
Self {
rid: None,
Expand Down Expand Up @@ -307,6 +311,7 @@ pub struct DomExceptionOperationError {
}

impl DomExceptionOperationError {
#[must_use]
pub fn new(msg: &str) -> Self {
DomExceptionOperationError {
msg: msg.to_string(),
Expand All @@ -322,6 +327,7 @@ impl fmt::Display for DomExceptionOperationError {

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

#[must_use]
pub fn get_error_class_name(e: &AnyError) -> Option<&'static str> {
e.downcast_ref::<DomExceptionOperationError>()
.map(|_| "DOMExceptionOperationError")
Expand Down
2 changes: 2 additions & 0 deletions naga/hlsl-snapshots/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub struct Config {
}

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

#[must_use]
pub fn is_empty(&self) -> bool {
let Self {
vertex,
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/bind_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn try_sampler_nonfiltering_layout(
let sampler = ctx.device.create_sampler(descriptor);

let create_bind_group = || {
ctx.device.create_bind_group(&wgpu::BindGroupDescriptor {
let _ = ctx.device.create_bind_group(&wgpu::BindGroupDescriptor {
label,
layout: &bind_group_layout,
entries: &[wgpu::BindGroupEntry {
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ static MINIMUM_BUFFER_BINDING_SIZE_LAYOUT: GpuTestConfiguration = GpuTestConfigu
wgpu_test::fail(
&ctx.device,
|| {
ctx.device
let _ = ctx.device
.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
label: None,
layout: Some(&pipeline_layout),
Expand Down
32 changes: 20 additions & 12 deletions tests/tests/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
fail(
&ctx.device,
|| {
ctx.device
let _ = ctx
.device
.create_command_encoder(&wgpu::CommandEncoderDescriptor::default());
},
Some("device with '' label is invalid"),
Expand All @@ -305,7 +306,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
fail(
&ctx.device,
|| {
ctx.device.create_buffer(&wgpu::BufferDescriptor {
let _ = ctx.device.create_buffer(&wgpu::BufferDescriptor {
label: None,
size: 256,
usage: wgpu::BufferUsages::MAP_WRITE | wgpu::BufferUsages::COPY_SRC,
Expand All @@ -319,7 +320,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
fail(
&ctx.device,
|| {
ctx.device.create_texture(&wgpu::TextureDescriptor {
let _ = ctx.device.create_texture(&wgpu::TextureDescriptor {
label: None,
size: wgpu::Extent3d {
width: 512,
Expand Down Expand Up @@ -458,7 +459,8 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
fail(
&ctx.device,
|| {
ctx.device
let _ = ctx
.device
.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: None,
entries: &[],
Expand All @@ -471,7 +473,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
fail(
&ctx.device,
|| {
ctx.device.create_bind_group(&wgpu::BindGroupDescriptor {
let _ = ctx.device.create_bind_group(&wgpu::BindGroupDescriptor {
label: None,
layout: &bind_group_layout,
entries: &[wgpu::BindGroupEntry {
Expand All @@ -489,7 +491,8 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
fail(
&ctx.device,
|| {
ctx.device
let _ = ctx
.device
.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: None,
bind_group_layouts: &[],
Expand All @@ -503,7 +506,8 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
fail(
&ctx.device,
|| {
ctx.device
let _ = ctx
.device
.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed("")),
Expand All @@ -516,7 +520,8 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
fail(
&ctx.device,
|| unsafe {
ctx.device
let _ = ctx
.device
.create_shader_module_spirv(&wgpu::ShaderModuleDescriptorSpirV {
label: None,
source: std::borrow::Cow::Borrowed(&[]),
Expand All @@ -529,7 +534,8 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
fail(
&ctx.device,
|| {
ctx.device
let _ = ctx
.device
.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: None,
layout: None,
Expand All @@ -554,7 +560,8 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
fail(
&ctx.device,
|| {
ctx.device
let _ = ctx
.device
.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
label: None,
layout: None,
Expand All @@ -571,7 +578,8 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
fail(
&ctx.device,
|| {
ctx.device
let _ = ctx
.device
.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
label: None,
layout: None,
Expand Down Expand Up @@ -852,7 +860,7 @@ static DIFFERENT_BGL_ORDER_BW_SHADER_AND_API: GpuTestConfiguration = GpuTestConf

// fail(&ctx.device, || {
// }, "");
ctx.device.create_bind_group(&wgpu::BindGroupDescriptor {
let _ = ctx.device.create_bind_group(&wgpu::BindGroupDescriptor {
label: None,
layout: &render_pipeline.get_bind_group_layout(0),
entries: &[
Expand Down
3 changes: 2 additions & 1 deletion tests/tests/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ static NO_TARGETLESS_RENDER: GpuTestConfiguration = GpuTestConfiguration::new()
// tries to compile code in an unsupported multisample count. Failing to validate here
// has historically resulted in requesting the back end to compile code.
for power_of_two in [1, 2, 4, 8, 16, 32, 64] {
ctx.device
let _ = ctx
.device
.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: None,
layout: None,
Expand Down
3 changes: 2 additions & 1 deletion tests/tests/regression/issue_5553.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ static ALLOW_INPUT_NOT_CONSUMED: GpuTestConfiguration =
push_constant_ranges: &[],
});

ctx.device
let _ = ctx
.device
.create_render_pipeline(&RenderPipelineDescriptor {
label: Some("Pipeline"),
layout: Some(&pipeline_layout),
Expand Down
3 changes: 3 additions & 0 deletions wgpu-types/src/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct InternalCounter {
impl InternalCounter {
/// Creates a counter with value 0.
#[inline]
#[must_use]
pub const fn new() -> Self {
InternalCounter {
#[cfg(feature = "counters")]
Expand All @@ -33,6 +34,7 @@ impl InternalCounter {
/// Always returns 0 if the `counters` feature is not enabled.
#[cfg(not(feature = "counters"))]
#[inline]
#[must_use]
pub fn read(&self) -> isize {
0
}
Expand All @@ -51,6 +53,7 @@ impl InternalCounter {
/// Always returns 0 if the `counters` feature is not enabled.
#[cfg(not(feature = "counters"))]
#[inline]
#[must_use]
pub fn take(&self) -> isize {
0
}
Expand Down
Loading

0 comments on commit a87c8d7

Please sign in to comment.