Hide confusing apostrophe struct
diff --git a/src/lifetime.rs b/src/lifetime.rs
index e62d6d0..2df7ca8 100644
--- a/src/lifetime.rs
+++ b/src/lifetime.rs
@@ -15,7 +15,6 @@
#[cfg(feature = "parsing")]
use lookahead;
-use token::Apostrophe;
/// A Rust lifetime: `'a`.
///
@@ -33,7 +32,7 @@
#[cfg_attr(feature = "extra-traits", derive(Debug))]
#[derive(Clone)]
pub struct Lifetime {
- pub apostrophe: Apostrophe,
+ pub apostrophe: Span,
pub ident: Ident,
}
@@ -69,7 +68,7 @@
}
Lifetime {
- apostrophe: Apostrophe::default(),
+ apostrophe: Span::call_site(),
ident: Ident::new(&s[1..], span),
}
}
@@ -119,18 +118,22 @@
pub mod parsing {
use super::*;
+ use proc_macro2::Spacing;
+
use ext::IdentExt;
- use parse::{Error, Parse, ParseStream, Result};
+ use parse::{Parse, ParseStream, Result};
impl Parse for Lifetime {
fn parse(input: ParseStream) -> Result<Self> {
Ok(Lifetime {
- apostrophe: match input.parse() {
- Ok(apostrophe) => apostrophe,
- Err(err) => {
- return Err(Error::new(err.span(), "expected lifetime"));
+ apostrophe: input.step(|cursor| {
+ if let Some((punct, rest)) = cursor.punct() {
+ if punct.as_char() == '\'' && punct.spacing() == Spacing::Joint {
+ return Ok((punct.span(), rest));
+ }
}
- },
+ Err(cursor.error("expected lifetime"))
+ })?,
ident: input.call(Ident::parse_any)?,
})
}
@@ -140,12 +143,15 @@
#[cfg(feature = "printing")]
mod printing {
use super::*;
- use proc_macro2::TokenStream;
- use quote::ToTokens;
+
+ use proc_macro2::{Punct, Spacing, TokenStream};
+ use quote::{ToTokens, TokenStreamExt};
impl ToTokens for Lifetime {
fn to_tokens(&self, tokens: &mut TokenStream) {
- self.apostrophe.to_tokens(tokens);
+ let mut apostrophe = Punct::new('\'', Spacing::Joint);
+ apostrophe.set_span(self.apostrophe);
+ tokens.append(apostrophe);
self.ident.to_tokens(tokens);
}
}
diff --git a/src/token.rs b/src/token.rs
index 0d33839..4db039a 100644
--- a/src/token.rs
+++ b/src/token.rs
@@ -105,11 +105,9 @@
#[cfg(feature = "parsing")]
use proc_macro2::Delimiter;
-#[cfg(any(feature = "printing", feature = "parsing"))]
-use proc_macro2::Spacing;
-use proc_macro2::{Ident, Span};
#[cfg(feature = "printing")]
-use proc_macro2::{Punct, TokenStream};
+use proc_macro2::TokenStream;
+use proc_macro2::{Ident, Span};
#[cfg(feature = "printing")]
use quote::{ToTokens, TokenStreamExt};
@@ -400,41 +398,9 @@
}
define_punctuation_structs! {
- "'" pub struct Apostrophe/1 /// `'`
"_" pub struct Underscore/1 /// `_`
}
-// Implement Clone anyway because it is required for cloning Lifetime.
-#[cfg(not(feature = "clone-impls"))]
-impl Clone for Apostrophe {
- fn clone(&self) -> Self {
- Apostrophe(self.spans)
- }
-}
-
-#[cfg(feature = "printing")]
-impl ToTokens for Apostrophe {
- fn to_tokens(&self, tokens: &mut TokenStream) {
- let mut token = Punct::new('\'', Spacing::Joint);
- token.set_span(self.spans[0]);
- tokens.append(token);
- }
-}
-
-#[cfg(feature = "parsing")]
-impl Parse for Apostrophe {
- fn parse(input: ParseStream) -> Result<Self> {
- input.step(|cursor| {
- if let Some((punct, rest)) = cursor.punct() {
- if punct.as_char() == '\'' && punct.spacing() == Spacing::Joint {
- return Ok((Apostrophe(punct.span()), rest));
- }
- }
- Err(cursor.error("expected `'`"))
- })
- }
-}
-
#[cfg(feature = "printing")]
impl ToTokens for Underscore {
fn to_tokens(&self, tokens: &mut TokenStream) {