-
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
Tracking issue for the quote!
macro in proc_macro
#54722
Comments
Ah, and this is also tracking the |
We need to avoid EDIT: thinking more about it, I think we should support I don't like We should make sure we error on And maybe we should consider There's also the question of what to do about spans. The For this, we can use an unstable |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Yes please. |
I'm wondering what the reasoning is behind the preference for I ask because as I see it (but without announcing a preference either way), |
@jjpe As I see, there are two main reasons: 1) easier to read (can be picked out at a glance with less difficulty), 2) agrees with long-established convention of backslash escapes (beginning with C I think, but existing in most current languages for strings, including Rust). Furthermore, it will probably be more common to escape |
@alexreg, main advantage of |
@jan-hudec That's not a real advantage to me. There's no additional complexity, when you already have all of those chars in the syntax. And I think the two reasons I gave above are more pertinent. |
is this |
@pnkfelix It's not. See also dtolnay/request-for-implementation#8 (comment). |
I'm kind of confused here: why would we want to pursue adding an inferior solution to the stdlib if a superior one exists as a crate? |
One other difference besides repetitions and (I don't have an opinion about whether proc_macro needs to provide a quote macro, just pointing out one other consideration that has not been brought up yet. It would be nice to fix this before stabilizing something.) |
I see. I struggle to understand why the |
It's accessible in other crates as a library, see also #57288. The
attributes to define proc macros are not.
…On Wed., Jan. 30, 2019, 23:35 Alexander Regueiro ***@***.*** wrote:
I see. I struggle to understand why the proc_macro crate is only
accessible from within proc macro crates though -- it gives rise to what I
see as an unfortunate need for the proc_macro2 crate, and creates a problem
with testing, not to mention the issue @dtolnay
<https://github.com/dtolnay> just pointed out above.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#54722 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AT4HVWZ8uxcYVj2UiLTmrMkWt01HuVWKks5vInKKgaJpZM4XCjad>
.
|
I believe @dtolnay is referring to the fact that the API itself will panic if used outside of the execution of a proc macro by a compiler, because it doesn't contain an implementation of the API, only the logic to talk to a "server" of such an implementation. Some have suggested having a default "server" (loopback, if you will), which behaves just like proc-macro2's polyfills and allows using |
@eddyb Yes, that’s what I’d like to see too. @acrichton thoughts on the above? |
Ah, I see. It surprises me somewhat that all of the implementation is provided by ABI rather than a more detailed in-Rust implementation with less reliance on the ABI. |
@alercah (Sorry for delayed response, I'm clearing out my notifications) If we were to provide an implementation of the With the RPC(-like) approach, a frontend can supply its own implementation, for any particular invocation. |
Is there any progress on this issue? It seems like a good candidate given recent efforts to reduce compile times due to proc macros and extremely complicated inline macros (of which Have we considered making a |
Lang briefly discussed this in backlog bonanza today and we'd like to see a summary of the outstanding blockers or expectations here. I think the thread so far has pointed out:
But it'd be useful to get a summary from folks more familiar on the blockers for stabilization (or removal, if we feel that's better). |
I’ve stumbled upon this interesting case: fn main() {
let expr: syn::Expr = syn::parse_str("2 + 2").unwrap();
let quoted = quote::quote! {
let foo = &#expr;
};
println!("{quoted}"); // & 2 + 2
} I think that’s not ideal (e.g. it differs from UPD: |
Can Looks like it only returns Edit: or, I guess that the nicer long term solution would be to make |
I think proc_macro::quote seems like it has been stable for a while. Rust team, the time has come to stabilize this. |
This comment was marked as spam.
This comment was marked as spam.
I commented this on zulip before, but for visibility: The current impl of the quote! macro in rustc forwards hygiene info from compile time of the proc macro into runtime. This means that this hygiene info has to be embedded into the proc macro and I believe loading a proc macro requires all the compile time dependencies of the proc macro too in case hygiene info originates from them. IMO we should rip out this functionality and just use the same hygiene as would be used when manually creating the token stream. |
Verifying: would that change make proc_macro::quote behave like the one from the crates.io ecosystem ( |
We discussed this in today's @rust-lang/lang meeting. Given the widespread use of What would it take to get |
If #125721 lands |
Assorted things we may want to figure out before stabilization, mostly related to parity with
|
To comment with my rust-analyzer hat on, I'd like it if we could support tracking the def site spans to the concrete tokens somehow (for rust-analyzer at least) in the future. As being able to use go to def and landing within the proc-macro source (where relevant) sounds really neat. So it would be nice if we don't close the doors to that possibility when stabilizing the macro. |
|
Do you want me to change my PR to use |
Rough thought from the lang team meeting: Making I realize that will take away the purported benefit of But maybe that's a sign that we should be pursuing a different syntax, not sure. |
@rustbot labels -I-lang-nominated We talked about this today. There seems to be enthusiasm for making |
Did you mean
I wondered about this, is |
I’d argue that |
So concretely, the hardest blockers seem to be:
At least personally, I consider "feature-parity with the crate" to be a huge "nice-to-have" and something that's easy to use as a block to ever shipping this. We should focus mainly on those that we expect to be essentially impossible to simply tack on later, which will probably include...
|
I'm splitting this off #38356 to track the
quote!
macro specifically contained inproc_macro
. This macro has different syntax than thequote
crate on crates.io but I believe similar functionality. At this time it's not clear (to me at least) what the status of this macro is in terms of how much we actually want to stabilize it or what would block its stabilization. Others are welcome to fill this in though!Steps / History
TokenTree
,TokenKind
, hygienicquote!
, and other API #40939Unresolved questions
$
to match other macros or#
to drop in withquote::quote
? Tracking issue for thequote!
macro inproc_macro
#54722 (comment)quote!
macro inproc_macro
#54722 (comment)From #54722 (comment):
quote::ToTokens
rather than relying onFrom
?The text was updated successfully, but these errors were encountered: