From e19c11fdb30295127cff1d018189bd436892415e Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Fri, 1 Nov 2024 12:37:53 +0100 Subject: [PATCH] Fix clippy lints Specifically `rust-version = "1.58"` in the `autogen` module that I added in #223 is weird, since any developers working on and/or contributing to the repository should easily be able to run the latest stable and take advantage of newer Rust features in `autogen` code. --- autogen/Cargo.toml | 1 - autogen/src/binary.rs | 4 ++-- autogen/src/dr.rs | 4 ++-- autogen/src/structs.rs | 15 ++++++--------- rspirv/binary/autogen_decode_operand.rs | 2 +- rspirv/binary/autogen_parse_operand.rs | 2 +- rspirv/binary/decoder.rs | 4 ++-- rspirv/binary/tracker.rs | 2 +- rspirv/sr/storage.rs | 8 ++++---- 9 files changed, 19 insertions(+), 23 deletions(-) diff --git a/autogen/Cargo.toml b/autogen/Cargo.toml index 43c85fd7..10a0174d 100644 --- a/autogen/Cargo.toml +++ b/autogen/Cargo.toml @@ -6,7 +6,6 @@ authors = [ "Lei Zhang ", ] edition = "2018" -rust-version = "1.58" publish = false diff --git a/autogen/src/binary.rs b/autogen/src/binary.rs index f880b8f9..61cd5b35 100644 --- a/autogen/src/binary.rs +++ b/autogen/src/binary.rs @@ -111,7 +111,7 @@ pub fn gen_operand_decode_methods(grammar: &[structs::OperandKind]) -> TokenStre }); quote! { - impl<'a> Decoder<'a> { + impl Decoder<'_> { #(#methods)* } } @@ -288,7 +288,7 @@ pub fn gen_operand_parse_methods(grammar: &[structs::OperandKind]) -> TokenStrea }); quote! { - impl<'c, 'd> Parser<'c, 'd> { + impl Parser<'_, '_> { fn parse_operand(&mut self, kind: GOpKind) -> Result> { Ok(match kind { #(#normal_cases),*, diff --git a/autogen/src/dr.rs b/autogen/src/dr.rs index bc5b4125..90ecbd22 100644 --- a/autogen/src/dr.rs +++ b/autogen/src/dr.rs @@ -391,7 +391,7 @@ pub fn gen_dr_operand_kinds(grammar: &[structs::OperandKind]) -> TokenStream { let mut seen_discriminator = BTreeMap::new(); for e in enumerators { - if seen_discriminator.get(&e.value).is_none() { + if let std::collections::btree_map::Entry::Vacant(seen_entry) = seen_discriminator.entry(e.value) { let name = match category { structs::Category::BitEnum => { use heck::ShoutySnakeCase; @@ -412,7 +412,7 @@ pub fn gen_dr_operand_kinds(grammar: &[structs::OperandKind]) -> TokenStream { _ => panic!("Unexpected operand type"), }; - seen_discriminator.insert(e.value, name.clone()); + seen_entry.insert(name.clone()); capability_clauses .entry(&e.capabilities) diff --git a/autogen/src/structs.rs b/autogen/src/structs.rs index 138a895b..d24939d4 100644 --- a/autogen/src/structs.rs +++ b/autogen/src/structs.rs @@ -1,4 +1,6 @@ -/// Rust structs for deserializing the SPIR-V JSON grammar. +//! Rust structs for deserializing the SPIR-V JSON grammar. +#![allow(dead_code)] // Parsed but unread fields + use serde::de; use serde_derive::*; use std::{convert::TryInto, fmt, result, str}; @@ -74,7 +76,7 @@ pub struct ExtInstSetGrammar { fn num_or_hex<'de, D: de::Deserializer<'de>>(d: D) -> result::Result { struct NumOrStr; - impl<'de> de::Visitor<'de> for NumOrStr { + impl de::Visitor<'_> for NumOrStr { type Value = u32; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { @@ -93,9 +95,10 @@ fn num_or_hex<'de, D: de::Deserializer<'de>>(d: D) -> result::Result Self { - Quantifier::One - } -} - #[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize)] pub enum Class { Annotation, diff --git a/rspirv/binary/autogen_decode_operand.rs b/rspirv/binary/autogen_decode_operand.rs index 4e01335a..b709174c 100644 --- a/rspirv/binary/autogen_decode_operand.rs +++ b/rspirv/binary/autogen_decode_operand.rs @@ -2,7 +2,7 @@ // external/spirv.core.grammar.json. // DO NOT MODIFY! -impl<'a> Decoder<'a> { +impl Decoder<'_> { #[doc = "Decodes and returns the next SPIR-V word as\na SPIR-V ImageOperands value."] pub fn image_operands(&mut self) -> Result { if let Ok(word) = self.word() { diff --git a/rspirv/binary/autogen_parse_operand.rs b/rspirv/binary/autogen_parse_operand.rs index 9709215d..d9bc7a5d 100644 --- a/rspirv/binary/autogen_parse_operand.rs +++ b/rspirv/binary/autogen_parse_operand.rs @@ -2,7 +2,7 @@ // external/spirv.core.grammar.json. // DO NOT MODIFY! -impl<'c, 'd> Parser<'c, 'd> { +impl Parser<'_, '_> { fn parse_operand(&mut self, kind: GOpKind) -> Result> { Ok(match kind { GOpKind::FPFastMathMode => vec![dr::Operand::FPFastMathMode( diff --git a/rspirv/binary/decoder.rs b/rspirv/binary/decoder.rs index 6e8e0136..48fc1c59 100644 --- a/rspirv/binary/decoder.rs +++ b/rspirv/binary/decoder.rs @@ -112,7 +112,7 @@ impl<'a> Decoder<'a> { } } -impl<'a> Decoder<'a> { +impl Decoder<'_> { /// Sets the limit to `num_words` words. /// /// The decoder will return [`State::LimitReached`](enum.ParseState.html) @@ -144,7 +144,7 @@ impl<'a> Decoder<'a> { } } -impl<'a> Decoder<'a> { +impl Decoder<'_> { /// Decodes and returns the next SPIR-V word as an id. pub fn id(&mut self) -> Result { self.word() diff --git a/rspirv/binary/tracker.rs b/rspirv/binary/tracker.rs index 9ca0af4a..d7689a10 100644 --- a/rspirv/binary/tracker.rs +++ b/rspirv/binary/tracker.rs @@ -116,7 +116,7 @@ impl ExtInstSetTracker { /// Returns true if the given extended instruction `set` has been /// recognized thus tracked. pub fn have(&self, set: spirv::Word) -> bool { - self.sets.get(&set).is_some() + self.sets.contains_key(&set) } /// Resolves the extended instruction with `opcode` in set `set`. diff --git a/rspirv/sr/storage.rs b/rspirv/sr/storage.rs index 4055f2d1..7e2daf18 100644 --- a/rspirv/sr/storage.rs +++ b/rspirv/sr/storage.rs @@ -112,8 +112,8 @@ mod tests { #[test] fn append_unique() { let mut storage: Storage = Storage::new(); - let t1 = storage.append(std::f64::NAN); - let t2 = storage.append(std::f64::NAN); + let t1 = storage.append(f64::NAN); + let t2 = storage.append(f64::NAN); assert!(t1 != t2); assert!(storage[t1] != storage[t2]); } @@ -130,8 +130,8 @@ mod tests { #[test] fn fetch_or_append_unique() { let mut storage: Storage = Storage::new(); - let t1 = storage.fetch_or_append(std::f64::NAN); - let t2 = storage.fetch_or_append(std::f64::NAN); + let t1 = storage.fetch_or_append(f64::NAN); + let t2 = storage.fetch_or_append(f64::NAN); assert!(t1 != t2); assert!(storage[t1] != storage[t2]); }