I am working on a procedural macro which implements a small DSL. Currently I am attempting to implement diagnostics-based error reporting, so that I can provide high quality feedback in the IDE setting.
My overall approach is to use the Diagnostic
API of the proc-macro-error
crate to create diagnostics.
This API should allow me to emit localized errors like so:
Diagnostic::spanned(span, Level::Error, text).emit();
The problem is, the spanned
method takes a proc_macro2::Span
as an argument, a struct which has no constructor available.
Based on the nature of the DSL, it is not possible for me to use any Span
from the input TokenStream
.
How can I create a Span
for use in this diagnostic?