pub struct Subspan(/* private fields */);Expand description
Turns a byte range of the macro input’s source spelling into a span pointing exactly at those bytes.
This is how string-literal mode stops being
imprecise. proc_macro::Literal::subspan does exactly this job, but it is
unstable (proc_macro_span) and proc_macro2 does not re-export it, so
this crate — which never touches proc_macro — takes it as a hook instead:
cinrs-macros, compiled with its nightly feature, passes one in, and
everything else passes None and keeps the (at line …) suffix.
The range is measured in bytes of the literal as written, r#" prefix,
closing "# and escape sequences and all, which is what subspan wants;
SourceMap does the translation from C-text offsets. Returning None
— which the real subspan does whenever the literal has no source of its
own, as under rust-analyzer — falls back to the whole-literal span.
Results are memoised, because a span is asked for once per generated token and the real implementation is a round trip into the compiler.