Define line number and filename e.g. for generated files (#line directive)


#1

Is the #line directive in any way available in Rust?

C/C++ preprocessors have it, for example (see http://www.cplusplus.com/doc/tutorial/preprocessor/), which is very helpful to create nice error messages for generated code. It can be used to show the erroneous line and filename of the original template instead of the position in the generated file.


Rust alternative to the #line directive?
#2

The line!() macro.


#3

There’s a misunderstanding, I want to set the line number (and filename), not retrieve it. Or for C++ devs, #line instead of __LINE__/__FILE__.


#4

There isn’t any equivalent at the moment; I don’t think anyone has even proposed a design.


#5

Oh. Sorry, I should learn to read…


#6

Syntax extensions can alter with spans in this way but things like macro_rules! macros cannot.