-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stabilize Span::mixed_site
#68716
Stabilize Span::mixed_site
#68716
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Stabilization reportThis PR stabilizes a proc macro API Tracking issue: #65049 Technical specificationProcedural macro producing tokens with MotivationProc macros do not have direct access to our oldest and most stable hygiene kind - To emulate it macro authors have to go through two steps - first generate a temporary I'd say that these workarounds with nested macro definitions have more chances to hit some corner cases in our hygiene system, in which we don't have full confidence. This API addition opens the way to stabilizing proc macros in expression, pattern and statement positions (#68717), for which use of call-site hygiene or workarounds with temporary items would be quite unfortunate. Tests
HistoryThe implementation (#64690) was merged about 4 months ago. |
r? @dtolnay |
One thing I'm wondering about here is the documentation ("how do we teach this") aspect and making it easy to "do the right thing" wrt. hygiene in expr/pat/stmt contexts. Hygiene is, in my experience, one of the less well known parts of the language and so it seems like this could be easy to get wrong without good teaching material. In the implementation PR, @dtolnay noted (#64690 (comment)) that:
I'm wondering if more thought has been put into this. @CAD97 did note in #64690 (comment) that changing to |
@Centril The recommendation on using I don't understand why the @CAD97's example would be broken, it doesn't seem to involve local variables. |
The teams should, in my view, still be interested in the wider ecosystem effects with respect to #68717 and not just the narrow technical aspect of Specifically, I'm somewhat concerned that the recommendation won't be heeded by many due to the relative ergonomics of |
I would be interested in a crater run that changes proc_macro::Span::call_site() to call mixed_site(), as a way to mimic what would happen from replacing quote's default. I agree with #68716 (comment) that I don't understand why the example given in the other PR would break.
|
A crater run sounds like a great idea. 👍 (I'm skeptical of |
#68766 is the PR doing that. |
#68766 (comment) has the experiment results. I haven't looked into the regressions too closely, but it seems a large variety of derive macros and attribute macros no longer work. That suggests to me mixed_site may not be a reasonable default and that it should be reserved as a power tool. But I intend to take a closer look at what particular patterns exhibit different behavior (and I could use all of your help with this). It is interesting that serde_derive seems completely fine using mixed_site everywhere. |
I'm also interested in finding out the root regressions and patterns that they represent. |
proc_macro: Stabilize `Span::resolved_at` and `Span::located_at` Introduced in rust-lang#47149. Part of rust-lang#54725. Motivation: rust-lang#68716 (comment). Identifiers in proc macros may want to inherit span locations for diagnostics from one tokens (e.g. some tokens from the macro input), but resolve those identifiers from some different location (e.g. from the macro's definition site). This becomes especially important when multiple resolution locations become available with stabilization of [`Span::mixed_site`](rust-lang#68716). Why I think this is the right API for setting span's location and hygiene - rust-lang#69041 (comment). r? @dtolnay
ping @dtolnay, this is unblocked and needs an official r+. |
@bors r+ |
📌 Commit f5223a3 has been approved by |
Rollup of 6 pull requests Successful merges: - rust-lang#68716 (Stabilize `Span::mixed_site`) - rust-lang#71263 (Remove unused abs_path method from rustc_span::source_map::FileLoader) - rust-lang#71409 (Point at the return type on `.into()` failure caused by `?`) - rust-lang#71419 (add message for resolution failure because wrong namespace) - rust-lang#71438 (Tweak some suggestions in `rustc_resolve`) - rust-lang#71589 (remove Unique::from for shared pointer types) Failed merges: r? @ghost
Fixes dtolnay#210 This was stabilized in Rust in rust-lang/rust#68716
Stabilize fn-like proc macros in expression, pattern and statement positions I.e. all the positions in which stable `macro_rules` macros are supported. Depends on rust-lang#68716 ("Stabilize `Span::mixed_site`"). cc rust-lang#54727 cc rust-lang#54727 (comment) Stabilization report: rust-lang#68717 (comment).
Stabilize fn-like proc macros in expression, pattern and statement positions I.e. all the positions in which stable `macro_rules` macros are supported. Depends on rust-lang/rust#68716 ("Stabilize `Span::mixed_site`"). cc rust-lang/rust#54727 cc rust-lang/rust#54727 (comment) Stabilization report: rust-lang/rust#68717 (comment).
Fixes dtolnay#210 This was stabilized in Rust in rust-lang/rust#68716
Stabilize fn-like proc macros in expression, pattern and statement positions I.e. all the positions in which stable `macro_rules` macros are supported. Depends on rust-lang/rust#68716 ("Stabilize `Span::mixed_site`"). cc rust-lang/rust#54727 cc rust-lang/rust#54727 (comment) Stabilization report: rust-lang/rust#68717 (comment).
Fixes #210 This was stabilized in Rust in rust-lang/rust#68716
Closes #65049.
cc #54727 (comment)
Pre-requisite for #68717 ("Stabilize fn-like proc macros in expression, pattern and statement positions").
Stabilization report: #68716 (comment).