-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Expand derive macros in the MacroExpander #39442
Conversation
r? @jseyfried |
src/librustc_resolve/macros.rs
Outdated
}, | ||
Err(Determinacy::Undetermined) if force => { | ||
let path: Vec<_> = segments.iter().map(|seg| seg.identifier).collect(); | ||
let msg = format!("derive macro does not exist: '{}'", path[0].name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you just the original path here directly?
Eventually we'll allow e.g. #![derive(foo::bar)]
.
path.segments[0].identifier.name would also work for now, but I see no reason to collect a path: Vec<_>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, how about "cannot find derive macro
{} in this scope"
?
c.f. this error
79db0dc
to
a3d0d48
Compare
src/libsyntax/ext/derive.rs
Outdated
add_derived_markers(cx, attrs); | ||
get_derive_attr(cx, attrs, DeriveType::Builtin) | ||
}).or_else(|| { | ||
get_derive_attr(cx, attrs, DeriveType::ProcMacro) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we switch the order here (i.e. ProcMacro
first, then add_derived_markers
/Builtin
) for back-compat?
Since we want the input of proc macro derives to be fully expanded, we'll want to move in the direction of not including builtin derives, but I'd like to do that all at once with a Crater run.
b94a0c3
to
2c2505e
Compare
So this PR has removed
|
@keeperofdakeys |
2c2505e
to
b117bee
Compare
@bors r+ |
📌 Commit b117bee has been approved by |
…eyfried Expand derive macros in the MacroExpander This removes the expand_derives function, and sprinkles the functionality throughout the Invocation Collector, Expander and Resolver. r? @jseyfried
…eyfried Expand derive macros in the MacroExpander This removes the expand_derives function, and sprinkles the functionality throughout the Invocation Collector, Expander and Resolver. r? @jseyfried
This PR might have resulted in this error during the rollup: https://travis-ci.org/rust-lang/rust/jobs/198341670
|
This allows builtin derives to be registered and resolved, just like other derive types.
This removes the expand_derives function, and sprinkles the functionality throughout the Invocation Collector, Expander and Resolver.
@jseyfried So it looks like travis didn't run the pretty tests, one of which I'm failing (which I've confirmed locally). It involves parsing and pretty printing derive attributes? I'm not sure how the pretty printer is linked to the invocation collector though. Any thoughts? |
Oh I think I understand now. With the The simple fix would be to remove the derives, or change them to builtin variants. Then maybe rename the |
Remove attr-variant-data.rs since it relies on quirks in legacy custom derive resolution (undefined derives only print a warning). Add a new test which uses a defined proc macro derive, and tests pretty printing of proc macro derive attributes.
b117bee
to
a201348
Compare
I deleted the failing test, since it didn't seem to add much after removing the custom derive parts (other tests test custom attributes). I also added a new test using a |
@keeperofdakeys Great, thanks! |
📌 Commit a201348 has been approved by |
…eyfried Expand derive macros in the MacroExpander This removes the expand_derives function, and sprinkles the functionality throughout the Invocation Collector, Expander and Resolver. Fixes rust-lang#39326 r? @jseyfried
[beta] Give a better error message for unknown derive messages This PR improves the error message for unknown derive macros. Currently unknown derives give the following error, which is very misleading: ``` `#[derive]` for custom traits is not stable enough for use. It is deprecated and will be removed in v1.15 (see issue #29644) ``` I'm currently working on a PR that will change this (#39442) to the following: ``` cannot find derive macro `Foo` in this scope ``` This PR backports the (as yet unmerged) error message to beta/1.16 (it's a pity that this is probably too late for 1.15). r? @jseyfried
This removes the expand_derives function, and sprinkles the functionality throughout the Invocation Collector, Expander and Resolver.
Fixes #39326
r? @jseyfried