-
Notifications
You must be signed in to change notification settings - Fork 13.3k
rustc: don't visit lifetime parameters through visit_lifetime. #51215
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
Conversation
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.
This looks good. I made an optional recommendation but r=me either way.
@@ -733,7 +733,16 @@ pub fn walk_ty_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v TyPar | |||
pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v GenericParam) { | |||
match *param { | |||
GenericParam::Lifetime(ref ld) => { | |||
visitor.visit_lifetime(&ld.lifetime); | |||
visitor.visit_id(ld.lifetime.id); |
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.
Wait, is there no visit_lifetime_def
? Can we make one?
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 guess we don't have visit_type_def
. Seems a shame, but ok.
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's visit_generic_param
- handling just one kind of parameter is generally a bug.
|
||
for param in &generics.params { | ||
match *param { | ||
hir::GenericParam::Lifetime(ref lifetime_def) => { | ||
if !lifetime_def.bounds.is_empty() { | ||
// `'a: 'b` means both `'a` and `'b` are referenced | ||
appears_in_where_clause.visit_generic_param(param); | ||
appears_in_where_clause.regions.insert(lifetime_def.lifetime.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.
if we had a visit_lifetime_def
, we could handle this within the visit impl, which seems like it'd be nicer
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'd be wrong, because it'd also apply on nested for
's but we only want the outermost params. I almost moved this check to the loop below.
@bors r=nikomatsakis |
📌 Commit df45c4f has been approved by |
🔒 Merge conflict |
df45c4f
to
5c76b64
Compare
@bors r=nikomatsakis |
📌 Commit 5c76b64 has been approved by |
rustc: don't visit lifetime parameters through visit_lifetime. Ideally we'd also not use the `Lifetime` struct for parameters, but I'll leave that to @varkor (#48149). Fixes #51185 (discovered while auditing all the `visit_lifetime` implementations). r? @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
Ideally we'd also not use the
Lifetime
struct for parameters, but I'll leave that to @varkor (#48149).Fixes #51185 (discovered while auditing all the
visit_lifetime
implementations).r? @nikomatsakis