diff --git a/impl/src/ast.rs b/impl/src/ast.rs index 7d074a0..a56b358 100644 --- a/impl/src/ast.rs +++ b/impl/src/ast.rs @@ -68,8 +68,7 @@ impl<'a> Struct<'a> { fn from_syn(node: &'a DeriveInput, data: &'a DataStruct) -> Result { let mut attrs = attr::get(&node.attrs)?; let scope = ParamsInScope::new(&node.generics); - let span = attrs.span().unwrap_or_else(Span::call_site); - let fields = Field::multiple_from_syn(&data.fields, &scope, span)?; + let fields = Field::multiple_from_syn(&data.fields, &scope)?; if let Some(display) = &mut attrs.display { let container = ContainerKind::from_struct(data); display.expand_shorthand(&fields, container)?; @@ -87,12 +86,11 @@ impl<'a> Enum<'a> { fn from_syn(node: &'a DeriveInput, data: &'a DataEnum) -> Result { let attrs = attr::get(&node.attrs)?; let scope = ParamsInScope::new(&node.generics); - let span = attrs.span().unwrap_or_else(Span::call_site); let variants = data .variants .iter() .map(|node| { - let mut variant = Variant::from_syn(node, &scope, span)?; + let mut variant = Variant::from_syn(node, &scope)?; if let display @ None = &mut variant.attrs.display { display.clone_from(&attrs.display); } @@ -115,37 +113,27 @@ impl<'a> Enum<'a> { } impl<'a> Variant<'a> { - fn from_syn(node: &'a syn::Variant, scope: &ParamsInScope<'a>, span: Span) -> Result { + fn from_syn(node: &'a syn::Variant, scope: &ParamsInScope<'a>) -> Result { let attrs = attr::get(&node.attrs)?; - let span = attrs.span().unwrap_or(span); Ok(Variant { original: node, attrs, ident: node.ident.clone(), - fields: Field::multiple_from_syn(&node.fields, scope, span)?, + fields: Field::multiple_from_syn(&node.fields, scope)?, }) } } impl<'a> Field<'a> { - fn multiple_from_syn( - fields: &'a Fields, - scope: &ParamsInScope<'a>, - span: Span, - ) -> Result> { + fn multiple_from_syn(fields: &'a Fields, scope: &ParamsInScope<'a>) -> Result> { fields .iter() .enumerate() - .map(|(i, field)| Field::from_syn(i, field, scope, span)) + .map(|(i, field)| Field::from_syn(i, field, scope)) .collect() } - fn from_syn( - i: usize, - node: &'a syn::Field, - scope: &ParamsInScope<'a>, - span: Span, - ) -> Result { + fn from_syn(i: usize, node: &'a syn::Field, scope: &ParamsInScope<'a>) -> Result { Ok(Field { original: node, attrs: attr::get(&node.attrs)?, @@ -153,7 +141,7 @@ impl<'a> Field<'a> { Some(name) => MemberUnraw::Named(IdentUnraw::new(name.clone())), None => MemberUnraw::Unnamed(Index { index: i as u32, - span, + span: Span::call_site(), }), }, ty: &node.ty, @@ -192,15 +180,3 @@ impl Display for ContainerKind { }) } } - -impl Attrs<'_> { - pub fn span(&self) -> Option { - if let Some(display) = &self.display { - Some(display.fmt.span()) - } else if let Some(transparent) = &self.transparent { - Some(transparent.span) - } else { - None - } - } -}