Rust alternative to the #line directive?


#1

Hi there!

While debugging a macro_derive’d impl of a trait, I’ve been hit by this somewhat unhelpful error:

18 | #[derive(Debug, Template)]
   |                 ^^^^^^^^ cannot move out of borrowed content

The issue is, of course, that Template generates an impl with an error. This particular derive is from askama, which generates an impl based on my own template file.

In C, source generators would pepper the generated code with #line directives, so that the compiler would display the actual line that led to the generation of invalid code.

Is there an equivalent for Rust?


#2

Alright, should’ve dug deeper before writing.

Also, looking at the definition in proc_macro, it seems that providing span information is also not possible at the moment in procedural macros.