-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Extend HIR to track the source and syntax of a lifetime #139945
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
base: master
Are you sure you want to change the base?
Conversation
An upcoming lint will want to be able to know if a lifetime is hidden (e.g. `&u8`, `ContainsLifetime`) or anonymous: (e.g. `&'_ u8`, `ContainsLifetime<'_>`). It will also want to know if the lifetime is related to a reference (`&u8`) or a path (`ContainsLifetime`).
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.
Some questions and comments, but I definitely like the direction this is headed in. I'm not certain the LifetimeSource
/LifetimeSyntax
split is the optimal representation, but it's clearer than IsAnonInPath
so I won't be too pedantic about it.
|
||
/// Details not yet needed. Feel free to give useful | ||
/// categorization to these usages. | ||
Other, |
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.
What is this for? Can you give an example?
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.
The comment is attempting to express this, but it's literally just every other usage that isn't one of the previous categories. Those usages are not relevant to the lint I'm writing, and I'm not familiar with what they are, so it didn't seem right to spend time to categorize them in ways that are not useful to me and potentially actively un-useful for the next person.
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.
Sorry, I'm fine with having Other
, but can you give one or two examples in the comment? It's not obvious to me what other cases there are.
fn from(ident: Ident) -> Self { | ||
let name = ident.name; | ||
|
||
if name == kw::Empty { |
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.
Can kw::Empty
ever reach here? If so, where from? I'm curious because I've been eliminating kw::Empty
uses aggressively lately.
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 don't actually know; this was more of a "just in case" scenario. Do you want me to change this to a panic?
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.
If it doesn't trip on any test, yes please.
} | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable_Generic)] | ||
pub enum LifetimeSyntax { |
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 all combinations of LifetimeSource
/LifetimeSyntax
possible?
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.
No, I don't believe so. For example, I don't think you can have LifetimeSyntax::Hidden
with LifetimeSource::OutlivesBound
or LifetimeSource::PreciseCapturing
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.
That would be good to capture in a comment. Maybe on the definition of Lifetime
, because that's where LifetimeSyntax
and LifetimeSource
are used together.
}; | ||
let span = self.tcx.sess.source_map().start_point(t.span).shrink_to_hi(); | ||
let region = Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id }; | ||
(region, LifetimeSyntax::Hidden) |
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 the name is '_
but the LifetimeSyntax
is Hidden
... why is that? It's the only call to lower_lifetime
where the given ident doesn't match the ident in the lifetime.
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.
It has to have a name — ident
isn't an Option
and you are removing these kinds of usages of kw::Empty
, so UnderscoreLifetime
would be the next most semantic choice. This corresponds to &Type
— there is no original source code name for the lifetime, it is hidden.
It's the only call to
lower_lifetime
where the given ident doesn't match the ident in the lifetime.
That's true, but notably lower_lifetime_hidden_in_path
and elided_dyn_bound
do the same concept of pairing UnderscoreLifetime
with Hidden
.
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.
ok
☔ The latest upstream changes (presumably #139938) made this pull request unmergeable. Please resolve the merge conflicts. |
Adding the panic on the empty case and a couple more comments should be enough for this to merge, thanks. |
An upcoming lint will want to be able to know if a lifetime is hidden (e.g.
&u8
,ContainsLifetime
) or anonymous: (e.g.&'_ u8
,ContainsLifetime<'_>
). It will also want to know if the lifetime is related to a reference (&u8
) or a path (ContainsLifetime
).r? @nnethercote