Stream: t-compiler/rust-analyzer

Topic: Proc macro expansion


Lukas Wirth (Apr 10 2021 at 17:19, on Zulip):

Is it expected that for a proc macro with this call bevy_ecs_macros::all_tuples! {impl_tuple_fetch, 0, 1, F, A }, that the proc macro receives the following TokenStream?

TokenStream [Group { delimiter: Brace, stream: TokenStream [Ident { ident: "impl_tuple_fetch", span: 4294967295 }, Punct { ch: ',', spacing: Alone, span: 4294967295 }, Literal { kind: , symbol: "0", suffix: None, span: 3 }, Punct { ch: ',', spacing: Alone, span: 4294967295 }, Literal { kind: , symbol: "1", suffix: None, span: 5 }, Punct { ch: ',', spacing: Alone, span: 4294967295 }, Ident { ident: "F", span: 4294967295 }, Punct { ch: ',', spacing: Alone, span: 4294967295 }, Ident { ident: "A", span: 4294967295 }], span: 0 }]

Note the delimiter grouping at the start

Lukas Wirth (Apr 10 2021 at 17:20, on Zulip):

Been trying out bevy wondering why a lot of inference doesnt work and it seems that this proc macro doesnt expand(it emits compile_error which we also dont emit a diagnostic for) saying it expects an ident.

Jonas Schievink [he/him] (Apr 10 2021 at 17:21, on Zulip):

hmm, do we strip the outer group when you invoke it with ();?

Lukas Wirth (Apr 10 2021 at 17:22, on Zulip):

Nope, still contains the delimiters

Lukas Wirth (Apr 10 2021 at 17:22, on Zulip):

Also when called with [];

Lukas Wirth (Apr 10 2021 at 17:24, on Zulip):

Wouldn't mind looking into this some more but in that case I need some pointers where to look since I'm not into macro stuff in RA

Lukas Wirth (Apr 10 2021 at 17:46, on Zulip):

Okay I think the problem is in this PR https://github.com/rust-analyzer/rust-analyzer/pull/8443, commit prior to this works fine

Jonas Schievink [he/him] (Apr 10 2021 at 17:48, on Zulip):

oh, seems like the old code removed the outer group, but that's not documented anywhere

Jonas Schievink [he/him] (Apr 10 2021 at 17:48, on Zulip):

"remove derives" is not something that should happen for fn-like macros, but we do need to do that part

Lukas Wirth (Apr 10 2021 at 17:57, on Zulip):

TokenBuffer stripped the outer grouping before then I suppose?

Jonas Schievink [he/him] (Apr 10 2021 at 18:00, on Zulip):

yeah: TokenBuffer::from_tokens(&tt.token_trees);

Jonas Schievink [he/him] (Apr 10 2021 at 18:01, on Zulip):

disposes tt.delimiter

Jonas Schievink [he/him] (Apr 10 2021 at 18:01, on Zulip):

and let mut result = tt::Subtree::default(); creates a subtree without delimiter

Jonas Schievink [he/him] (Apr 10 2021 at 18:01, on Zulip):

I'm thinking we might want to revert that PR because it's also otherwise broken

Jonas Schievink [he/him] (Apr 10 2021 at 18:04, on Zulip):

does this make github unhappy or is that just me? https://github.com/rust-analyzer/rust-analyzer/pull/8443/revert

Lukas Wirth (Apr 10 2021 at 18:04, on Zulip):

Unhappy in what sense?

Lukas Wirth (Apr 10 2021 at 18:05, on Zulip):

opening that just redirects me to the PR without the revert part

Lukas Wirth (Apr 10 2021 at 18:05, on Zulip):

Oh clicking the revert button server errors, I guess that's what you mean :laughing:

Jonas Schievink [he/him] (Apr 10 2021 at 18:10, on Zulip):

ah, yeah

Jonas Schievink [he/him] (Apr 10 2021 at 18:46, on Zulip):

reverted it

Last update: Jul 26 2021 at 12:00UTC