From 18853ab149fa7c757f82a17c16a5a813db537808 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Sat, 13 Feb 2021 21:54:43 -0500 Subject: [PATCH] Add warnings for trivial casts and clean them up in the code --- src/back/glsl/mod.rs | 10 +++++----- src/back/spv/layout.rs | 2 +- src/back/spv/layout_tests.rs | 2 +- src/back/spv/mod.rs | 2 +- src/back/spv/test_framework.rs | 2 +- src/back/spv/writer.rs | 4 ++-- src/front/glsl/ast.rs | 2 +- src/lib.rs | 6 ++++++ 8 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/back/glsl/mod.rs b/src/back/glsl/mod.rs index 14959bbb35..d843dc920b 100644 --- a/src/back/glsl/mod.rs +++ b/src/back/glsl/mod.rs @@ -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, - array_index: Option>, + coordinate: Handle, + array_index: Option>, 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, Error> { +fn glsl_scalar(kind: ScalarKind, width: Bytes) -> Result, 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, expr: &crate::Expression) { + fn visit_expr(&mut self, _: Handle, expr: &Expression) { // We only care about `ImageSample` and `ImageLoad` // // Both `image` and `sampler` are `Expression::GlobalVariable` otherwise the module is diff --git a/src/back/spv/layout.rs b/src/back/spv/layout.rs index bba3697412..bbd4ea764b 100644 --- a/src/back/spv/layout.rs +++ b/src/back/spv/layout.rs @@ -83,7 +83,7 @@ impl Instruction { } pub(super) fn to_words(&self, sink: &mut impl Extend) { - 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()); diff --git a/src/back/spv/layout_tests.rs b/src/back/spv/layout_tests.rs index c09c91495c..b5f1018b78 100644 --- a/src/back/spv/layout_tests.rs +++ b/src/back/spv/layout_tests.rs @@ -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]) diff --git a/src/back/spv/mod.rs b/src/back/spv/mod.rs index bbad11f855..5e9f1de622 100644 --- a/src/back/spv/mod.rs +++ b/src/back/spv/mod.rs @@ -55,7 +55,7 @@ struct Instruction { pub fn write_vec( module: &crate::Module, flags: WriterFlags, - capabilities: crate::FastHashSet, + capabilities: crate::FastHashSet, ) -> Result, Error> { let mut words = Vec::new(); let mut w = Writer::new(&module.header, flags, capabilities); diff --git a/src/back/spv/test_framework.rs b/src/back/spv/test_framework.rs index be2fa74fe1..2b801ecf3a 100644 --- a/src/back/spv/test_framework.rs +++ b/src/back/spv/test_framework.rs @@ -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; } } diff --git a/src/back/spv/writer.rs b/src/back/spv/writer.rs index f9b05376f0..d2a0270d1e 100644 --- a/src/back/spv/writer.rs +++ b/src/back/spv/writer.rs @@ -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 = diff --git a/src/front/glsl/ast.rs b/src/front/glsl/ast.rs index 8b9144430a..a19cab9030 100644 --- a/src/front/glsl/ast.rs +++ b/src/front/glsl/ast.rs @@ -109,7 +109,7 @@ impl Program { pub fn resolve_type( &mut self, - handle: Handle, + handle: Handle, ) -> Result<&crate::TypeInner, ErrorKind> { let resolve_ctx = ResolveContext { constants: &self.module.constants, diff --git a/src/lib.rs b/src/lib.rs index 38d2157cc7..e4adc32fa4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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,