Skip to content

Commit 08a98b4

Browse files
committed
Add a lifetime specifier to macro_rules!
1 parent 43efcc6 commit 08a98b4

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

text/0000-macro-lifetimes.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
- Feature Name: Allow `lifetime` specifiers to be passed to macros
2+
- Start Date: 2016-04-22
3+
- RFC PR: (leave this empty)
4+
- Rust Issue: (leave this empty)
5+
6+
# Summary
7+
[summary]: #summary
8+
9+
Add a `lifetime` specifier for `macro_rules!` patterns, that matches any valid
10+
lifetime.
11+
12+
# Motivation
13+
[motivation]: #motivation
14+
15+
Certain classes of macros are completely impossible without the ability to pass
16+
lifetimes. Specifically, anything that wants to implement a trait from inside of
17+
a macro is going to need to deal with lifetimes eventually. They're also
18+
commonly needed for any macros that need to deal with types in a more granular
19+
way than just `ty`.
20+
21+
Since a lifetime is a single token, there is currently no way to accept one
22+
without an explicit matcher. Something like `'$lifetime:ident` will fail to
23+
compile.
24+
25+
# Detailed design
26+
[design]: #detailed-design
27+
28+
This RFC proposes adding `lifetime` as an additional specifier to
29+
`macro_rules!` (alternatively: `life` or `lt`). Since a lifetime acts very much
30+
like an identifier, and can appear in almost as many places, it can be handled
31+
almost identically. A preliminary implementation can be found at
32+
https://github.com/rust-lang/rust/pull/33135
33+
34+
# Drawbacks
35+
[drawbacks]: #drawbacks
36+
37+
None
38+
39+
# Alternatives
40+
[alternatives]: #alternatives
41+
42+
A more general specifier, such as a "type parameter list", which would roughly
43+
map to `ast::Generics` would cover most of the cases that matching lifetimes
44+
individually would cover.
45+
46+
# Unresolved questions
47+
[unresolved]: #unresolved-questions
48+
49+
None

0 commit comments

Comments
 (0)