-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add a lifetime
specifier to macro_rules!
#1590
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
- 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, 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 | ||
|
||
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lt
might be confused with 'literal
', if it were ever added.Also, perhaps these other names could be moved to the
# Alternatives
section?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are differing names an alternative to the RFC? Seems like it's a detail of the RFC itself. And yeah, I'm strongly in favor of
lifetime
as the nameThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the long word
lifetime
seems good. I don't see a reason to save letters here.