serde_derive/internals/
respan.rs

1use proc_macro2::{Group, Span, TokenStream, TokenTree};
2
3pub(crate) fn respan(stream: TokenStream, span: Span) -> TokenStream {
4    stream
5        .into_iter()
6        .map(|token| respan_token(token, span))
7        .collect()
8}
9
10fn respan_token(mut token: TokenTree, span: Span) -> TokenTree {
11    if let TokenTree::Group(g) = &mut token {
12        *g = Group::new(g.delimiter(), respan(g.stream(), span));
13    }
14    token.set_span(span);
15    token
16}