mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2024-11-23 07:10:29 +00:00
Track the outer type's spans too for implicit impls
This commit is contained in:
parent
eb55cee41e
commit
9dab9d8e38
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user