Skip to content

Add walk_generic_arg #103692

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Nov 1, 2022
Merged

Add walk_generic_arg #103692

merged 1 commit into from
Nov 1, 2022

Conversation

smoelius
Copy link
Contributor

@smoelius smoelius commented Oct 28, 2022

Could this please be added?

I could use it for a Clippy lint.

@rustbot
Copy link
Collaborator

rustbot commented Oct 28, 2022

r? @davidtwco

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 28, 2022
Comment on lines +478 to +486
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),
}
}

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?

@fee1-dead
Copy link
Member

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

Yeah, that would be desirable. But that seems okay as a followup.

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Oct 31, 2022

📌 Commit 86a4009 has been approved by fee1-dead

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 31, 2022
@fee1-dead fee1-dead assigned fee1-dead and unassigned davidtwco Oct 31, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 1, 2022
Rollup of 10 pull requests

Successful merges:

 - rust-lang#103007 (Add better python discovery)
 - rust-lang#103674 (Update note about unstable split-debuginfo flag.)
 - rust-lang#103692 (Add `walk_generic_arg`)
 - rust-lang#103749 (Reduce span of let else irrefutable_let_patterns warning)
 - rust-lang#103772 (better error for `rustc_strict_coherence` misuse)
 - rust-lang#103788 (Fix ICE in checking transmutability of NaughtyLenArray)
 - rust-lang#103793 (rustdoc: add margins to all impl-item toggles, not just methods)
 - rust-lang#103798 (interpret: move type_name implementation to an interpreter-independent helper file)
 - rust-lang#103799 (Remove generation of tuple struct fields in the search index)
 - rust-lang#103805 (Enable RUSTC_BOOTSTRAP for a few steps)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 2125181 into rust-lang:master Nov 1, 2022
@rustbot rustbot added this to the 1.67.0 milestone Nov 1, 2022
@smoelius smoelius deleted the walk_generic_arg branch November 1, 2022 08:41
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Nov 2, 2022
…=fee1-dead

Reorder `walk_` functions in intravisit.rs

Reorder the `walk_` functions to match the order of the `visit_` methods. This is a follow up to rust-lang#103692.

Note that there are some oddballs. I put them where I thought made the most sense:
```diff
$ diff \
<(sed -n 's/^.*\<fn visit_\([^(]*\).*$/\1/;T;p' compiler/rustc_hir/src/intravisit.rs) \
<(sed -n 's/^.*\<fn walk_\([^<]*\).*$/\1/;T;p' compiler/rustc_hir/src/intravisit.rs)
1,5d0
< nested_item
< nested_trait_item
< nested_impl_item
< nested_foreign_item
< nested_body
9,10d3
< id
< name
20c13
< array_length
---
> array_len
30a24
> fn_ret_ty
31a26
> fn_kind
41c36
< variant_data
---
> struct_def
46c41
< infer
---
> inf
54d48
< attribute
```

Also, as some weak evidence that i did things correctly, I get the following before and after the change:
```sh
$ sort compiler/rustc_hir/src/intravisit.rs | openssl sha256
SHA256(stdin)= cac13d2545731ef442f318e2b4286490d7ac5494f4ad10c4cf4c5d4f50d21641
```

r? `@fee1-dead`
bors added a commit to rust-lang/rust-clippy that referenced this pull request Nov 22, 2022
Use `walk_generic_arg`

This is a tiny followup to to #9743, now that rust-lang/rust#103692 has landed.

r? `@Alexendoo`

changelog: none
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants