Implement function-like procedural macros ( #[proc_macro])#40129
Implement function-like procedural macros ( #[proc_macro])#40129bors merged 1 commit intorust-lang:masterfrom
#[proc_macro])#40129Conversation
|
Unanswered question: did we decide whether or not to include the outer delimiters from the invocation in the input? i.e. |
There was a problem hiding this comment.
I'm on the fence about reusing the typedef. I didn't see much point to having a unique type with the same signature.
There was a problem hiding this comment.
This might fail the test because the wrapping delimiters might get included. I forget what the executive decision was on whether or not to include those.
There was a problem hiding this comment.
Nope, works as-is.
#[proc_macro])#[proc_macro])
bdbadad to
fcebcf4
Compare
Looks like I didn't have to do any extra work to support that as-is, very nice. |
There was a problem hiding this comment.
Formatting suggestion welcome here.
There was a problem hiding this comment.
Should be indented three spaces (to align with first condition) or eight spaces (to distinguish from body).
There was a problem hiding this comment.
Eh, I don't really like how either of those look so it's your call. I would almost prefer a .check_names() method which can take a slice or iterator or something.
There was a problem hiding this comment.
In this case I'd write:
if PROC_MACRO_KINDS.iter().any(|kind| attr.check_name(kind)) { ... }where
const PROC_MACRO_KINDS: [&'static str, 3] =
["proc_macro", "proc_macro_attribute", "proc_macro_derive"];There was a problem hiding this comment.
Sounds good. I might use the static-in-const feature to make that a little shorter too.
src/libproc_macro/lib.rs
Outdated
There was a problem hiding this comment.
Bikeshed: "fnlike" instead of "bang"?
There was a problem hiding this comment.
I prefer Bang inside the compiler to avoid overloading "function". Also, we might want to use "proc macro function" for the underlying function item annotated with #[proc_macro*].
There was a problem hiding this comment.
Also, we might want to use "proc macro function" for the underlying function item annotated with #[proc_macro*].
Clarify?
There was a problem hiding this comment.
For #[proc_macro_derive(A)] fn f(..) { .. }, we would say A is a [derive] proc macro and f is the [derive] proc macro function.
There was a problem hiding this comment.
Okay. That doesn't affect anything in this PR, though, right? That's purely wording for documentation and stuff?
There was a problem hiding this comment.
Yeah, it's just an argument for "bang proc macro" instead of "function / fnlike procedural macro".
c7035cb to
e7f258e
Compare
src/libsyntax/feature_gate.rs
Outdated
There was a problem hiding this comment.
nit: These should be indented to the same column as Stability::Unstable,.
src/libsyntax_ext/proc_macro_impl.rs
Outdated
There was a problem hiding this comment.
It would be nice to factor this out to avoid duplication across macro kinds (not needed for this PR though).
There was a problem hiding this comment.
nit: I would break after the = or give each macro kind its own line.
|
@abonander Looks great! What happens when we |
|
I'll have to test that, I think we're only checking that in the attribute proc macro codepath. |
|
Only supporting @abonander Nice. Maybe you'd like to add a misspelled call for a proc macro to this test, so we can test suggestions? They should be working, but it would be good to make sure. |
|
Yeah |
There was a problem hiding this comment.
We don't. I copy-pasted this from another file to get the copyright and stuff and I must have forgotten to remove that.
|
@abonander Awesome, thanks. |
489cd50 to
1be0a59
Compare
|
@jseyfried Last nits fixed and rebased. |
There was a problem hiding this comment.
"meta item" is compiler jargon -- I'd say "does not accept arguments" (also applies to proc_macro_attribute).
|
r=me modulo comments |
|
✌️ @abonander can now approve this pull request |
1be0a59 to
2fcbb48
Compare
|
@bors r=jseyfried |
|
📌 Commit 2fcbb48 has been approved by |
Implement function-like procedural macros ( `#[proc_macro]`) Adds the `#[proc_macro]` attribute, which expects bare functions of the kind `fn(TokenStream) -> TokenStream`, which can be invoked like `my_macro!()`. cc rust-lang/rfcs#1913, rust-lang#38356 r? @jseyfried cc @nrc
Implement function-like procedural macros ( `#[proc_macro]`) Adds the `#[proc_macro]` attribute, which expects bare functions of the kind `fn(TokenStream) -> TokenStream`, which can be invoked like `my_macro!()`. cc rust-lang/rfcs#1913, rust-lang#38356 r? @jseyfried cc @nrc
Implement function-like procedural macros ( `#[proc_macro]`) Adds the `#[proc_macro]` attribute, which expects bare functions of the kind `fn(TokenStream) -> TokenStream`, which can be invoked like `my_macro!()`. cc rust-lang/rfcs#1913, rust-lang#38356 r? @jseyfried cc @nrc
Adds the
#[proc_macro]attribute, which expects bare functions of the kindfn(TokenStream) -> TokenStream, which can be invoked likemy_macro!().cc rust-lang/rfcs#1913, #38356
r? @jseyfried
cc @nrc