Skip to content
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 walk_generic_arg #103692

Merged
merged 1 commit into from
Nov 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions compiler/rustc_hir/src/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,7 @@ pub trait Visitor<'v>: Sized {
walk_inf(self, inf);
}
fn visit_generic_arg(&mut self, generic_arg: &'v GenericArg<'v>) {
match generic_arg {
GenericArg::Lifetime(lt) => self.visit_lifetime(lt),
GenericArg::Type(ty) => self.visit_ty(ty),
GenericArg::Const(ct) => self.visit_anon_const(&ct.value),
GenericArg::Infer(inf) => self.visit_infer(inf),
}
walk_generic_arg(self, generic_arg);
}
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
walk_lifetime(self, lifetime)
Expand Down Expand Up @@ -480,6 +475,15 @@ pub fn walk_label<'v, V: Visitor<'v>>(visitor: &mut V, label: &'v Label) {
visitor.visit_ident(label.ident);
}

pub fn walk_generic_arg<'v, V: Visitor<'v>>(visitor: &mut V, generic_arg: &'v GenericArg<'v>) {
match generic_arg {
GenericArg::Lifetime(lt) => visitor.visit_lifetime(lt),
GenericArg::Type(ty) => visitor.visit_ty(ty),
GenericArg::Const(ct) => visitor.visit_anon_const(&ct.value),
GenericArg::Infer(inf) => visitor.visit_infer(inf),
}
}

Comment on lines +478 to +486
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be after walk_inf instead of here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be happy to make that change.

But here are the visit_ methods in the order they appear in intravisit.rs:

visit_ methods
nested_item
nested_trait_item
nested_impl_item
nested_foreign_item
nested_body
param
item
body
id
name
ident
mod
foreign_item
local
block
stmt
arm
pat
pat_field
array_length
anon_const
expr
let_expr
expr_field
ty
generic_param
const_param_default
generics
where_predicate
fn_decl
fn
use
trait_item
trait_item_ref
impl_item
foreign_item_ref
impl_item_ref
trait_ref
param_bound
poly_trait_ref
variant_data
field_def
enum_def
variant
label
infer
generic_arg
lifetime
qpath
path
path_segment
generic_args
assoc_type_binding
attribute
associated_item_kind
defaultness
inline_asm

And here are the walk_ functions in the order they appear in intravisit.rs:

walk_ functions
mod
body
local
ident
label
generic_arg
lifetime
poly_trait_ref
trait_ref
param
item
inline_asm
use
enum_def
variant
ty
inf
qpath
path
path_segment
generic_args
assoc_type_binding
pat
pat_field
foreign_item
param_bound
generic_param
const_param_default
generics
where_predicate
fn_ret_ty
fn_decl
fn_kind
fn
trait_item
trait_item_ref
impl_item
foreign_item_ref
impl_item_ref
struct_def
field_def
block
stmt
array_len
anon_const
let_expr
expr_field
expr
arm
associated_item_kind
defaultness

Would it be better if I reordered the walk_ functions to match the order of the visit_ functions?

pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime) {
visitor.visit_id(lifetime.hir_id);
match lifetime.name {
Expand Down