Add Span::mixed_site, Span::resolved_at, and Span::located_at behind hygiene feature#228
Add Span::mixed_site, Span::resolved_at, and Span::located_at behind hygiene feature#228dtolnay merged 2 commits intodtolnay:masterfrom
Span::mixed_site, Span::resolved_at, and Span::located_at behind hygiene feature#228Conversation
src/lib.rs
Outdated
| /// The span located at the invocation of the procedural macro, but with | ||
| /// local variables, labels, and `$crate` resolved at the definition site | ||
| /// of the macro. | ||
| /// | ||
| /// `macro_rules` behaves like this in terms of hygiene. |
There was a problem hiding this comment.
This is a rephrasing of the proc_macro::Span::mixed_site() documentation, but I was unable to get $crate to work in a proc macro -- it just errors with "expected identifier, found $". Do you know if that is expected to work, or is that referring only to macro_rules?
|
Would it be possible to avoid the need to opt-in with a feature? Perhaps these APIs could be unconditionally defined on appropriate rustc versions and beyond? |
dtolnay
left a comment
There was a problem hiding this comment.
Agreed with Alex; there shouldn't be a feature gate on these.
Additionally, it would be better to expose resolved_at and located_at unconditionally and have it return the span associated with the name resolution behavior (as opposed to the line/column information, which is cosmetic) when the compiler doesn't support the underlying API. This way they can be adopted more readily by downstream code.
Fixes dtolnay#210 This was stabilized in Rust in rust-lang/rust#68716
On compilers prior to 1.45 where this is not stable, these fall back to returning the span associated with resolution behavior, since the source location is only cosmetic. This is a reversal of the previous fallback implementation, which preserved source location because it does not track resolution location. The differnce is only observable with `span_locations` enabled. These methods were stabilized in Rust in rust-lang/rust#69041
This adds support for hygiene-related APIs recently stabilized for Rust 1.45 (currently nightly).
mixed_sitewas stabilized in StabilizeSpan::mixed_siterust-lang/rust#68716.resolved_atandlocated_atwere stabilized in proc_macro: StabilizeSpan::resolved_atandSpan::located_atrust-lang/rust#69041The Cargo feature is named following the overarching
proc_macro_hygienelanguage feature also about to be stabilized, which itself doesn't add any API surface forproc_macro2.Closes #210