Skip to content

Empty versions of Span::start and Span::end returned on stable compiler #237

@udoprog

Description

@udoprog

Introduced in #166.

With a stable compiler with the span-locations feature enabled, we now have a situation where Span::start and Span::end reports mocked values (LineColumn { line: 0, column: 0 }) (see code). This is understandable since the underlying function in the compiler is nightly-only behind a feature flag (proc_macro_span and rust-lang/rust#54725), but it was somewhat surprising to me that proc_macro2 falls back to reporting fake spans.

The surprising behavior can be mitigated by documenting in Span::start and Span::end that their values will be mocked on stable compilers until the relevant features are stabilized. But also, downstream projects which for whatever reason rely on accurate spans don't have a great avenue for erroring at compile time in case the compiler version is too old to support them*.

*: Span::unwrap could in principle be used, but would mean that the code no longer can run outside of a proc_macro.

This is also a potential future compatibility hazard if start and end were to be broken out into a separate feature flag (as discussed here) to ease the road towards future stabilization. So I'm tying it together here since I'm looking into if and how it can be done.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions