rust-lang/rust-clippy

`std_wildcard_imports` to lint against `use std::mod::*`

Open

#13.961 geöffnet am 7. Jan. 2025

Auf GitHub ansehen
 (4 Kommentare) (1 Reaktion) (1 zugewiesene Person)Rust (1.391 Forks)batch import
A-lintE-help-wantedgood first issue

Repository-Metriken

Stars
 (10.406 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 16T 6h) (79 gemergte PRs in 30 T)

Beschreibung

What it does

This is a version of wildcard_imports that affects only imports from the standard crates std, core, proc_macro, alloc, and test.

Advantage

wildcard_imports is in pedantic, which seems reasonable for most crates. However, using glob imports from the standard library means that upgrading Rust version can break the build. Recent examples:

I am proposing std_wildcard_imports as a separate lint from wildcard_imports so it can get enabled by default, likely in clippy::style (or possibly uplifted https://github.com/rust-lang/rust/issues/135672#issuecomment-2605426121)

Drawbacks

Confusion between wildcard_imports and std_wildcard_imports, noise on existing code, sometimes use proc_macro::* or similar is fine for testing.

Example

Lint on glob imports:

use std::mem::*; // error
use core::sync::*; // error
use proc_macro::*; // error

However, using glob imports from prelude modules should not raise this warning:

use std::io::prelude::*; // ok
use std::prelude::rust_2021:* // unlikely, but still ok

Non-std crates don't raise this lint

use regex::*; // ok

Contributor Guide