Skip to content
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

macros 1.1: future proofing and cleanup #37198

Merged
merged 3 commits into from
Oct 19, 2016

Conversation

jseyfried
Copy link
Contributor

@jseyfried jseyfried commented Oct 15, 2016

This PR

  • uses the macro namespace for custom derives (instead of a dedicated custom derive namespace),
  • relaxes the shadowing rules for #[macro_use]-imported custom derives to match the shadowing rules for ordinary #[macro_use]-imported macros, and
  • treats custom derive extern crates like empty modules so that we can eventually allow, for example, extern crate serde_derive; use serde_derive::Serialize; backwards compatibly.

r? @alexcrichton

@jseyfried
Copy link
Contributor Author

cc @nrc

@jseyfried jseyfried force-pushed the future_proof_macros_11 branch 2 times, most recently from f870188 to aac6dca Compare October 15, 2016 22:55
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me but I'm not 100% familiar with all the changes, so

r? @nrc


#![feature(proc_macro)]

#[macro_use]
extern crate derive_a;
#[macro_use]
extern crate derive_a_2; //~ ERROR: cannot shadow existing derive mode `A`
extern crate derive_a; //~ ERROR `derive_a` has already been defined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm isn't this testing something else than before? Before it was preventing two #[proc_macro_derive(A)] was an error, but here it's erroring out on the extern crate annotations?

Copy link
Contributor Author

@jseyfried jseyfried Oct 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it used to test that a #[macro_use]-imported custom derive cannot shadow an existing #[macro_use]-imported custom derive.

This PR changes #[macro_use]-imported custom derives to have the same scope and shadowing restrictions as other #[macro_use]-imported macros, so it is no longer an error for an unexpanded #[macro_use] to import a shadowing custom derive (just as it is not an error today for ordinary unexpanded #[macro_use]s to shadow).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(c.f. the second bullet point in the initial comment)

@alexcrichton alexcrichton assigned nrc and unassigned alexcrichton Oct 16, 2016
@nrc
Copy link
Member

nrc commented Oct 17, 2016

@bors: r+

@bors
Copy link
Contributor

bors commented Oct 17, 2016

📌 Commit aac6dca has been approved by nrc

eddyb added a commit to eddyb/rust that referenced this pull request Oct 19, 2016
…=nrc

macros 1.1: future proofing and cleanup

This PR
 - uses the macro namespace for custom derives (instead of a dedicated custom derive namespace),
 - relaxes the shadowing rules for `#[macro_use]`-imported custom derives to match the shadowing rules for ordinary `#[macro_use]`-imported macros, and
 - treats custom derive `extern crate`s like empty modules so that we can eventually allow, for example, `extern crate serde_derive; use serde_derive::Serialize;` backwards compatibly.

r? @alexcrichton
eddyb added a commit to eddyb/rust that referenced this pull request Oct 19, 2016
…=nrc

macros 1.1: future proofing and cleanup

This PR
 - uses the macro namespace for custom derives (instead of a dedicated custom derive namespace),
 - relaxes the shadowing rules for `#[macro_use]`-imported custom derives to match the shadowing rules for ordinary `#[macro_use]`-imported macros, and
 - treats custom derive `extern crate`s like empty modules so that we can eventually allow, for example, `extern crate serde_derive; use serde_derive::Serialize;` backwards compatibly.

r? @alexcrichton
bors added a commit that referenced this pull request Oct 19, 2016
@bors bors merged commit aac6dca into rust-lang:master Oct 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants