Closed
Description
The proc_macro::TokenTree
data structure currently look like this.
enum TokenTree {
Group(Group),
Ident(Ident),
Punct(Punct),
Literal(Literal),
}
impl Group {
fn span(&self) -> Span;
}
Every delimited group like (
...)
[
...]
{
...}
has only a single Span
that covers the full source location from opening delimiter to closing delimiter. This makes it impossible for a procedural macro to trigger an error pointing to just the opening or closing delimiter. The Rust compiler does not seem to have the same limitation:
mod m {
type T =
}
error: expected type, found `}`
--> src/main.rs:3:1
|
3 | }
| ^
The best things we can do in a proc macro are point to the last token inside the block, point to the entire block, or point to the next token after the block, none of which is really what you want for an error like above.