Track lifetimes on rust name types
diff --git a/syntax/impls.rs b/syntax/impls.rs
index 4504fe6..8c16f2d 100644
--- a/syntax/impls.rs
+++ b/syntax/impls.rs
@@ -1,5 +1,5 @@
use crate::syntax::{
- Array, ExternFn, Impl, Include, Receiver, Ref, Signature, SliceRef, Ty1, Type, Var,
+ Array, ExternFn, Impl, Include, Lifetimes, Receiver, Ref, Signature, SliceRef, Ty1, Type, Var,
};
use std::borrow::Borrow;
use std::hash::{Hash, Hasher};
@@ -81,6 +81,38 @@
}
}
+impl Eq for Lifetimes {}
+
+impl PartialEq for Lifetimes {
+ fn eq(&self, other: &Lifetimes) -> bool {
+ let Lifetimes {
+ lt_token: _,
+ lifetimes,
+ gt_token: _,
+ } = self;
+ let Lifetimes {
+ lt_token: _,
+ lifetimes: lifetimes2,
+ gt_token: _,
+ } = other;
+ lifetimes.iter().eq(lifetimes2)
+ }
+}
+
+impl Hash for Lifetimes {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ let Lifetimes {
+ lt_token: _,
+ lifetimes,
+ gt_token: _,
+ } = self;
+ lifetimes.len().hash(state);
+ for lifetime in lifetimes {
+ lifetime.hash(state);
+ }
+ }
+}
+
impl Eq for Ty1 {}
impl PartialEq for Ty1 {
diff --git a/syntax/mod.rs b/syntax/mod.rs
index 64ff8e7..6fe45d3 100644
--- a/syntax/mod.rs
+++ b/syntax/mod.rs
@@ -254,7 +254,8 @@
// Wrapper for a type which needs to be resolved before it can be printed in
// C++.
-#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
+#[derive(PartialEq, Eq, Hash)]
pub struct RustName {
pub rust: Ident,
+ pub generics: Lifetimes,
}
diff --git a/syntax/names.rs b/syntax/names.rs
index 51b1341..50f6ebd 100644
--- a/syntax/names.rs
+++ b/syntax/names.rs
@@ -1,6 +1,7 @@
-use crate::syntax::{Pair, RustName, Symbol, Types};
+use crate::syntax::{Lifetimes, Pair, RustName, Symbol, Types};
use proc_macro2::{Ident, Span};
use std::iter;
+use syn::punctuated::Punctuated;
impl Pair {
pub fn to_symbol(&self) -> Symbol {
@@ -23,7 +24,12 @@
impl RustName {
pub fn new(rust: Ident) -> Self {
- RustName { rust }
+ let generics = Lifetimes {
+ lt_token: None,
+ lifetimes: Punctuated::new(),
+ gt_token: None,
+ };
+ RustName { rust, generics }
}
pub fn span(&self) -> Span {
diff --git a/syntax/tokens.rs b/syntax/tokens.rs
index f4478bc..71f77b1 100644
--- a/syntax/tokens.rs
+++ b/syntax/tokens.rs
@@ -256,7 +256,7 @@
impl ToTokens for RustName {
fn to_tokens(&self, tokens: &mut TokenStream) {
- let RustName { rust } = self;
+ let RustName { rust, generics: _ } = self;
rust.to_tokens(tokens);
}
}