mirror of
https://gitee.com/openharmony/third_party_rust_proc-macro2
synced 2024-11-26 17:12:19 +00:00
Consistently use Self in the return of From impls
This commit is contained in:
parent
3915aeedc6
commit
bce0e5f0ab
@ -234,7 +234,7 @@ impl Debug for TokenStream {
|
||||
|
||||
#[cfg(use_proc_macro)]
|
||||
impl From<proc_macro::TokenStream> for TokenStream {
|
||||
fn from(inner: proc_macro::TokenStream) -> TokenStream {
|
||||
fn from(inner: proc_macro::TokenStream) -> Self {
|
||||
inner
|
||||
.to_string()
|
||||
.parse()
|
||||
@ -244,7 +244,7 @@ impl From<proc_macro::TokenStream> for TokenStream {
|
||||
|
||||
#[cfg(use_proc_macro)]
|
||||
impl From<TokenStream> for proc_macro::TokenStream {
|
||||
fn from(inner: TokenStream) -> proc_macro::TokenStream {
|
||||
fn from(inner: TokenStream) -> Self {
|
||||
inner
|
||||
.to_string()
|
||||
.parse()
|
||||
@ -253,7 +253,7 @@ impl From<TokenStream> for proc_macro::TokenStream {
|
||||
}
|
||||
|
||||
impl From<TokenTree> for TokenStream {
|
||||
fn from(tree: TokenTree) -> TokenStream {
|
||||
fn from(tree: TokenTree) -> Self {
|
||||
let mut stream = RcVecBuilder::new();
|
||||
push_token_from_proc_macro(stream.as_mut(), tree);
|
||||
TokenStream {
|
||||
|
12
src/lib.rs
12
src/lib.rs
@ -231,14 +231,14 @@ impl FromStr for TokenStream {
|
||||
|
||||
#[cfg(use_proc_macro)]
|
||||
impl From<proc_macro::TokenStream> for TokenStream {
|
||||
fn from(inner: proc_macro::TokenStream) -> TokenStream {
|
||||
fn from(inner: proc_macro::TokenStream) -> Self {
|
||||
TokenStream::_new(inner.into())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(use_proc_macro)]
|
||||
impl From<TokenStream> for proc_macro::TokenStream {
|
||||
fn from(inner: TokenStream) -> proc_macro::TokenStream {
|
||||
fn from(inner: TokenStream) -> Self {
|
||||
inner.inner.into()
|
||||
}
|
||||
}
|
||||
@ -574,25 +574,25 @@ impl TokenTree {
|
||||
}
|
||||
|
||||
impl From<Group> for TokenTree {
|
||||
fn from(g: Group) -> TokenTree {
|
||||
fn from(g: Group) -> Self {
|
||||
TokenTree::Group(g)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Ident> for TokenTree {
|
||||
fn from(g: Ident) -> TokenTree {
|
||||
fn from(g: Ident) -> Self {
|
||||
TokenTree::Ident(g)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Punct> for TokenTree {
|
||||
fn from(g: Punct) -> TokenTree {
|
||||
fn from(g: Punct) -> Self {
|
||||
TokenTree::Punct(g)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Literal> for TokenTree {
|
||||
fn from(g: Literal) -> TokenTree {
|
||||
fn from(g: Literal) -> Self {
|
||||
TokenTree::Literal(g)
|
||||
}
|
||||
}
|
||||
|
@ -131,13 +131,13 @@ impl Display for TokenStream {
|
||||
}
|
||||
|
||||
impl From<proc_macro::TokenStream> for TokenStream {
|
||||
fn from(inner: proc_macro::TokenStream) -> TokenStream {
|
||||
fn from(inner: proc_macro::TokenStream) -> Self {
|
||||
TokenStream::Compiler(DeferredTokenStream::new(inner))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TokenStream> for proc_macro::TokenStream {
|
||||
fn from(inner: TokenStream) -> proc_macro::TokenStream {
|
||||
fn from(inner: TokenStream) -> Self {
|
||||
match inner {
|
||||
TokenStream::Compiler(inner) => inner.into_token_stream(),
|
||||
TokenStream::Fallback(inner) => inner.to_string().parse().unwrap(),
|
||||
@ -146,7 +146,7 @@ impl From<TokenStream> for proc_macro::TokenStream {
|
||||
}
|
||||
|
||||
impl From<fallback::TokenStream> for TokenStream {
|
||||
fn from(inner: fallback::TokenStream) -> TokenStream {
|
||||
fn from(inner: fallback::TokenStream) -> Self {
|
||||
TokenStream::Fallback(inner)
|
||||
}
|
||||
}
|
||||
@ -170,7 +170,7 @@ fn into_compiler_token(token: TokenTree) -> proc_macro::TokenTree {
|
||||
}
|
||||
|
||||
impl From<TokenTree> for TokenStream {
|
||||
fn from(token: TokenTree) -> TokenStream {
|
||||
fn from(token: TokenTree) -> Self {
|
||||
if inside_proc_macro() {
|
||||
TokenStream::Compiler(DeferredTokenStream::new(into_compiler_token(token).into()))
|
||||
} else {
|
||||
@ -263,13 +263,13 @@ impl LexError {
|
||||
}
|
||||
|
||||
impl From<proc_macro::LexError> for LexError {
|
||||
fn from(e: proc_macro::LexError) -> LexError {
|
||||
fn from(e: proc_macro::LexError) -> Self {
|
||||
LexError::Compiler(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<fallback::LexError> for LexError {
|
||||
fn from(e: fallback::LexError) -> LexError {
|
||||
fn from(e: fallback::LexError) -> Self {
|
||||
LexError::Fallback(e)
|
||||
}
|
||||
}
|
||||
@ -539,13 +539,13 @@ impl Span {
|
||||
}
|
||||
|
||||
impl From<proc_macro::Span> for crate::Span {
|
||||
fn from(proc_span: proc_macro::Span) -> crate::Span {
|
||||
fn from(proc_span: proc_macro::Span) -> Self {
|
||||
crate::Span::_new(Span::Compiler(proc_span))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<fallback::Span> for Span {
|
||||
fn from(inner: fallback::Span) -> Span {
|
||||
fn from(inner: fallback::Span) -> Self {
|
||||
Span::Fallback(inner)
|
||||
}
|
||||
}
|
||||
@ -929,7 +929,7 @@ impl Literal {
|
||||
}
|
||||
|
||||
impl From<fallback::Literal> for Literal {
|
||||
fn from(s: fallback::Literal) -> Literal {
|
||||
fn from(s: fallback::Literal) -> Self {
|
||||
Literal::Fallback(s)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user