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

ast: Generalize item kind visiting #124382

Merged
merged 2 commits into from Apr 27, 2024
Merged

Conversation

petrochenkov
Copy link
Contributor

And avoid duplicating logic for visiting Items with different kinds (regular, associated, foreign).

The diff is better viewed with whitespace ignored.

@rustbot
Copy link
Collaborator

rustbot commented Apr 25, 2024

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Apr 25, 2024
@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

r=me after nits

@@ -34,6 +34,10 @@ impl<A: Array> ExpectOne<A> for SmallVec<A> {
}
}

pub trait NoopVisitItemKind {
Copy link
Contributor

Choose a reason for hiding this comment

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

using noop here is confusing to me. This seems to match SuperVisitable for types, so I'd really like this to be renamed to sth like trait SuperVisitableItem

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 used the naming convention that is used everywhere else in mut_visit.rs, there are dozens of noop_visits there.
(Same applies to visit.rs.)

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, i dislike that 😢 i guess it's fine to keep it, but if you have the time, I would be really happy to see it changed in a separate PR then

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 think it's better to keep the consistent naming, and at some point change the naming scheme in one go (if change at all).

(I don't have any hard feelings towards the current naming personally, it's been around for like 10 years, and at least everyone working with AST knows it.)

Copy link
Contributor

Choose a reason for hiding this comment

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

sure, I would like to see it changed in one go. Anyways, for this PR then please just do

Suggested change
pub trait NoopVisitItemKind {
pub trait NoopVisitableItem {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The style guide recommends against "able" in traits though - https://github.com/rust-lang/rfcs/blob/master/text/0344-conventions-galore.md#trait-naming (at least that's what standard library follows, so I've been always following it in the compiler as well).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Also, this is about ItemKind specifically, not Item)

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess that's alright 👍 we do use -able for quite a few existing traits, esp the existing ty visitors, but 🤷

@@ -34,6 +34,10 @@ impl<A: Array> ExpectOne<A> for SmallVec<A> {
}
}

pub trait NoopVisitItemKind {
fn noop_visit(&mut self, visitor: &mut impl MutVisitor);
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

Suggested change
fn noop_visit(&mut self, visitor: &mut impl MutVisitor);
fn super_visit(mut self, visitor: &mut impl MutVisitor);

@@ -102,6 +102,15 @@ pub enum LifetimeCtxt {
GenericArg,
}

pub trait WalkItemKind: Sized {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub trait WalkItemKind: Sized {
pub trait WalkableKind: Sized {

And avoid duplicating logic for visiting `Item`s with different kinds (regular, associated, foreign).
@rustbot
Copy link
Collaborator

rustbot commented Apr 25, 2024

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@lcnr
Copy link
Contributor

lcnr commented Apr 27, 2024

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Apr 27, 2024

📌 Commit 7517a4f has been approved by lcnr

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 Apr 27, 2024
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 27, 2024
ast: Generalize item kind visiting

And avoid duplicating logic for visiting `Item`s with different kinds (regular, associated, foreign).

The diff is better viewed with whitespace ignored.
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 27, 2024
Rollup of 3 pull requests

Successful merges:

 - rust-lang#124370 (Fix substitution parts having a shifted underline in some cases)
 - rust-lang#124382 (ast: Generalize item kind visiting)
 - rust-lang#124387 (thread_local: be excruciatingly explicit in dtor code)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 27, 2024
…iaskrgr

Rollup of 3 pull requests

Successful merges:

 - rust-lang#124382 (ast: Generalize item kind visiting)
 - rust-lang#124387 (thread_local: be excruciatingly explicit in dtor code)
 - rust-lang#124427 (Add missing tests for an ICE)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit cf07246 into rust-lang:master Apr 27, 2024
10 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Apr 27, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 27, 2024
Rollup merge of rust-lang#124382 - petrochenkov:itemvisit, r=lcnr

ast: Generalize item kind visiting

And avoid duplicating logic for visiting `Item`s with different kinds (regular, associated, foreign).

The diff is better viewed with whitespace ignored.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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.

None yet

5 participants