Add 2018/2021 edition tests for wildcard_imports
This commit is contained in:
parent
3b67e6af9e
commit
033f1ec797
@ -5,7 +5,6 @@
|
|||||||
// the 2015 edition here is needed because edition 2018 changed the module system
|
// the 2015 edition here is needed because edition 2018 changed the module system
|
||||||
// (see https://doc.rust-lang.org/edition-guide/rust-2018/path-changes.html) which means the lint
|
// (see https://doc.rust-lang.org/edition-guide/rust-2018/path-changes.html) which means the lint
|
||||||
// no longer detects some of the cases starting with Rust 2018.
|
// no longer detects some of the cases starting with Rust 2018.
|
||||||
// FIXME: We should likely add another edition 2021 test case for this lint
|
|
||||||
|
|
||||||
#![warn(clippy::wildcard_imports)]
|
#![warn(clippy::wildcard_imports)]
|
||||||
#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
|
#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
// the 2015 edition here is needed because edition 2018 changed the module system
|
// the 2015 edition here is needed because edition 2018 changed the module system
|
||||||
// (see https://doc.rust-lang.org/edition-guide/rust-2018/path-changes.html) which means the lint
|
// (see https://doc.rust-lang.org/edition-guide/rust-2018/path-changes.html) which means the lint
|
||||||
// no longer detects some of the cases starting with Rust 2018.
|
// no longer detects some of the cases starting with Rust 2018.
|
||||||
// FIXME: We should likely add another edition 2021 test case for this lint
|
|
||||||
|
|
||||||
#![warn(clippy::wildcard_imports)]
|
#![warn(clippy::wildcard_imports)]
|
||||||
#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
|
#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:16:5
|
--> $DIR/wildcard_imports.rs:15:5
|
||||||
|
|
|
|
||||||
LL | use crate::fn_mod::*;
|
LL | use crate::fn_mod::*;
|
||||||
| ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
|
| ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
|
||||||
@ -7,85 +7,85 @@ LL | use crate::fn_mod::*;
|
|||||||
= note: `-D clippy::wildcard-imports` implied by `-D warnings`
|
= note: `-D clippy::wildcard-imports` implied by `-D warnings`
|
||||||
|
|
||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:17:5
|
--> $DIR/wildcard_imports.rs:16:5
|
||||||
|
|
|
|
||||||
LL | use crate::mod_mod::*;
|
LL | use crate::mod_mod::*;
|
||||||
| ^^^^^^^^^^^^^^^^^ help: try: `crate::mod_mod::inner_mod`
|
| ^^^^^^^^^^^^^^^^^ help: try: `crate::mod_mod::inner_mod`
|
||||||
|
|
||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:18:5
|
--> $DIR/wildcard_imports.rs:17:5
|
||||||
|
|
|
|
||||||
LL | use crate::multi_fn_mod::*;
|
LL | use crate::multi_fn_mod::*;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}`
|
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}`
|
||||||
|
|
||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:20:5
|
--> $DIR/wildcard_imports.rs:19:5
|
||||||
|
|
|
|
||||||
LL | use crate::struct_mod::*;
|
LL | use crate::struct_mod::*;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::struct_mod::{A, inner_struct_mod}`
|
| ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::struct_mod::{A, inner_struct_mod}`
|
||||||
|
|
||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:24:5
|
--> $DIR/wildcard_imports.rs:23:5
|
||||||
|
|
|
|
||||||
LL | use wildcard_imports_helper::inner::inner_for_self_import::*;
|
LL | use wildcard_imports_helper::inner::inner_for_self_import::*;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar`
|
||||||
|
|
||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:25:5
|
--> $DIR/wildcard_imports.rs:24:5
|
||||||
|
|
|
|
||||||
LL | use wildcard_imports_helper::*;
|
LL | use wildcard_imports_helper::*;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
|
||||||
|
|
||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:96:13
|
--> $DIR/wildcard_imports.rs:95:13
|
||||||
|
|
|
|
||||||
LL | use crate::fn_mod::*;
|
LL | use crate::fn_mod::*;
|
||||||
| ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
|
| ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
|
||||||
|
|
||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:102:75
|
--> $DIR/wildcard_imports.rs:101:75
|
||||||
|
|
|
|
||||||
LL | use wildcard_imports_helper::inner::inner_for_self_import::{self, *};
|
LL | use wildcard_imports_helper::inner::inner_for_self_import::{self, *};
|
||||||
| ^ help: try: `inner_extern_foo`
|
| ^ help: try: `inner_extern_foo`
|
||||||
|
|
||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:103:13
|
--> $DIR/wildcard_imports.rs:102:13
|
||||||
|
|
|
|
||||||
LL | use wildcard_imports_helper::*;
|
LL | use wildcard_imports_helper::*;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
|
||||||
|
|
||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:114:20
|
--> $DIR/wildcard_imports.rs:113:20
|
||||||
|
|
|
|
||||||
LL | use self::{inner::*, inner2::*};
|
LL | use self::{inner::*, inner2::*};
|
||||||
| ^^^^^^^^ help: try: `inner::inner_foo`
|
| ^^^^^^^^ help: try: `inner::inner_foo`
|
||||||
|
|
||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:114:30
|
--> $DIR/wildcard_imports.rs:113:30
|
||||||
|
|
|
|
||||||
LL | use self::{inner::*, inner2::*};
|
LL | use self::{inner::*, inner2::*};
|
||||||
| ^^^^^^^^^ help: try: `inner2::inner_bar`
|
| ^^^^^^^^^ help: try: `inner2::inner_bar`
|
||||||
|
|
||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:121:13
|
--> $DIR/wildcard_imports.rs:120:13
|
||||||
|
|
|
|
||||||
LL | use wildcard_imports_helper::*;
|
LL | use wildcard_imports_helper::*;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}`
|
||||||
|
|
||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:150:9
|
--> $DIR/wildcard_imports.rs:149:9
|
||||||
|
|
|
|
||||||
LL | use crate::in_fn_test::*;
|
LL | use crate::in_fn_test::*;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}`
|
| ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}`
|
||||||
|
|
||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:159:9
|
--> $DIR/wildcard_imports.rs:158:9
|
||||||
|
|
|
|
||||||
LL | use crate:: in_fn_test:: * ;
|
LL | use crate:: in_fn_test:: * ;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported`
|
||||||
|
|
||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:160:9
|
--> $DIR/wildcard_imports.rs:159:9
|
||||||
|
|
|
|
||||||
LL | use crate:: fn_mod::
|
LL | use crate:: fn_mod::
|
||||||
| _________^
|
| _________^
|
||||||
@ -93,37 +93,37 @@ LL | | *;
|
|||||||
| |_________^ help: try: `crate:: fn_mod::foo`
|
| |_________^ help: try: `crate:: fn_mod::foo`
|
||||||
|
|
||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:171:13
|
--> $DIR/wildcard_imports.rs:170:13
|
||||||
|
|
|
|
||||||
LL | use super::*;
|
LL | use super::*;
|
||||||
| ^^^^^^^^ help: try: `super::foofoo`
|
| ^^^^^^^^ help: try: `super::foofoo`
|
||||||
|
|
||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:206:17
|
--> $DIR/wildcard_imports.rs:205:17
|
||||||
|
|
|
|
||||||
LL | use super::*;
|
LL | use super::*;
|
||||||
| ^^^^^^^^ help: try: `super::insidefoo`
|
| ^^^^^^^^ help: try: `super::insidefoo`
|
||||||
|
|
||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:214:13
|
--> $DIR/wildcard_imports.rs:213:13
|
||||||
|
|
|
|
||||||
LL | use super_imports::*;
|
LL | use super_imports::*;
|
||||||
| ^^^^^^^^^^^^^^^^ help: try: `super_imports::foofoo`
|
| ^^^^^^^^^^^^^^^^ help: try: `super_imports::foofoo`
|
||||||
|
|
||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:223:17
|
--> $DIR/wildcard_imports.rs:222:17
|
||||||
|
|
|
|
||||||
LL | use super::super::*;
|
LL | use super::super::*;
|
||||||
| ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
|
| ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
|
||||||
|
|
||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:232:13
|
--> $DIR/wildcard_imports.rs:231:13
|
||||||
|
|
|
|
||||||
LL | use super::super::super_imports::*;
|
LL | use super::super::super_imports::*;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`
|
||||||
|
|
||||||
error: usage of wildcard import
|
error: usage of wildcard import
|
||||||
--> $DIR/wildcard_imports.rs:240:13
|
--> $DIR/wildcard_imports.rs:239:13
|
||||||
|
|
|
|
||||||
LL | use super::*;
|
LL | use super::*;
|
||||||
| ^^^^^^^^ help: try: `super::foofoo`
|
| ^^^^^^^^ help: try: `super::foofoo`
|
||||||
|
240
tests/ui/wildcard_imports_2021.edition2018.fixed
Normal file
240
tests/ui/wildcard_imports_2021.edition2018.fixed
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
// revisions: edition2018 edition2021
|
||||||
|
//[edition2018] edition:2018
|
||||||
|
//[edition2021] edition:2021
|
||||||
|
// run-rustfix
|
||||||
|
// aux-build:wildcard_imports_helper.rs
|
||||||
|
|
||||||
|
#![warn(clippy::wildcard_imports)]
|
||||||
|
#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
|
||||||
|
#![warn(unused_imports)]
|
||||||
|
|
||||||
|
extern crate wildcard_imports_helper;
|
||||||
|
|
||||||
|
use crate::fn_mod::foo;
|
||||||
|
use crate::mod_mod::inner_mod;
|
||||||
|
use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod};
|
||||||
|
use crate::struct_mod::{A, inner_struct_mod};
|
||||||
|
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar;
|
||||||
|
use wildcard_imports_helper::prelude::v1::*;
|
||||||
|
use wildcard_imports_helper::{ExternA, extern_foo};
|
||||||
|
|
||||||
|
use std::io::prelude::*;
|
||||||
|
|
||||||
|
struct ReadFoo;
|
||||||
|
|
||||||
|
impl Read for ReadFoo {
|
||||||
|
fn read(&mut self, _buf: &mut [u8]) -> std::io::Result<usize> {
|
||||||
|
Ok(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod fn_mod {
|
||||||
|
pub fn foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod mod_mod {
|
||||||
|
pub mod inner_mod {
|
||||||
|
pub fn foo() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod multi_fn_mod {
|
||||||
|
pub fn multi_foo() {}
|
||||||
|
pub fn multi_bar() {}
|
||||||
|
pub fn multi_baz() {}
|
||||||
|
pub mod multi_inner_mod {
|
||||||
|
pub fn foo() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod struct_mod {
|
||||||
|
pub struct A;
|
||||||
|
pub struct B;
|
||||||
|
pub mod inner_struct_mod {
|
||||||
|
pub struct C;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! double_struct_import_test {
|
||||||
|
() => {
|
||||||
|
let _ = A;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
foo();
|
||||||
|
multi_foo();
|
||||||
|
multi_bar();
|
||||||
|
multi_inner_mod::foo();
|
||||||
|
inner_mod::foo();
|
||||||
|
extern_foo();
|
||||||
|
inner_extern_bar();
|
||||||
|
|
||||||
|
let _ = A;
|
||||||
|
let _ = inner_struct_mod::C;
|
||||||
|
let _ = ExternA;
|
||||||
|
let _ = PreludeModAnywhere;
|
||||||
|
|
||||||
|
double_struct_import_test!();
|
||||||
|
double_struct_import_test!();
|
||||||
|
}
|
||||||
|
|
||||||
|
mod in_fn_test {
|
||||||
|
pub use self::inner_exported::*;
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
pub(crate) use self::inner_exported2::*;
|
||||||
|
|
||||||
|
fn test_intern() {
|
||||||
|
use crate::fn_mod::foo;
|
||||||
|
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_extern() {
|
||||||
|
use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo};
|
||||||
|
use wildcard_imports_helper::{ExternA, extern_foo};
|
||||||
|
|
||||||
|
inner_for_self_import::inner_extern_foo();
|
||||||
|
inner_extern_foo();
|
||||||
|
|
||||||
|
extern_foo();
|
||||||
|
|
||||||
|
let _ = ExternA;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_inner_nested() {
|
||||||
|
use self::{inner::inner_foo, inner2::inner_bar};
|
||||||
|
|
||||||
|
inner_foo();
|
||||||
|
inner_bar();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_extern_reexported() {
|
||||||
|
use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported};
|
||||||
|
|
||||||
|
extern_exported();
|
||||||
|
let _ = ExternExportedStruct;
|
||||||
|
let _ = ExternExportedEnum::A;
|
||||||
|
}
|
||||||
|
|
||||||
|
mod inner_exported {
|
||||||
|
pub fn exported() {}
|
||||||
|
pub struct ExportedStruct;
|
||||||
|
pub enum ExportedEnum {
|
||||||
|
A,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod inner_exported2 {
|
||||||
|
pub(crate) fn exported2() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod inner {
|
||||||
|
pub fn inner_foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod inner2 {
|
||||||
|
pub fn inner_bar() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_reexported() {
|
||||||
|
use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported};
|
||||||
|
|
||||||
|
exported();
|
||||||
|
let _ = ExportedStruct;
|
||||||
|
let _ = ExportedEnum::A;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rustfmt::skip]
|
||||||
|
fn test_weird_formatting() {
|
||||||
|
use crate:: in_fn_test::exported;
|
||||||
|
use crate:: fn_mod::foo;
|
||||||
|
|
||||||
|
exported();
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
|
||||||
|
mod super_imports {
|
||||||
|
fn foofoo() {}
|
||||||
|
|
||||||
|
mod should_be_replaced {
|
||||||
|
use super::foofoo;
|
||||||
|
|
||||||
|
fn with_super() {
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod test_should_pass {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn with_super() {
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod test_should_pass_inside_function {
|
||||||
|
fn with_super_inside_function() {
|
||||||
|
use super::*;
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod test_should_pass_further_inside {
|
||||||
|
fn insidefoo() {}
|
||||||
|
mod inner {
|
||||||
|
use super::*;
|
||||||
|
fn with_super() {
|
||||||
|
let _ = insidefoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod should_be_replaced_further_inside {
|
||||||
|
fn insidefoo() {}
|
||||||
|
mod inner {
|
||||||
|
use super::insidefoo;
|
||||||
|
fn with_super() {
|
||||||
|
let _ = insidefoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod use_explicit_should_be_replaced {
|
||||||
|
use crate::super_imports::foofoo;
|
||||||
|
|
||||||
|
fn with_explicit() {
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod use_double_super_should_be_replaced {
|
||||||
|
mod inner {
|
||||||
|
use super::super::foofoo;
|
||||||
|
|
||||||
|
fn with_double_super() {
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod use_super_explicit_should_be_replaced {
|
||||||
|
use super::super::super_imports::foofoo;
|
||||||
|
|
||||||
|
fn with_super_explicit() {
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod attestation_should_be_replaced {
|
||||||
|
use super::foofoo;
|
||||||
|
|
||||||
|
fn with_explicit() {
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
132
tests/ui/wildcard_imports_2021.edition2018.stderr
Normal file
132
tests/ui/wildcard_imports_2021.edition2018.stderr
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:13:5
|
||||||
|
|
|
||||||
|
LL | use crate::fn_mod::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
|
||||||
|
|
|
||||||
|
= note: `-D clippy::wildcard-imports` implied by `-D warnings`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:14:5
|
||||||
|
|
|
||||||
|
LL | use crate::mod_mod::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^ help: try: `crate::mod_mod::inner_mod`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:15:5
|
||||||
|
|
|
||||||
|
LL | use crate::multi_fn_mod::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:16:5
|
||||||
|
|
|
||||||
|
LL | use crate::struct_mod::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::struct_mod::{A, inner_struct_mod}`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:19:5
|
||||||
|
|
|
||||||
|
LL | use wildcard_imports_helper::inner::inner_for_self_import::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:21:5
|
||||||
|
|
|
||||||
|
LL | use wildcard_imports_helper::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:91:13
|
||||||
|
|
|
||||||
|
LL | use crate::fn_mod::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:97:75
|
||||||
|
|
|
||||||
|
LL | use wildcard_imports_helper::inner::inner_for_self_import::{self, *};
|
||||||
|
| ^ help: try: `inner_extern_foo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:98:13
|
||||||
|
|
|
||||||
|
LL | use wildcard_imports_helper::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:109:20
|
||||||
|
|
|
||||||
|
LL | use self::{inner::*, inner2::*};
|
||||||
|
| ^^^^^^^^ help: try: `inner::inner_foo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:109:30
|
||||||
|
|
|
||||||
|
LL | use self::{inner::*, inner2::*};
|
||||||
|
| ^^^^^^^^^ help: try: `inner2::inner_bar`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:116:13
|
||||||
|
|
|
||||||
|
LL | use wildcard_imports_helper::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:145:9
|
||||||
|
|
|
||||||
|
LL | use crate::in_fn_test::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:154:9
|
||||||
|
|
|
||||||
|
LL | use crate:: in_fn_test:: * ;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:155:9
|
||||||
|
|
|
||||||
|
LL | use crate:: fn_mod::
|
||||||
|
| _________^
|
||||||
|
LL | | *;
|
||||||
|
| |_________^ help: try: `crate:: fn_mod::foo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:166:13
|
||||||
|
|
|
||||||
|
LL | use super::*;
|
||||||
|
| ^^^^^^^^ help: try: `super::foofoo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:201:17
|
||||||
|
|
|
||||||
|
LL | use super::*;
|
||||||
|
| ^^^^^^^^ help: try: `super::insidefoo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:209:13
|
||||||
|
|
|
||||||
|
LL | use crate::super_imports::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::super_imports::foofoo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:218:17
|
||||||
|
|
|
||||||
|
LL | use super::super::*;
|
||||||
|
| ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:227:13
|
||||||
|
|
|
||||||
|
LL | use super::super::super_imports::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:235:13
|
||||||
|
|
|
||||||
|
LL | use super::*;
|
||||||
|
| ^^^^^^^^ help: try: `super::foofoo`
|
||||||
|
|
||||||
|
error: aborting due to 21 previous errors
|
||||||
|
|
240
tests/ui/wildcard_imports_2021.edition2021.fixed
Normal file
240
tests/ui/wildcard_imports_2021.edition2021.fixed
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
// revisions: edition2018 edition2021
|
||||||
|
//[edition2018] edition:2018
|
||||||
|
//[edition2021] edition:2021
|
||||||
|
// run-rustfix
|
||||||
|
// aux-build:wildcard_imports_helper.rs
|
||||||
|
|
||||||
|
#![warn(clippy::wildcard_imports)]
|
||||||
|
#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
|
||||||
|
#![warn(unused_imports)]
|
||||||
|
|
||||||
|
extern crate wildcard_imports_helper;
|
||||||
|
|
||||||
|
use crate::fn_mod::foo;
|
||||||
|
use crate::mod_mod::inner_mod;
|
||||||
|
use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod};
|
||||||
|
use crate::struct_mod::{A, inner_struct_mod};
|
||||||
|
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar;
|
||||||
|
use wildcard_imports_helper::prelude::v1::*;
|
||||||
|
use wildcard_imports_helper::{ExternA, extern_foo};
|
||||||
|
|
||||||
|
use std::io::prelude::*;
|
||||||
|
|
||||||
|
struct ReadFoo;
|
||||||
|
|
||||||
|
impl Read for ReadFoo {
|
||||||
|
fn read(&mut self, _buf: &mut [u8]) -> std::io::Result<usize> {
|
||||||
|
Ok(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod fn_mod {
|
||||||
|
pub fn foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod mod_mod {
|
||||||
|
pub mod inner_mod {
|
||||||
|
pub fn foo() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod multi_fn_mod {
|
||||||
|
pub fn multi_foo() {}
|
||||||
|
pub fn multi_bar() {}
|
||||||
|
pub fn multi_baz() {}
|
||||||
|
pub mod multi_inner_mod {
|
||||||
|
pub fn foo() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod struct_mod {
|
||||||
|
pub struct A;
|
||||||
|
pub struct B;
|
||||||
|
pub mod inner_struct_mod {
|
||||||
|
pub struct C;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! double_struct_import_test {
|
||||||
|
() => {
|
||||||
|
let _ = A;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
foo();
|
||||||
|
multi_foo();
|
||||||
|
multi_bar();
|
||||||
|
multi_inner_mod::foo();
|
||||||
|
inner_mod::foo();
|
||||||
|
extern_foo();
|
||||||
|
inner_extern_bar();
|
||||||
|
|
||||||
|
let _ = A;
|
||||||
|
let _ = inner_struct_mod::C;
|
||||||
|
let _ = ExternA;
|
||||||
|
let _ = PreludeModAnywhere;
|
||||||
|
|
||||||
|
double_struct_import_test!();
|
||||||
|
double_struct_import_test!();
|
||||||
|
}
|
||||||
|
|
||||||
|
mod in_fn_test {
|
||||||
|
pub use self::inner_exported::*;
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
pub(crate) use self::inner_exported2::*;
|
||||||
|
|
||||||
|
fn test_intern() {
|
||||||
|
use crate::fn_mod::foo;
|
||||||
|
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_extern() {
|
||||||
|
use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo};
|
||||||
|
use wildcard_imports_helper::{ExternA, extern_foo};
|
||||||
|
|
||||||
|
inner_for_self_import::inner_extern_foo();
|
||||||
|
inner_extern_foo();
|
||||||
|
|
||||||
|
extern_foo();
|
||||||
|
|
||||||
|
let _ = ExternA;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_inner_nested() {
|
||||||
|
use self::{inner::inner_foo, inner2::inner_bar};
|
||||||
|
|
||||||
|
inner_foo();
|
||||||
|
inner_bar();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_extern_reexported() {
|
||||||
|
use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported};
|
||||||
|
|
||||||
|
extern_exported();
|
||||||
|
let _ = ExternExportedStruct;
|
||||||
|
let _ = ExternExportedEnum::A;
|
||||||
|
}
|
||||||
|
|
||||||
|
mod inner_exported {
|
||||||
|
pub fn exported() {}
|
||||||
|
pub struct ExportedStruct;
|
||||||
|
pub enum ExportedEnum {
|
||||||
|
A,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod inner_exported2 {
|
||||||
|
pub(crate) fn exported2() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod inner {
|
||||||
|
pub fn inner_foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod inner2 {
|
||||||
|
pub fn inner_bar() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_reexported() {
|
||||||
|
use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported};
|
||||||
|
|
||||||
|
exported();
|
||||||
|
let _ = ExportedStruct;
|
||||||
|
let _ = ExportedEnum::A;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rustfmt::skip]
|
||||||
|
fn test_weird_formatting() {
|
||||||
|
use crate:: in_fn_test::exported;
|
||||||
|
use crate:: fn_mod::foo;
|
||||||
|
|
||||||
|
exported();
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
|
||||||
|
mod super_imports {
|
||||||
|
fn foofoo() {}
|
||||||
|
|
||||||
|
mod should_be_replaced {
|
||||||
|
use super::foofoo;
|
||||||
|
|
||||||
|
fn with_super() {
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod test_should_pass {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn with_super() {
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod test_should_pass_inside_function {
|
||||||
|
fn with_super_inside_function() {
|
||||||
|
use super::*;
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod test_should_pass_further_inside {
|
||||||
|
fn insidefoo() {}
|
||||||
|
mod inner {
|
||||||
|
use super::*;
|
||||||
|
fn with_super() {
|
||||||
|
let _ = insidefoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod should_be_replaced_further_inside {
|
||||||
|
fn insidefoo() {}
|
||||||
|
mod inner {
|
||||||
|
use super::insidefoo;
|
||||||
|
fn with_super() {
|
||||||
|
let _ = insidefoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod use_explicit_should_be_replaced {
|
||||||
|
use crate::super_imports::foofoo;
|
||||||
|
|
||||||
|
fn with_explicit() {
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod use_double_super_should_be_replaced {
|
||||||
|
mod inner {
|
||||||
|
use super::super::foofoo;
|
||||||
|
|
||||||
|
fn with_double_super() {
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod use_super_explicit_should_be_replaced {
|
||||||
|
use super::super::super_imports::foofoo;
|
||||||
|
|
||||||
|
fn with_super_explicit() {
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod attestation_should_be_replaced {
|
||||||
|
use super::foofoo;
|
||||||
|
|
||||||
|
fn with_explicit() {
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
132
tests/ui/wildcard_imports_2021.edition2021.stderr
Normal file
132
tests/ui/wildcard_imports_2021.edition2021.stderr
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:13:5
|
||||||
|
|
|
||||||
|
LL | use crate::fn_mod::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
|
||||||
|
|
|
||||||
|
= note: `-D clippy::wildcard-imports` implied by `-D warnings`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:14:5
|
||||||
|
|
|
||||||
|
LL | use crate::mod_mod::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^ help: try: `crate::mod_mod::inner_mod`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:15:5
|
||||||
|
|
|
||||||
|
LL | use crate::multi_fn_mod::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:16:5
|
||||||
|
|
|
||||||
|
LL | use crate::struct_mod::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::struct_mod::{A, inner_struct_mod}`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:19:5
|
||||||
|
|
|
||||||
|
LL | use wildcard_imports_helper::inner::inner_for_self_import::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:21:5
|
||||||
|
|
|
||||||
|
LL | use wildcard_imports_helper::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:91:13
|
||||||
|
|
|
||||||
|
LL | use crate::fn_mod::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:97:75
|
||||||
|
|
|
||||||
|
LL | use wildcard_imports_helper::inner::inner_for_self_import::{self, *};
|
||||||
|
| ^ help: try: `inner_extern_foo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:98:13
|
||||||
|
|
|
||||||
|
LL | use wildcard_imports_helper::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:109:20
|
||||||
|
|
|
||||||
|
LL | use self::{inner::*, inner2::*};
|
||||||
|
| ^^^^^^^^ help: try: `inner::inner_foo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:109:30
|
||||||
|
|
|
||||||
|
LL | use self::{inner::*, inner2::*};
|
||||||
|
| ^^^^^^^^^ help: try: `inner2::inner_bar`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:116:13
|
||||||
|
|
|
||||||
|
LL | use wildcard_imports_helper::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:145:9
|
||||||
|
|
|
||||||
|
LL | use crate::in_fn_test::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:154:9
|
||||||
|
|
|
||||||
|
LL | use crate:: in_fn_test:: * ;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:155:9
|
||||||
|
|
|
||||||
|
LL | use crate:: fn_mod::
|
||||||
|
| _________^
|
||||||
|
LL | | *;
|
||||||
|
| |_________^ help: try: `crate:: fn_mod::foo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:166:13
|
||||||
|
|
|
||||||
|
LL | use super::*;
|
||||||
|
| ^^^^^^^^ help: try: `super::foofoo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:201:17
|
||||||
|
|
|
||||||
|
LL | use super::*;
|
||||||
|
| ^^^^^^^^ help: try: `super::insidefoo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:209:13
|
||||||
|
|
|
||||||
|
LL | use crate::super_imports::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::super_imports::foofoo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:218:17
|
||||||
|
|
|
||||||
|
LL | use super::super::*;
|
||||||
|
| ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:227:13
|
||||||
|
|
|
||||||
|
LL | use super::super::super_imports::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:235:13
|
||||||
|
|
|
||||||
|
LL | use super::*;
|
||||||
|
| ^^^^^^^^ help: try: `super::foofoo`
|
||||||
|
|
||||||
|
error: aborting due to 21 previous errors
|
||||||
|
|
241
tests/ui/wildcard_imports_2021.rs
Normal file
241
tests/ui/wildcard_imports_2021.rs
Normal file
@ -0,0 +1,241 @@
|
|||||||
|
// revisions: edition2018 edition2021
|
||||||
|
//[edition2018] edition:2018
|
||||||
|
//[edition2021] edition:2021
|
||||||
|
// run-rustfix
|
||||||
|
// aux-build:wildcard_imports_helper.rs
|
||||||
|
|
||||||
|
#![warn(clippy::wildcard_imports)]
|
||||||
|
#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
|
||||||
|
#![warn(unused_imports)]
|
||||||
|
|
||||||
|
extern crate wildcard_imports_helper;
|
||||||
|
|
||||||
|
use crate::fn_mod::*;
|
||||||
|
use crate::mod_mod::*;
|
||||||
|
use crate::multi_fn_mod::*;
|
||||||
|
use crate::struct_mod::*;
|
||||||
|
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
use wildcard_imports_helper::inner::inner_for_self_import::*;
|
||||||
|
use wildcard_imports_helper::prelude::v1::*;
|
||||||
|
use wildcard_imports_helper::*;
|
||||||
|
|
||||||
|
use std::io::prelude::*;
|
||||||
|
|
||||||
|
struct ReadFoo;
|
||||||
|
|
||||||
|
impl Read for ReadFoo {
|
||||||
|
fn read(&mut self, _buf: &mut [u8]) -> std::io::Result<usize> {
|
||||||
|
Ok(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod fn_mod {
|
||||||
|
pub fn foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod mod_mod {
|
||||||
|
pub mod inner_mod {
|
||||||
|
pub fn foo() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod multi_fn_mod {
|
||||||
|
pub fn multi_foo() {}
|
||||||
|
pub fn multi_bar() {}
|
||||||
|
pub fn multi_baz() {}
|
||||||
|
pub mod multi_inner_mod {
|
||||||
|
pub fn foo() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod struct_mod {
|
||||||
|
pub struct A;
|
||||||
|
pub struct B;
|
||||||
|
pub mod inner_struct_mod {
|
||||||
|
pub struct C;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! double_struct_import_test {
|
||||||
|
() => {
|
||||||
|
let _ = A;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
foo();
|
||||||
|
multi_foo();
|
||||||
|
multi_bar();
|
||||||
|
multi_inner_mod::foo();
|
||||||
|
inner_mod::foo();
|
||||||
|
extern_foo();
|
||||||
|
inner_extern_bar();
|
||||||
|
|
||||||
|
let _ = A;
|
||||||
|
let _ = inner_struct_mod::C;
|
||||||
|
let _ = ExternA;
|
||||||
|
let _ = PreludeModAnywhere;
|
||||||
|
|
||||||
|
double_struct_import_test!();
|
||||||
|
double_struct_import_test!();
|
||||||
|
}
|
||||||
|
|
||||||
|
mod in_fn_test {
|
||||||
|
pub use self::inner_exported::*;
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
pub(crate) use self::inner_exported2::*;
|
||||||
|
|
||||||
|
fn test_intern() {
|
||||||
|
use crate::fn_mod::*;
|
||||||
|
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_extern() {
|
||||||
|
use wildcard_imports_helper::inner::inner_for_self_import::{self, *};
|
||||||
|
use wildcard_imports_helper::*;
|
||||||
|
|
||||||
|
inner_for_self_import::inner_extern_foo();
|
||||||
|
inner_extern_foo();
|
||||||
|
|
||||||
|
extern_foo();
|
||||||
|
|
||||||
|
let _ = ExternA;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_inner_nested() {
|
||||||
|
use self::{inner::*, inner2::*};
|
||||||
|
|
||||||
|
inner_foo();
|
||||||
|
inner_bar();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_extern_reexported() {
|
||||||
|
use wildcard_imports_helper::*;
|
||||||
|
|
||||||
|
extern_exported();
|
||||||
|
let _ = ExternExportedStruct;
|
||||||
|
let _ = ExternExportedEnum::A;
|
||||||
|
}
|
||||||
|
|
||||||
|
mod inner_exported {
|
||||||
|
pub fn exported() {}
|
||||||
|
pub struct ExportedStruct;
|
||||||
|
pub enum ExportedEnum {
|
||||||
|
A,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod inner_exported2 {
|
||||||
|
pub(crate) fn exported2() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod inner {
|
||||||
|
pub fn inner_foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod inner2 {
|
||||||
|
pub fn inner_bar() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_reexported() {
|
||||||
|
use crate::in_fn_test::*;
|
||||||
|
|
||||||
|
exported();
|
||||||
|
let _ = ExportedStruct;
|
||||||
|
let _ = ExportedEnum::A;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rustfmt::skip]
|
||||||
|
fn test_weird_formatting() {
|
||||||
|
use crate:: in_fn_test:: * ;
|
||||||
|
use crate:: fn_mod::
|
||||||
|
*;
|
||||||
|
|
||||||
|
exported();
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
|
||||||
|
mod super_imports {
|
||||||
|
fn foofoo() {}
|
||||||
|
|
||||||
|
mod should_be_replaced {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn with_super() {
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod test_should_pass {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn with_super() {
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod test_should_pass_inside_function {
|
||||||
|
fn with_super_inside_function() {
|
||||||
|
use super::*;
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod test_should_pass_further_inside {
|
||||||
|
fn insidefoo() {}
|
||||||
|
mod inner {
|
||||||
|
use super::*;
|
||||||
|
fn with_super() {
|
||||||
|
let _ = insidefoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod should_be_replaced_further_inside {
|
||||||
|
fn insidefoo() {}
|
||||||
|
mod inner {
|
||||||
|
use super::*;
|
||||||
|
fn with_super() {
|
||||||
|
let _ = insidefoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod use_explicit_should_be_replaced {
|
||||||
|
use crate::super_imports::*;
|
||||||
|
|
||||||
|
fn with_explicit() {
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod use_double_super_should_be_replaced {
|
||||||
|
mod inner {
|
||||||
|
use super::super::*;
|
||||||
|
|
||||||
|
fn with_double_super() {
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod use_super_explicit_should_be_replaced {
|
||||||
|
use super::super::super_imports::*;
|
||||||
|
|
||||||
|
fn with_super_explicit() {
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod attestation_should_be_replaced {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn with_explicit() {
|
||||||
|
let _ = foofoo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
132
tests/ui/wildcard_imports_2021.stderr
Normal file
132
tests/ui/wildcard_imports_2021.stderr
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:9:5
|
||||||
|
|
|
||||||
|
LL | use crate::fn_mod::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
|
||||||
|
|
|
||||||
|
= note: `-D clippy::wildcard-imports` implied by `-D warnings`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:10:5
|
||||||
|
|
|
||||||
|
LL | use crate::mod_mod::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^ help: try: `crate::mod_mod::inner_mod`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:11:5
|
||||||
|
|
|
||||||
|
LL | use crate::multi_fn_mod::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:12:5
|
||||||
|
|
|
||||||
|
LL | use crate::struct_mod::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::struct_mod::{A, inner_struct_mod}`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:15:5
|
||||||
|
|
|
||||||
|
LL | use wildcard_imports_helper::inner::inner_for_self_import::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:17:5
|
||||||
|
|
|
||||||
|
LL | use wildcard_imports_helper::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:87:13
|
||||||
|
|
|
||||||
|
LL | use crate::fn_mod::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:93:75
|
||||||
|
|
|
||||||
|
LL | use wildcard_imports_helper::inner::inner_for_self_import::{self, *};
|
||||||
|
| ^ help: try: `inner_extern_foo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:94:13
|
||||||
|
|
|
||||||
|
LL | use wildcard_imports_helper::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:105:20
|
||||||
|
|
|
||||||
|
LL | use self::{inner::*, inner2::*};
|
||||||
|
| ^^^^^^^^ help: try: `inner::inner_foo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:105:30
|
||||||
|
|
|
||||||
|
LL | use self::{inner::*, inner2::*};
|
||||||
|
| ^^^^^^^^^ help: try: `inner2::inner_bar`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:112:13
|
||||||
|
|
|
||||||
|
LL | use wildcard_imports_helper::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:141:9
|
||||||
|
|
|
||||||
|
LL | use crate::in_fn_test::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:150:9
|
||||||
|
|
|
||||||
|
LL | use crate:: in_fn_test:: * ;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:151:9
|
||||||
|
|
|
||||||
|
LL | use crate:: fn_mod::
|
||||||
|
| _________^
|
||||||
|
LL | | *;
|
||||||
|
| |_________^ help: try: `crate:: fn_mod::foo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:162:13
|
||||||
|
|
|
||||||
|
LL | use super::*;
|
||||||
|
| ^^^^^^^^ help: try: `super::foofoo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:197:17
|
||||||
|
|
|
||||||
|
LL | use super::*;
|
||||||
|
| ^^^^^^^^ help: try: `super::insidefoo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:205:13
|
||||||
|
|
|
||||||
|
LL | use crate::super_imports::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::super_imports::foofoo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:214:17
|
||||||
|
|
|
||||||
|
LL | use super::super::*;
|
||||||
|
| ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:223:13
|
||||||
|
|
|
||||||
|
LL | use super::super::super_imports::*;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`
|
||||||
|
|
||||||
|
error: usage of wildcard import
|
||||||
|
--> $DIR/wildcard_imports_2021.rs:231:13
|
||||||
|
|
|
||||||
|
LL | use super::*;
|
||||||
|
| ^^^^^^^^ help: try: `super::foofoo`
|
||||||
|
|
||||||
|
error: aborting due to 21 previous errors
|
||||||
|
|
Loading…
Reference in New Issue
Block a user