Skip to content

Add new lint: std_wildcard_imports #14868

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alanbondarun
Copy link

@alanbondarun alanbondarun commented May 22, 2025

changelog: [std_wildcard_imports]: Initial implementation

This fixes #13961.

Please let me know if there any missing test cases and/or changes!

TODO

  • Fix failed tests from other lints
  • Add more test cases

@alanbondarun alanbondarun force-pushed the std_wildcard_imports branch 4 times, most recently from 3a0a721 to 5f8b8e3 Compare May 27, 2025 09:40
@alanbondarun alanbondarun marked this pull request as ready for review May 27, 2025 09:43
@rustbot
Copy link
Collaborator

rustbot commented May 27, 2025

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

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 27, 2025
@alanbondarun alanbondarun changed the title [WIP] Add new lint: std_wildcard_imports Add new lint: std_wildcard_imports May 27, 2025
@rustbot

This comment has been minimized.

@alanbondarun alanbondarun force-pushed the std_wildcard_imports branch from 5f8b8e3 to 80ac147 Compare June 2, 2025 12:36
Copy link
Contributor

@llogiq llogiq left a comment

Choose a reason for hiding this comment

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

There seems to be some duplication with the wildcard_imports lint. It probably makes sense to pull those lint passes together into one pass that implements both lints.

Otherwise I'm dubious about making this a warn-by-default lint, but we can discuss this during the final comment period.

/// Wildcard imports can pollute the namespace. This is especially bad when importing from the
/// standard library through wildcards:
///
/// ```no_run
Copy link
Contributor

Choose a reason for hiding this comment

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

This belongs into the Example section.

/// ```
#[clippy::version = "1.89.0"]
pub STD_WILDCARD_IMPORTS,
style,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about the lint group. Yes, namespace pollution is bad. But there are four stdlib namespaces (of which three might be imported from in somewhat normal code), so this could lead to serious churn.

I also don't follow the argument that names imported from std are somehow worse than others. Why? The standard library moves slower than other crates if anything.

cx,
STD_WILDCARD_IMPORTS,
span,
"usage of wildcard import from `std` crates",
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be shorter and clearer to replace the "std crates" with the actual crate name.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jun 2, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 4, 2025

☔ The latest upstream changes (possibly 84ef7fb) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

std_wildcard_imports to lint against use std::mod::*
3 participants