Skip to content

Is it possible to pass a span to compile_error! #44535

Closed
@chancancode

Description

@chancancode

I noticed that this question from @Stebalien was left unaddressed in the compile_error! RFC:

Is the span information not attached to the tokens passed to a macro? I'd like to be able point out which token in the macro input caused the macro expansion to fail (and why).

Before compile_error! was a thing, I generally report errors to the user (where possible) by passing the offending token to a "sink" macro that has no possible matches, which would cause the compiler to report no rule expected the token <token> with the right span. It is nice that now I can specify a useful message, however we lost the ability to point the error back to the right span. It is unfortunate to have to make this trade-off (either providing the right span without telling you why, or telling you why without reporting where), and in some scenario neither of the two options on their own would be sufficient to understand the error (it could be a very generic error that could happen in a lot of places – think "missing a semicolon" or "unbalanced braces" kind of errors).

cc @sgrif

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions