Detect multiple variants having same From type
This commit is contained in:
parent
f3b38c3a8a
commit
2492735b67
|
@ -1,5 +1,7 @@
|
|||
use crate::ast::{Enum, Field, Input, Struct, Variant};
|
||||
use crate::attr::Attrs;
|
||||
use quote::ToTokens;
|
||||
use std::collections::BTreeSet as Set;
|
||||
use syn::{Error, Member, Result};
|
||||
|
||||
pub(crate) const CHECKED: &str = "checked in validation";
|
||||
|
@ -37,6 +39,18 @@ impl Enum<'_> {
|
|||
));
|
||||
}
|
||||
}
|
||||
let mut from_types = Set::new();
|
||||
for variant in &self.variants {
|
||||
if let Some(from_field) = variant.from_field() {
|
||||
let repr = from_field.ty.to_token_stream().to_string();
|
||||
if !from_types.insert(repr) {
|
||||
return Err(Error::new_spanned(
|
||||
from_field.original,
|
||||
"cannot derive From because another variant has the same source type",
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue