1

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?

sak
  • 2,612
  • 24
  • 55

1 Answers1

0

spanned method takes Span which is S: MultiSpan you can use any of those functions to get the span

def_site()

call_site()

mixed_site()

You didn't mention your exact code for better elaboration, so hope the above help

You can also check this link

https://doc.rust-lang.org/proc_macro/struct.Span.html#method.call_site