Skip to main content

Module restore

Module restore 

Source
Expand description

Puts the input’s own attribute groups back into an expansion that went through syn.

syn writes every delimiter group with one span, so an attribute that survives a parse and a quote! reaches the compiler with its [..] and (..) delimiters collapsed, and an editor can no longer map the attribute’s path to the source it was written at. restore_attrs replaces each surviving #[..] group with the group the input carried, which is the same tokens with their original spans.

A group is matched by its contents with spacing ignored and by its span, which syn keeps from the input as the span of the whole group: an attribute the macro removed, rewrote or generated has no counterpart and is left as built, even where its text equals another attribute’s. Among groups equal in both, which only an input that repeats one source position can carry, source order decides.

Functions§

restore_attrs
output with every #[..] or #![..] group that also appears in input replaced by the input’s group.
restore_item
item written back as tokens, with the attribute groups input carried restored. input is the tokens the macro was given and item what it parsed from them and may have changed; only the item is restored, so an attribute the macro generates around it is not matched.