Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd a `lifetime` specifier to `macro_rules!` #1590
Conversation
sgrif
referenced this pull request
Apr 22, 2016
Closed
Allow lifetimes to be passed to macros #33135
bluss
reviewed
Apr 23, 2016
|
|
||
| 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. |
This comment has been minimized.
This comment has been minimized.
bluss
Apr 23, 2016
lifetime tokens ('xyz) are matched by tt. So just like the literal matcher RFC, this caveat should apply, that it doesn't actually add much power just ease of use to macros by example. /pull/1576
This comment has been minimized.
This comment has been minimized.
sgrif
Apr 23, 2016
Author
Contributor
Ah good point. I would argue it does still add a good bit of power in the context of sequences. I will amend the RFC to note this, however.
This comment has been minimized.
This comment has been minimized.
sgrif
Apr 23, 2016
Author
Contributor
As it turns out, you actually can't use a tt in a lifetime position:
error: expected identifier, found `'a`
impl<$($lifetime),*> SomeTrait
This comment has been minimized.
This comment has been minimized.
bluss
Apr 23, 2016
•
tts don't expand anywhere without the ast coercion (reparse trick) that danielkeep was referring to.
This comment has been minimized.
This comment has been minimized.
bluss
Apr 23, 2016
Don't get me wrong, I think this is a good addition, good RFC. But I don't think it gives macro_rules powers it didn't already have.
This comment has been minimized.
This comment has been minimized.
bluss
Apr 23, 2016
Here's the reparse trick. https://play.rust-lang.org/?gist=3287a8aab3bea913916f56d12c7a00ad&version=stable&backtrace=0
This comment has been minimized.
This comment has been minimized.
sgrif
Apr 23, 2016
Author
Contributor
Gotcha. Thanks for the link. I'm also interested because I would like to use this in Diesel as a workaround until this (hopefully) is accepted and in stable
brendanzab
reviewed
Apr 23, 2016
| [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 |
This comment has been minimized.
This comment has been minimized.
brendanzab
Apr 23, 2016
•
Member
lt might be confused with 'literal', if it were ever added.
Also, perhaps these other names could be moved to the # Alternatives section?
This comment has been minimized.
This comment has been minimized.
sgrif
Apr 23, 2016
Author
Contributor
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 name
This comment has been minimized.
This comment has been minimized.
bluss
Apr 23, 2016
I agree that the long word lifetime seems good. I don't see a reason to save letters here.
pnkfelix
added
the
T-lang
label
Apr 23, 2016
This comment has been minimized.
This comment has been minimized.
|
I know it's in the implementation, but the follow set for the matcher is probably a detail that should be in the RFC (and possibly included as a delta to RFC 550 as well). |
This comment has been minimized.
This comment has been minimized.
|
I wrote a PR for this a while back and @alexcrichton mentioned that |
This comment has been minimized.
This comment has been minimized.
|
I don't think we can really make new non-contextual keywords anymore. And I don't see the ambiguity anyway if there were to be a matcher with the same name as a keyword. |
nikomatsakis
added
the
I-nominated
label
Apr 28, 2016
This comment has been minimized.
This comment has been minimized.
|
I'm nominating this for discussion as a "fast track for FCP" thing. However, I also think we should add a note about the follow-set (though it is mostly implied by the comparison to identifier). |
This comment has been minimized.
This comment has been minimized.
|
Updated to mention the follow-set |
nikomatsakis
assigned
pnkfelix
Apr 28, 2016
This comment has been minimized.
This comment has been minimized.
|
(another potential way to denote the bound could be |
nikomatsakis
removed
the
I-nominated
label
May 5, 2016
This comment has been minimized.
This comment has been minimized.
|
We discussed this RFC in the previous @rust-lang/lang meeting. We all agree this is a pretty harmless addition, but for one concern: there remains some lingering concern among us that the term lifetime may not have been the best choice. Specifically, there is this ambiguity between the lifetime of a value -- i.e., when the destructor will run, which I tend to call the value's scope -- and the lifetime of a reference -- the region of the code where the reference will be used. To make matters just a bit more confusing, these two notions of lifetime are interrelated -- specifically, you can't make a reference to a value for longer than the value's scope. Up till now the term reference, while firmly entrenched in our documentation and blog posts, hasn't been in the language itself (though it does appear in the associated items RFC; but that was never implemented -- something we ought to fix, but then of course we'd run into the same problem). That said, this may well be a distinction without a difference. I have to admit I feel pretty terrible holding up this otherwise unobjectionable RFC on this matter, since it's kind of an amorphous concern with no clear resolution. This is one reason we were brainstorming other possible syntaxes, such as I was thinking now though that there is though another possible way to view things which might make the name lifetime perfectly acceptable. That is, one could coin a term representing the region of the code where a reference is used -- candidates might be calling it the reference's region, or extent, or the duration of a borrow. In that case, the term lifetime is kind of a "superset" of these things: a scope is a lifetime, but so is a region. Not sure yet if that's a useful way to think about things. Anyway, those were our concerns. |
This comment has been minimized.
This comment has been minimized.
|
This is about syntax. A macro isn't manipulating the validity region of a reference or the destruction scope of a value or anything like that. Everyone calls the
|
This comment has been minimized.
This comment has been minimized.
|
Amusingly, the macro |
This comment has been minimized.
This comment has been minimized.
bluss
commented
May 6, 2016
|
Maybe this fact can inspire new names: Loop labels use the same syntax. |
This comment has been minimized.
This comment has been minimized.
|
I definitely think 'ident would be fine as well, but I'm not sure how On Fri, May 6, 2016, 6:38 PM bluss notifications@github.com wrote:
|
This comment has been minimized.
This comment has been minimized.
bluss
commented
May 7, 2016
|
|
This comment has been minimized.
This comment has been minimized.
|
Yes, this was intentional, because we intended to (and I think still let x;
let y;
'a: {
x = &'a y; // (error)
}On Fri, May 06, 2016 at 04:38:01PM -0700, bluss wrote:
|
This comment has been minimized.
This comment has been minimized.
|
Is there any hope of un-stalling this? Several ideas have been proposed to solve the trivial naming issue which is blocking the RFC (ignore it and use |
This comment has been minimized.
This comment has been minimized.
bluss
commented
May 14, 2016
|
|
This comment has been minimized.
This comment has been minimized.
|
@durka I talked with @nikomatsakis last week about this. I suspect at this point that we are likely to bite the bullet and just accept Renominating for discussion at lang-team mtg. |
pnkfelix
added
the
I-nominated
label
May 16, 2016
This comment has been minimized.
This comment has been minimized.
|
We discussed in the @rust-lang/lang meeting. We came to the conclusion that we should just go with the term "lifetime". Hence we are nominating this for final comment period. My personal feeling is that I would like to have three terms:
Right now we tend to call all 3 of these lifetimes, so I am roughly proposing keeping that in place, but adding some more specific terms for two distinct concepts. I am not quite sure what that third term ought to be, though: I vacillate between "extent", "region", "duration", and a few other such words. I hope that in most docs and error messages though we can get away with not needing to use it, so maybe it's just a term that we use when trying to explain the type system at a more advanced level. |
This comment has been minimized.
This comment has been minimized.
|
Hear ye, hear ye! This RFC is now entering final comment period. |
nikomatsakis
added
the
final-comment-period
label
May 20, 2016
nikomatsakis
removed
the
I-nominated
label
May 20, 2016
This comment has been minimized.
This comment has been minimized.
|
FCP should be over soon, yeah? |
This comment has been minimized.
This comment has been minimized.
|
Yes -- the lang meeting wound up cancelled last week, but we should have a final decision on Thursday. Sorry or the delay! |
This comment has been minimized.
This comment has been minimized.
|
This is getting a bit ridiculous. |
This comment has been minimized.
This comment has been minimized.
|
Actually, the problem is my fault. The @rust-lang/lang team did discuss this and decided to accept it some time back (a week or so) -- but i've been overwhelmed and failed to follow up on my clerical duties! I do apologize. |
This comment has been minimized.
This comment has been minimized.
|
Huzzah! The @rust-lang/lang team has decided to accept this RFC. |
nikomatsakis
referenced this pull request
Jun 16, 2016
Closed
Tracking issue for adding a `lifetime` specifier to `macro_rules!` #34303
nikomatsakis
merged commit 17d68e5
into
rust-lang:master
Jun 16, 2016
This comment has been minimized.
This comment has been minimized.
|
Woohoo! |
sgrif commentedApr 22, 2016
•
edited
Rendered