]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/wildcard_imports.txt
Rollup merge of #102470 - est31:stabilize_const_char_convert, r=joshtriplett
[rust.git] / src / tools / clippy / src / docs / wildcard_imports.txt
1 ### What it does
2 Checks for wildcard imports `use _::*`.
3
4 ### Why is this bad?
5 wildcard imports can pollute the namespace. This is especially bad if
6 you try to import something through a wildcard, that already has been imported by name from
7 a different source:
8
9 ```
10 use crate1::foo; // Imports a function named foo
11 use crate2::*; // Has a function named foo
12
13 foo(); // Calls crate1::foo
14 ```
15
16 This can lead to confusing error messages at best and to unexpected behavior at worst.
17
18 ### Exceptions
19 Wildcard imports are allowed from modules named `prelude`. Many crates (including the standard library)
20 provide modules named "prelude" specifically designed for wildcard import.
21
22 `use super::*` is allowed in test modules. This is defined as any module with "test" in the name.
23
24 These exceptions can be disabled using the `warn-on-all-wildcard-imports` configuration flag.
25
26 ### Known problems
27 If macros are imported through the wildcard, this macro is not included
28 by the suggestion and has to be added by hand.
29
30 Applying the suggestion when explicit imports of the things imported with a glob import
31 exist, may result in `unused_imports` warnings.
32
33 ### Example
34 ```
35 use crate1::*;
36
37 foo();
38 ```
39
40 Use instead:
41 ```
42 use crate1::foo;
43
44 foo();
45 ```