diff --git a/autogen/src/dr.rs b/autogen/src/dr.rs index e548ca92..c929ed9e 100644 --- a/autogen/src/dr.rs +++ b/autogen/src/dr.rs @@ -1,3 +1,5 @@ +use std::collections::HashSet; + use crate::structs; use crate::utils::*; @@ -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)] diff --git a/autogen/src/sr.rs b/autogen/src/sr.rs index 6bfe12fe..14f935aa 100644 --- a/autogen/src/sr.rs +++ b/autogen/src/sr.rs @@ -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 ),* } diff --git a/rspirv/dr/autogen_operand.rs b/rspirv/dr/autogen_operand.rs index 02bcbc54..05549ff3 100644 --- a/rspirv/dr/autogen_operand.rs +++ b/rspirv/dr/autogen_operand.rs @@ -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), diff --git a/rspirv/sr/autogen_decoration.rs b/rspirv/sr/autogen_decoration.rs index ace64096..2c35bd90 100644 --- a/rspirv/sr/autogen_decoration.rs +++ b/rspirv/sr/autogen_decoration.rs @@ -2,10 +2,9 @@ // external/spirv.core.grammar.json. // DO NOT MODIFY! -use derive_more::From; use spirv; #[doc = r" SPIR-V decorations."] -#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, From)] +#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] pub enum Decoration { RelaxedPrecision, SpecId(u32),