mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Add warnings for trivial casts and clean them up in the code
This commit is contained in:
committed by
Dzmitry Malyshau
parent
8e96085caf
commit
18853ab149
@@ -211,7 +211,7 @@ impl IdGenerator {
|
||||
}
|
||||
|
||||
/// Shorthand result used internally by the backend
|
||||
type BackendResult = std::result::Result<(), Error>;
|
||||
type BackendResult = Result<(), Error>;
|
||||
|
||||
/// A glsl compilation error.
|
||||
#[derive(Debug, Error)]
|
||||
@@ -1716,8 +1716,8 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
|
||||
fn write_texture_coordinates(
|
||||
&mut self,
|
||||
coordinate: Handle<crate::Expression>,
|
||||
array_index: Option<Handle<crate::Expression>>,
|
||||
coordinate: Handle<Expression>,
|
||||
array_index: Option<Handle<Expression>>,
|
||||
dim: crate::ImageDimension,
|
||||
ctx: &FunctionCtx,
|
||||
) -> Result<(), Error> {
|
||||
@@ -1793,7 +1793,7 @@ struct ScalarString<'a> {
|
||||
///
|
||||
/// # Errors
|
||||
/// If a [`Float`](crate::ScalarKind::Float) with an width that isn't 4 or 8
|
||||
fn glsl_scalar(kind: ScalarKind, width: crate::Bytes) -> Result<ScalarString<'static>, Error> {
|
||||
fn glsl_scalar(kind: ScalarKind, width: Bytes) -> Result<ScalarString<'static>, Error> {
|
||||
Ok(match kind {
|
||||
ScalarKind::Sint => ScalarString {
|
||||
prefix: "i",
|
||||
@@ -1940,7 +1940,7 @@ struct TextureMappingVisitor<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Visitor for TextureMappingVisitor<'a> {
|
||||
fn visit_expr(&mut self, _: Handle<crate::Expression>, expr: &crate::Expression) {
|
||||
fn visit_expr(&mut self, _: Handle<Expression>, expr: &Expression) {
|
||||
// We only care about `ImageSample` and `ImageLoad`
|
||||
//
|
||||
// Both `image` and `sampler` are `Expression::GlobalVariable` otherwise the module is
|
||||
|
||||
@@ -83,7 +83,7 @@ impl Instruction {
|
||||
}
|
||||
|
||||
pub(super) fn to_words(&self, sink: &mut impl Extend<Word>) {
|
||||
sink.extend(Some((self.wc << 16 | self.op as u32) as u32));
|
||||
sink.extend(Some(self.wc << 16 | self.op as u32));
|
||||
sink.extend(self.type_id);
|
||||
sink.extend(self.result_id);
|
||||
sink.extend(self.operands.iter().cloned());
|
||||
|
||||
@@ -18,7 +18,7 @@ fn test_physical_layout_in_words() {
|
||||
|
||||
layout.in_words(&mut output);
|
||||
|
||||
assert_eq!(output[0], spirv::MAGIC_NUMBER);
|
||||
assert_eq!(output[0], MAGIC_NUMBER);
|
||||
assert_eq!(
|
||||
output[1],
|
||||
to_word(&[header.version.0, header.version.1, header.version.2, 1])
|
||||
|
||||
@@ -55,7 +55,7 @@ struct Instruction {
|
||||
pub fn write_vec(
|
||||
module: &crate::Module,
|
||||
flags: WriterFlags,
|
||||
capabilities: crate::FastHashSet<spirv::Capability>,
|
||||
capabilities: crate::FastHashSet<Capability>,
|
||||
) -> Result<Vec<u32>, Error> {
|
||||
let mut words = Vec::new();
|
||||
let mut w = Writer::new(&module.header, flags, capabilities);
|
||||
|
||||
@@ -21,7 +21,7 @@ pub(super) fn validate_instruction(
|
||||
|
||||
let mut op_index = 0;
|
||||
for i in inst_index..wc as usize {
|
||||
assert_eq!(words[i as usize], instruction.operands[op_index]);
|
||||
assert_eq!(words[i], instruction.operands[op_index]);
|
||||
op_index += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,7 +336,7 @@ impl Writer {
|
||||
)
|
||||
}
|
||||
|
||||
fn create_pointer_type(&mut self, type_id: spirv::Word, class: spirv::StorageClass) -> Word {
|
||||
fn create_pointer_type(&mut self, type_id: Word, class: spirv::StorageClass) -> Word {
|
||||
let id = self.generate_id();
|
||||
let instruction = Instruction::type_pointer(id, class, type_id);
|
||||
instruction.to_words(&mut self.logical_layout.declarations);
|
||||
@@ -1398,7 +1398,7 @@ impl Writer {
|
||||
use crate::MathFunction as Mf;
|
||||
enum MathOp {
|
||||
Ext(spirv::GLOp),
|
||||
Custom(super::Instruction),
|
||||
Custom(Instruction),
|
||||
}
|
||||
|
||||
let arg0_id =
|
||||
|
||||
@@ -109,7 +109,7 @@ impl Program {
|
||||
|
||||
pub fn resolve_type(
|
||||
&mut self,
|
||||
handle: Handle<crate::Expression>,
|
||||
handle: Handle<Expression>,
|
||||
) -> Result<&crate::TypeInner, ErrorKind> {
|
||||
let resolve_ctx = ResolveContext {
|
||||
constants: &self.module.constants,
|
||||
|
||||
@@ -4,6 +4,12 @@
|
||||
//!
|
||||
//! To improve performance and reduce memory usage, most structures are stored
|
||||
//! in an [`Arena`], and can be retrieved using the corresponding [`Handle`].
|
||||
#![warn(
|
||||
trivial_casts,
|
||||
trivial_numeric_casts,
|
||||
unused_extern_crates,
|
||||
unused_qualifications
|
||||
)]
|
||||
#![allow(
|
||||
clippy::new_without_default,
|
||||
clippy::unneeded_field_pattern,
|
||||
|
||||
Reference in New Issue
Block a user