From 08a98b4a65f8d577ab7815e4ca6733781f3a49d9 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Fri, 22 Apr 2016 14:58:17 -0600 Subject: [PATCH 1/3] Add a `lifetime` specifier to `macro_rules!` --- text/0000-macro-lifetimes.md | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 text/0000-macro-lifetimes.md diff --git a/text/0000-macro-lifetimes.md b/text/0000-macro-lifetimes.md new file mode 100644 index 00000000000..91facfb8435 --- /dev/null +++ b/text/0000-macro-lifetimes.md @@ -0,0 +1,49 @@ +- Feature Name: Allow `lifetime` specifiers to be passed to macros +- Start Date: 2016-04-22 +- RFC PR: (leave this empty) +- Rust Issue: (leave this empty) + +# Summary +[summary]: #summary + +Add a `lifetime` specifier for `macro_rules!` patterns, that matches any valid +lifetime. + +# Motivation +[motivation]: #motivation + +Certain classes of macros are completely impossible without the ability to pass +lifetimes. Specifically, anything that wants to implement a trait from inside of +a macro is going to need to deal with lifetimes eventually. They're also +commonly needed for any macros that need to deal with types in a more granular +way than just `ty`. + +Since a lifetime is a single token, there is currently no way to accept one +without an explicit matcher. Something like `'$lifetime:ident` will fail to +compile. + +# Detailed design +[design]: #detailed-design + +This RFC proposes adding `lifetime` as an additional specifier to +`macro_rules!` (alternatively: `life` or `lt`). Since a lifetime acts very much +like an identifier, and can appear in almost as many places, it can be handled +almost identically. A preliminary implementation can be found at +https://github.com/rust-lang/rust/pull/33135 + +# Drawbacks +[drawbacks]: #drawbacks + +None + +# Alternatives +[alternatives]: #alternatives + +A more general specifier, such as a "type parameter list", which would roughly +map to `ast::Generics` would cover most of the cases that matching lifetimes +individually would cover. + +# Unresolved questions +[unresolved]: #unresolved-questions + +None From 942c40ed55af07930ded53a523c5571a74bcdf16 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Sat, 23 Apr 2016 08:49:13 -0600 Subject: [PATCH 2/3] Note that `tt` can be used to match a lifetime --- text/0000-macro-lifetimes.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/text/0000-macro-lifetimes.md b/text/0000-macro-lifetimes.md index 91facfb8435..6b29deb19fa 100644 --- a/text/0000-macro-lifetimes.md +++ b/text/0000-macro-lifetimes.md @@ -18,9 +18,11 @@ a macro is going to need to deal with lifetimes eventually. They're also commonly needed for any macros that need to deal with types in a more granular way than just `ty`. -Since a lifetime is a single token, there is currently no way to accept one -without an explicit matcher. Something like `'$lifetime:ident` will fail to -compile. +Since a lifetime is a single token, the only way to match against a lifetime is +by capturing it as `tt`. Something like `'$lifetime:ident` would fail to +compile. This is extremely limiting, as it becomes difficult to sanitize input, +and `tt` is extremely difficult to use in a sequence without using awkward +separators. # Detailed design [design]: #detailed-design From 17d68e5f0054d1e809c3f9c1ec64fadf64bc9be8 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Wed, 27 Apr 2016 18:13:24 -0600 Subject: [PATCH 3/3] Add an explicit mention of the follow rules for the specifier --- text/0000-macro-lifetimes.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/text/0000-macro-lifetimes.md b/text/0000-macro-lifetimes.md index 6b29deb19fa..0580cd0ab31 100644 --- a/text/0000-macro-lifetimes.md +++ b/text/0000-macro-lifetimes.md @@ -28,9 +28,12 @@ separators. [design]: #detailed-design This RFC proposes adding `lifetime` as an additional specifier to -`macro_rules!` (alternatively: `life` or `lt`). Since a lifetime acts very much +`macro_rules!` (alternatively: `life` or `lt`). As it is a single token, it is +able to be followed by any other specifier. Since a lifetime acts very much like an identifier, and can appear in almost as many places, it can be handled -almost identically. A preliminary implementation can be found at +almost identically. + +A preliminary implementation can be found at https://github.com/rust-lang/rust/pull/33135 # Drawbacks