diff options
author | David Tolnay <dtolnay@gmail.com> | 2021-03-27 01:46:01 -0400 |
---|---|---|
committer | David Tolnay <dtolnay@gmail.com> | 2021-03-27 01:51:08 -0400 |
commit | 9dab9d8e3859d03a0b1c7fd1a60b0eb38eeea411 (patch) | |
tree | 4c3584b12f072ed5f080e20176b6b70ac6d1ec98 | |
parent | eb55cee41e23109283f87dd1100ca044b1ab2693 (diff) | |
download | cxx-9dab9d8e3859d03a0b1c7fd1a60b0eb38eeea411.tar.gz |
Track the outer type's spans too for implicit impls
-rw-r--r-- | syntax/instantiate.rs | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/syntax/instantiate.rs b/syntax/instantiate.rs index c2a5af0c..b6cbf24b 100644 --- a/syntax/instantiate.rs +++ b/syntax/instantiate.rs @@ -1,5 +1,5 @@ -use crate::syntax::{NamedType, Type}; -use proc_macro2::Ident; +use crate::syntax::{NamedType, Ty1, Type}; +use proc_macro2::{Ident, Span}; use std::hash::{Hash, Hasher}; use syn::Token; @@ -15,36 +15,38 @@ pub enum ImplKey<'a> { #[derive(Copy, Clone)] pub struct NamedImplKey<'a> { + pub begin_span: Span, pub rust: &'a Ident, pub lt_token: Option<Token![<]>, pub gt_token: Option<Token![>]>, + pub end_span: Span, } impl Type { pub(crate) fn impl_key(&self) -> Option<ImplKey> { if let Type::RustBox(ty) = self { if let Type::Ident(ident) = &ty.inner { - return Some(ImplKey::RustBox(NamedImplKey::from(ident))); + return Some(ImplKey::RustBox(NamedImplKey::new(ty, ident))); } } else if let Type::RustVec(ty) = self { if let Type::Ident(ident) = &ty.inner { - return Some(ImplKey::RustVec(NamedImplKey::from(ident))); + return Some(ImplKey::RustVec(NamedImplKey::new(ty, ident))); } } else if let Type::UniquePtr(ty) = self { if let Type::Ident(ident) = &ty.inner { - return Some(ImplKey::UniquePtr(NamedImplKey::from(ident))); + return Some(ImplKey::UniquePtr(NamedImplKey::new(ty, ident))); } } else if let Type::SharedPtr(ty) = self { if let Type::Ident(ident) = &ty.inner { - return Some(ImplKey::SharedPtr(NamedImplKey::from(ident))); + return Some(ImplKey::SharedPtr(NamedImplKey::new(ty, ident))); } } else if let Type::WeakPtr(ty) = self { if let Type::Ident(ident) = &ty.inner { - return Some(ImplKey::WeakPtr(NamedImplKey::from(ident))); + return Some(ImplKey::WeakPtr(NamedImplKey::new(ty, ident))); } } else if let Type::CxxVector(ty) = self { if let Type::Ident(ident) = &ty.inner { - return Some(ImplKey::CxxVector(NamedImplKey::from(ident))); + return Some(ImplKey::CxxVector(NamedImplKey::new(ty, ident))); } } None @@ -65,12 +67,14 @@ impl<'a> Hash for NamedImplKey<'a> { } } -impl<'a> From<&'a NamedType> for NamedImplKey<'a> { - fn from(ty: &'a NamedType) -> Self { +impl<'a> NamedImplKey<'a> { + fn new(outer: &Ty1, inner: &'a NamedType) -> Self { NamedImplKey { - rust: &ty.rust, - lt_token: ty.generics.lt_token, - gt_token: ty.generics.gt_token, + begin_span: outer.name.span(), + rust: &inner.rust, + lt_token: inner.generics.lt_token, + gt_token: inner.generics.gt_token, + end_span: outer.rangle.span, } } } |