Skip to content

Commit

Permalink
emit from(ignore) on duplicate enum variants for derive_more 0.99 (#181)
Browse files Browse the repository at this point in the history
* Cargo update

* Update derive_more to 0.99

* emit from(ignore) on duplicate enum variants for derive_more 0.99

* Fix clippy::single_component_path_imports

    warning: this import is redundant
      --> spirv/lib.rs:15:1
       |
    15 | use num_traits;
       | ^^^^^^^^^^^^^^^ help: remove it entirely
       |
       = note: `#[warn(clippy::single_component_path_imports)]` on by default
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports
  • Loading branch information
MarijnS95 authored Jan 12, 2021
1 parent 7920128 commit dae552c
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 161 deletions.
184 changes: 37 additions & 147 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion autogen/src/dr.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashSet;

use crate::structs;
use crate::utils::*;

Expand Down Expand Up @@ -240,7 +242,19 @@ pub fn gen_dr_operand_kinds(grammar: &[structs::OperandKind]) -> TokenStream {
};

let kind_enum = {
let kinds = kind_and_ty.iter().map(|(kind, ty)| quote! {#kind(#ty)});
let mut types_seen = HashSet::new();

// To prevent ambiguity we don't want to generate an implementation for `Word` at all:
types_seen.insert(quote!(spirv::Word).to_string());

let kinds = kind_and_ty.iter().map(|(kind, ty)| {
let v = quote!(#kind(#ty));
if types_seen.insert(ty.to_string()) {
v
} else {
quote!(#[from(ignore)] #v)
}
});
quote! {
#[doc = "Data representation of a SPIR-V operand."]
#[derive(Clone, Debug, PartialEq, From)]
Expand Down
3 changes: 1 addition & 2 deletions autogen/src/sr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,10 @@ pub fn gen_sr_code_from_operand_kind_grammar(
})
.collect();
let tokens = quote! {
use derive_more::From;
use spirv;

/// SPIR-V decorations.
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, From)]
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub enum Decoration {
#( #enumerants ),*
}
Expand Down
2 changes: 1 addition & 1 deletion rspirv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ travis-ci = { repository = "gfx-rs/rspirv" }

[dependencies]
clippy = { version = "0.0", optional = true }
derive_more = "0.15"
derive_more = "0.99"
fxhash = "0.2"
num-traits = "0.2"

Expand Down
4 changes: 4 additions & 0 deletions rspirv/dr/autogen_operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ pub enum Operand {
RayQueryIntersection(spirv::RayQueryIntersection),
RayQueryCommittedIntersectionType(spirv::RayQueryCommittedIntersectionType),
RayQueryCandidateIntersectionType(spirv::RayQueryCandidateIntersectionType),
#[from(ignore)]
IdMemorySemantics(spirv::Word),
#[from(ignore)]
IdScope(spirv::Word),
#[from(ignore)]
IdRef(spirv::Word),
LiteralInt32(u32),
LiteralInt64(u64),
LiteralFloat32(f32),
LiteralFloat64(f64),
#[from(ignore)]
LiteralExtInstInteger(u32),
LiteralSpecConstantOpInteger(spirv::Op),
LiteralString(String),
Expand Down
Loading

0 comments on commit dae552c

Please sign in to comment.