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

RFC for allowing macros in all ident positions #215

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions active/0053-ident-macros.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
- Start Date: 2014-08-28
- RFC PR: (leave this empty)
- Rust Issue: (leave this empty)

# Summary

Macros which resolve to idents should be usable in all positions that expect idents, including function/struct/enum names in definitions, et cetera.
Currently they can only be used as variable names.

# Motivation

This will allow for creating better macros which resolve to functions. For example:

```
macro_rules! make_setter(
( $attr:ident ) => (
fn concat_idents!(set_,$attr) (&self) -> u32 {
self.$attr
}
);
)
```

can be created to generate setters just by calling `make_setter(foo)` (which will create `set_foo()`)


Currently, using macros in this manner will lead to errors like

```
test.rs:1:17: 1:18 error: expected `(` but found `!`
test.rs:1 fn concat_idents!(Foo, Bar) () {
^
```

See also: https://github.com/rust-lang/rust/issues/13294

# Detailed design

This will probably require converting [`ast::Ident`](http://doc.rust-lang.org/master/syntax/ast/struct.Ident.html) to an enum allowing for a `NamedIdent` vs `MacroIdent` duality.

# Drawbacks

None that I see

# Alternatives

Suggestions welcome

# Unresolved questions

I'm rather unsure about the implementation.