Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MarijnS95 committed Dec 27, 2024
1 parent b2662b2 commit e19c11f
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 23 deletions.
1 change: 0 additions & 1 deletion autogen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ authors = [
"Lei Zhang <antiagainst@gmail.com>",
]
edition = "2018"
rust-version = "1.58"

publish = false

Expand Down
4 changes: 2 additions & 2 deletions autogen/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub fn gen_operand_decode_methods(grammar: &[structs::OperandKind]) -> TokenStre
});

quote! {
impl<'a> Decoder<'a> {
impl Decoder<'_> {
#(#methods)*
}
}
Expand Down Expand Up @@ -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<Vec<dr::Operand>> {
Ok(match kind {
#(#normal_cases),*,
Expand Down
4 changes: 2 additions & 2 deletions autogen/src/dr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
15 changes: 6 additions & 9 deletions autogen/src/structs.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -74,7 +76,7 @@ pub struct ExtInstSetGrammar {
fn num_or_hex<'de, D: de::Deserializer<'de>>(d: D) -> result::Result<u32, D::Error> {
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 {
Expand All @@ -93,22 +95,17 @@ fn num_or_hex<'de, D: de::Deserializer<'de>>(d: D) -> result::Result<u32, D::Err
d.deserialize_any(NumOrStr)
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Ord, PartialOrd)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Deserialize, Ord, PartialOrd)]
pub enum Quantifier {
#[serde(rename = "")]
#[default]
One,
#[serde(rename = "?")]
ZeroOrOne,
#[serde(rename = "*")]
ZeroOrMore,
}

impl Default for Quantifier {
fn default() -> Self {
Quantifier::One
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize)]
pub enum Class {
Annotation,
Expand Down
2 changes: 1 addition & 1 deletion rspirv/binary/autogen_decode_operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<spirv::ImageOperands> {
if let Ok(word) = self.word() {
Expand Down
2 changes: 1 addition & 1 deletion rspirv/binary/autogen_parse_operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<dr::Operand>> {
Ok(match kind {
GOpKind::FPFastMathMode => vec![dr::Operand::FPFastMathMode(
Expand Down
4 changes: 2 additions & 2 deletions rspirv/binary/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<spirv::Word> {
self.word()
Expand Down
2 changes: 1 addition & 1 deletion rspirv/binary/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
8 changes: 4 additions & 4 deletions rspirv/sr/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ mod tests {
#[test]
fn append_unique() {
let mut storage: Storage<f64> = 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]);
}
Expand All @@ -130,8 +130,8 @@ mod tests {
#[test]
fn fetch_or_append_unique() {
let mut storage: Storage<f64> = 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]);
}
Expand Down

0 comments on commit e19c11f

Please sign in to comment.