Record original syntax tree references for error reporting

This commit is contained in:
David Tolnay 2019-10-12 11:00:33 -07:00
parent 69052f88d8
commit e3f152983c
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
2 changed files with 5 additions and 1 deletions

View file

@ -24,12 +24,14 @@ pub struct Enum<'a> {
}
pub struct Variant<'a> {
pub original: &'a syn::Variant,
pub attrs: Attrs,
pub ident: Ident,
pub fields: Vec<Field<'a>>,
}
pub struct Field<'a> {
pub original: &'a syn::Field,
pub attrs: Attrs,
pub member: Member,
pub ty: &'a Type,
@ -77,6 +79,7 @@ impl<'a> Enum<'a> {
impl<'a> Variant<'a> {
fn from_syn(node: &'a syn::Variant) -> Result<Self> {
Ok(Variant {
original: node,
attrs: attr::get(&node.attrs)?,
ident: node.ident.clone(),
fields: Field::multiple_from_syn(&node.fields)?,
@ -95,6 +98,7 @@ impl<'a> Field<'a> {
fn from_syn(i: usize, node: &'a syn::Field) -> Result<Self> {
Ok(Field {
original: node,
attrs: attr::get(&node.attrs)?,
member: node
.ident

View file

@ -135,7 +135,7 @@ fn impl_enum(input: Enum) -> Result<TokenStream> {
.map(|(variant, attrs)| {
let display = attrs.display.as_ref().ok_or_else(|| {
Error::new_spanned(
&variant.ident,
variant.original,
"missing #[error(\"...\")] display attribute",
)
})?;