Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add span methods to all item types #49

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/parse_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fn consume_attributes_with_inner(tokens: &mut TokenIter, expect_inner: bool) ->
Some(TokenTree::Punct(punct)) if punct.as_char() == '=' => {
let tk_equals = punct.clone();
attribute_tokens.next();
let value = attribute_tokens.into_iter().collect();
let value = attribute_tokens.collect();
AttributeValue::Equals(tk_equals, value)
}
_ => unreachable!(),
Expand Down
41 changes: 41 additions & 0 deletions src/types_edition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub use crate::types::{
use crate::types::{FnQualifiers, GenericArg, GenericArgList, Impl, Module, Path};
use crate::{Constant, Punctuated, Trait, TyDefinition};
use proc_macro2::{Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
use quote::spanned::Spanned;

impl Declaration {
/// Returns the [`Vec<Attribute>`] of the declaration.
Expand Down Expand Up @@ -723,6 +724,46 @@ impl TyExpr {
}
}

macro_rules! implement_span {
($Kind:ident) => {
impl $Kind {
/// Returns span of this item.
pub fn span(&self) -> Span {
self.__span()
}
}
};
}

implement_span!(Attribute);
implement_span!(AttributeValue);
implement_span!(Declaration);
implement_span!(Enum);
implement_span!(EnumVariant);
implement_span!(EnumVariantValue);
implement_span!(Function);

implement_span!(GenericBound);
implement_span!(GenericParam);
implement_span!(GenericParamList);
implement_span!(NamedField);
implement_span!(Struct);

implement_span!(StructFields);
implement_span!(TupleField);
implement_span!(TyExpr);
implement_span!(Union);
implement_span!(VisMarker);
implement_span!(WhereClause);
implement_span!(WhereClauseItem);

impl InlineGenericArgs<'_> {
/// Returns span of this item.
pub fn span(&self) -> Span {
self.__span()
}
}

impl GroupSpan {
/// Create from proc_macro2 Group.
pub fn new(group: &Group) -> Self {
Expand Down
Loading