Skip to content

Require the use of as _ for indirectly used traits in Clippy sources - #17369

Merged
llogiq merged 2 commits into
rust-lang:masterfrom
samueltardieu:cleanups/trait-import-as-underscore
Jul 17, 2026
Merged

Require the use of as _ for indirectly used traits in Clippy sources#17369
llogiq merged 2 commits into
rust-lang:masterfrom
samueltardieu:cleanups/trait-import-as-underscore

Conversation

@samueltardieu

Copy link
Copy Markdown
Member

This PR requires as _ in Clippy sources when importing a trait name which is not directly used, as to not pollute the namespace (first commit). It also activate the clippy::unused_trait_names in dogfood (second commit).

changelog: none

@rustbot

rustbot commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in clippy_lints/src/doc

cc @notriddle

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 6, 2026
@rustbot

rustbot commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

r? @llogiq

rustbot has assigned @llogiq.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 8 candidates
  • 8 candidates expanded to 8 candidates
  • Random selection from Jarcho, llogiq

@samueltardieu samueltardieu changed the title Cleanups/trait import as underscore Require the use of as _ for indirectly used traits in Clippy sources Jul 6, 2026

@bushrat011899 bushrat011899 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes sense to me. Confirmed that every change in the first commit simply adds as _ to most traits, with one exception noted below. Mostly just a curiosity and not an issue with this PR.

View changes since this review

@@ -4,11 +4,11 @@ use clippy_utils::sugg::Sugg;
use hir::Param;
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::intravisit::{Visitor as HirVisitor, Visitor};
use rustc_hir::intravisit::Visitor;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Surprised this wasn't triggering unused_imports on HirVisitor. I guess the trait's items were being used from HirVisitor (keeping it used), while the trait as a name was used as Visitor? (or vice versa?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Multiple imports with renaming don't seem to trigger unused_imports, which makes sense as the import is not unused, just redundant.

@samueltardieu
samueltardieu force-pushed the cleanups/trait-import-as-underscore branch from 50d0d2a to 55eb6c4 Compare July 10, 2026 08:17
@rustbot

This comment has been minimized.

@samueltardieu
samueltardieu force-pushed the cleanups/trait-import-as-underscore branch from 55eb6c4 to 17baf7e Compare July 10, 2026 08:17
@rustbot

This comment has been minimized.

@samueltardieu
samueltardieu force-pushed the cleanups/trait-import-as-underscore branch from 17baf7e to 58a4f9c Compare July 10, 2026 14:41
@rustbot

This comment has been minimized.

@samueltardieu
samueltardieu force-pushed the cleanups/trait-import-as-underscore branch from 58a4f9c to f9d532c Compare July 10, 2026 14:47
@samueltardieu
samueltardieu force-pushed the cleanups/trait-import-as-underscore branch from f9d532c to 15edcdd Compare July 11, 2026 07:51
@rustbot

rustbot commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@llogiq llogiq left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ok, why not. If it was too cumbersome for us, we shouldn't have the lint at all.

View changes since this review

@Jarcho

Jarcho commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

This is going to make rust-analyzer's auto imports annoying since it doesn't import using as _.

Ok, why not. If it was too cumbersome for us, we shouldn't have the lint at all.

It's a restriction lint. One that might have been pedantic if it were there from the beginning, but still a restriction lint.

@samueltardieu
samueltardieu deleted the cleanups/trait-import-as-underscore branch July 19, 2026 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants