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

Procedural macro crates should require at most one definition per macro name #52225

Closed
alexcrichton opened this Issue Jul 10, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@alexcrichton
Copy link
Member

alexcrichton commented Jul 10, 2018

Discovered by @alercah here, this crate should be rejected:

#![crate_type = "proc-macro"]

extern crate proc_macro;

use proc_macro::TokenStream;

#[proc_macro]
pub fn bad(_ : TokenStream) -> TokenStream { "".parse().unwrap() }

#[proc_macro_derive(bad)]
pub fn deriver(_ : TokenStream) -> TokenStream { "".parse().unwrap() }
@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Jul 10, 2018

I believe this would be fixed by @petrochenkov suggestion here where definition of a macro inserts an entry into the macro namespace, although @petrochenkov correct me if I'm wrong!

@petrochenkov petrochenkov self-assigned this Jul 10, 2018

@petrochenkov

This comment has been minimized.

Copy link
Contributor

petrochenkov commented Jul 10, 2018

#[proc_macro_derive(bad)]

The issue solvable by inserting a dummy entry into macro namespace is not about inert attributes in derives, but about this case.

macro foo() {} // Should be future-proofed and report an error

#[proc_macro]
fn foo(...) -> ... { ... }
@petrochenkov

This comment has been minimized.

Copy link
Contributor

petrochenkov commented Jul 10, 2018

Stabilization PR for proc macro definitions is in process of merge (#52081), so this should be fixed soon too.

@petrochenkov

This comment has been minimized.

Copy link
Contributor

petrochenkov commented Jul 12, 2018

Fixed locally, will submit a PR today.

bors added a commit that referenced this issue Jul 15, 2018

Auto merge of #52383 - petrochenkov:pmns, r=alexcrichton
resolve: Functions introducing procedural macros reserve a slot in the macro namespace as well

Similarly to #52234, this gives us symmetry between internal and external views of a crate, but in this case it's always an error to call a procedural macro in the same crate in which it's defined.

Closes #52225

@bors bors closed this in #52383 Jul 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.