-
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
Conversation
|
||
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. |
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.
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
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.
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.
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.
As it turns out, you actually can't use a tt
in a lifetime position:
error: expected identifier, found `'a`
impl<$($lifetime),*> SomeTrait
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.
tts don't expand anywhere without the ast coercion (reparse trick) that danielkeep was referring to.
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.
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.
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.
Here's the reparse trick. https://play.rust-lang.org/?gist=3287a8aab3bea913916f56d12c7a00ad&version=stable&backtrace=0
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.
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
[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 |
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 name
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.
I agree that the long word lifetime
seems good. I don't see a reason to save letters here.
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). |
I wrote a PR for this a while back and @alexcrichton mentioned that |
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. |
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). |
Updated to mention the follow-set |
(another potential way to denote the bound could be |
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 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
|
Amusingly, the macro |
Maybe this fact can inspire new names: Loop labels use the same syntax. |
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:
|
|
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:
|
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 |
|
@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. |
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. |
Hear ye, hear ye! This RFC is now entering final comment period. |
FCP should be over soon, yeah? |
Yes -- the lang meeting wound up cancelled last week, but we should have a final decision on Thursday. Sorry or the delay! |
This is getting a bit ridiculous. |
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. |
Huzzah! The @rust-lang/lang team has decided to accept this RFC. |
Woohoo! |
Rendered