Preserve lifetimes on parsed references
diff --git a/syntax/impls.rs b/syntax/impls.rs
index 7b2d746..657fdb3 100644
--- a/syntax/impls.rs
+++ b/syntax/impls.rs
@@ -86,15 +86,17 @@
fn eq(&self, other: &Ref) -> bool {
let Ref {
ampersand: _,
+ lifetime,
mutability,
inner,
} = self;
let Ref {
ampersand: _,
+ lifetime: lifetime2,
mutability: mutability2,
inner: inner2,
} = other;
- mutability.is_some() == mutability2.is_some() && inner == inner2
+ lifetime == lifetime2 && mutability.is_some() == mutability2.is_some() && inner == inner2
}
}
@@ -102,9 +104,11 @@
fn hash<H: Hasher>(&self, state: &mut H) {
let Ref {
ampersand: _,
+ lifetime,
mutability,
inner,
} = self;
+ lifetime.hash(state);
mutability.is_some().hash(state);
inner.hash(state);
}
@@ -186,17 +190,19 @@
fn eq(&self, other: &Receiver) -> bool {
let Receiver {
ampersand: _,
+ lifetime,
mutability,
var: _,
ty,
} = self;
let Receiver {
ampersand: _,
+ lifetime: lifetime2,
mutability: mutability2,
var: _,
ty: ty2,
} = other;
- mutability.is_some() == mutability2.is_some() && ty == ty2
+ lifetime == lifetime2 && mutability.is_some() == mutability2.is_some() && ty == ty2
}
}
@@ -204,10 +210,12 @@
fn hash<H: Hasher>(&self, state: &mut H) {
let Receiver {
ampersand: _,
+ lifetime,
mutability,
var: _,
ty,
} = self;
+ lifetime.hash(state);
mutability.is_some().hash(state);
ty.hash(state);
}
diff --git a/syntax/mod.rs b/syntax/mod.rs
index 3a2bb93..cf811cf 100644
--- a/syntax/mod.rs
+++ b/syntax/mod.rs
@@ -19,7 +19,7 @@
use proc_macro2::{Ident, Span};
use syn::punctuated::Punctuated;
use syn::token::{Brace, Bracket, Paren};
-use syn::{LitStr, Token};
+use syn::{Lifetime, LitStr, Token};
pub use self::atom::Atom;
pub use self::doc::Doc;
@@ -76,6 +76,7 @@
pub struct Receiver {
pub ampersand: Token![&],
+ pub lifetime: Option<Lifetime>,
pub mutability: Option<Token![mut]>,
pub var: Token![self],
pub ty: Ident,
@@ -102,6 +103,7 @@
pub struct Ref {
pub ampersand: Token![&],
+ pub lifetime: Option<Lifetime>,
pub mutability: Option<Token![mut]>,
pub inner: Type,
}
diff --git a/syntax/parse.rs b/syntax/parse.rs
index 8cc4e2a..aed77d8 100644
--- a/syntax/parse.rs
+++ b/syntax/parse.rs
@@ -177,9 +177,10 @@
match arg {
FnArg::Receiver(arg) => {
if let Some(ety) = single_type {
- if let Some((ampersand, _)) = arg.reference {
+ if let Some((ampersand, lifetime)) = &arg.reference {
receiver = Some(Receiver {
- ampersand,
+ ampersand: *ampersand,
+ lifetime: lifetime.clone(),
mutability: arg.mutability,
var: Token),
ty: ety.ident.clone(),
@@ -206,6 +207,7 @@
if let Type::Ident(ident) = reference.inner {
receiver = Some(Receiver {
ampersand: reference.ampersand,
+ lifetime: reference.lifetime,
mutability: reference.mutability,
var: Token),
ty: ident,
@@ -273,6 +275,7 @@
};
Ok(which(Box::new(Ref {
ampersand: ty.and_token,
+ lifetime: ty.lifetime.clone(),
mutability: ty.mutability,
inner,
})))
diff --git a/syntax/tokens.rs b/syntax/tokens.rs
index 08c966a..26bb3d1 100644
--- a/syntax/tokens.rs
+++ b/syntax/tokens.rs
@@ -47,6 +47,7 @@
impl ToTokens for Ref {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.ampersand.to_tokens(tokens);
+ self.lifetime.to_tokens(tokens);
self.mutability.to_tokens(tokens);
self.inner.to_tokens(tokens);
}
@@ -110,6 +111,7 @@
impl ToTokens for ReceiverType<'_> {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.0.ampersand.to_tokens(tokens);
+ self.0.lifetime.to_tokens(tokens);
self.0.mutability.to_tokens(tokens);
self.0.ty.to_tokens(tokens);
}