mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-23 11:48:00 +00:00
Fix handling of Self keyword in type definition
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
use proc_macro2::{Span, TokenStream};
|
||||
use quote::ToTokens;
|
||||
use syn::parse::Parse;
|
||||
|
||||
pub(crate) fn respan<T>(node: &T, span: Span) -> T
|
||||
where
|
||||
T: ToTokens + Parse,
|
||||
{
|
||||
let tokens = node.to_token_stream();
|
||||
let respanned = respan_tokens(tokens, span);
|
||||
syn::parse2(respanned).unwrap()
|
||||
}
|
||||
|
||||
fn respan_tokens(tokens: TokenStream, span: Span) -> TokenStream {
|
||||
tokens
|
||||
.into_iter()
|
||||
.map(|mut token| {
|
||||
token.set_span(span);
|
||||
token
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
Reference in New Issue
Block a user