2023-04-23 11:03:09 +00:00
|
|
|
//@edition:2015
|
2023-08-24 19:32:12 +00:00
|
|
|
|
2023-04-23 11:03:09 +00:00
|
|
|
//@aux-build:wildcard_imports_helper.rs
|
2020-01-07 16:53:33 +00:00
|
|
|
|
2021-11-04 12:52:36 +00:00
|
|
|
// 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
|
|
|
|
// no longer detects some of the cases starting with Rust 2018.
|
|
|
|
|
2020-01-07 16:53:33 +00:00
|
|
|
#![warn(clippy::wildcard_imports)]
|
2022-05-05 14:12:52 +00:00
|
|
|
#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
|
2020-01-07 16:53:33 +00:00
|
|
|
#![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};
|
|
|
|
#[macro_use]
|
|
|
|
use crate::struct_mod::{A, inner_struct_mod};
|
|
|
|
|
|
|
|
#[allow(unused_imports)]
|
|
|
|
use wildcard_imports_helper::inner::inner_for_self_import;
|
|
|
|
use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar;
|
|
|
|
use wildcard_imports_helper::{ExternA, extern_foo};
|
|
|
|
|
2020-02-09 11:55:20 +00:00
|
|
|
use std::io::prelude::*;
|
2023-06-02 09:41:57 +00:00
|
|
|
use wildcard_imports_helper::extern_prelude::v1::*;
|
2020-08-28 14:10:16 +00:00
|
|
|
use wildcard_imports_helper::prelude::v1::*;
|
2020-02-09 11:55:20 +00:00
|
|
|
|
|
|
|
struct ReadFoo;
|
|
|
|
|
|
|
|
impl Read for ReadFoo {
|
|
|
|
fn read(&mut self, _buf: &mut [u8]) -> std::io::Result<usize> {
|
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-07 16:53:33 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-06 15:35:45 +00:00
|
|
|
// issue 9942
|
|
|
|
mod underscore_mod {
|
|
|
|
// allow use of `deref` so that `clippy --fix` includes `Deref`.
|
|
|
|
#![allow(noop_method_call)]
|
|
|
|
|
|
|
|
mod exports_underscore {
|
|
|
|
pub use std::ops::Deref as _;
|
|
|
|
pub fn dummy() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
mod exports_underscore_ish {
|
|
|
|
pub use std::ops::Deref as _Deref;
|
|
|
|
pub fn dummy() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn does_not_lint() {
|
|
|
|
use self::exports_underscore::*;
|
|
|
|
let _ = (&0).deref();
|
|
|
|
dummy();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn does_lint() {
|
|
|
|
use self::exports_underscore_ish::{_Deref, dummy};
|
|
|
|
let _ = (&0).deref();
|
|
|
|
dummy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-07 16:53:33 +00:00
|
|
|
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;
|
2020-08-28 14:10:16 +00:00
|
|
|
let _ = PreludeModAnywhere;
|
2023-06-02 09:41:57 +00:00
|
|
|
let _ = ExternPreludeModAnywhere;
|
2020-01-07 16:53:33 +00:00
|
|
|
|
|
|
|
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() {
|
2023-07-17 08:19:29 +00:00
|
|
|
#[rustfmt::skip]
|
2020-01-07 16:53:33 +00:00
|
|
|
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;
|
|
|
|
}
|
2020-02-21 09:15:38 +00:00
|
|
|
|
|
|
|
#[rustfmt::skip]
|
|
|
|
fn test_weird_formatting() {
|
|
|
|
use crate:: in_fn_test::exported;
|
|
|
|
use crate:: fn_mod::foo;
|
|
|
|
|
|
|
|
exported();
|
|
|
|
foo();
|
|
|
|
}
|
2020-05-11 18:23:47 +00:00
|
|
|
|
|
|
|
mod super_imports {
|
|
|
|
fn foofoo() {}
|
|
|
|
|
|
|
|
mod should_be_replaced {
|
|
|
|
use super::foofoo;
|
|
|
|
|
|
|
|
fn with_super() {
|
|
|
|
let _ = foofoo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-11 13:44:03 +00:00
|
|
|
#[cfg(test)]
|
2020-05-11 18:23:47 +00:00
|
|
|
mod test_should_pass {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
fn with_super() {
|
|
|
|
let _ = foofoo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-11 13:44:03 +00:00
|
|
|
#[cfg(test)]
|
2020-05-11 18:23:47 +00:00
|
|
|
mod test_should_pass_inside_function {
|
|
|
|
fn with_super_inside_function() {
|
|
|
|
use super::*;
|
|
|
|
let _ = foofoo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-11 13:44:03 +00:00
|
|
|
#[cfg(test)]
|
2020-05-11 18:23:47 +00:00
|
|
|
mod test_should_pass_further_inside {
|
|
|
|
fn insidefoo() {}
|
|
|
|
mod inner {
|
|
|
|
use super::*;
|
|
|
|
fn with_super() {
|
|
|
|
let _ = insidefoo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-18 07:39:37 +00:00
|
|
|
mod should_be_replaced_further_inside {
|
2020-05-11 18:23:47 +00:00
|
|
|
fn insidefoo() {}
|
|
|
|
mod inner {
|
|
|
|
use super::insidefoo;
|
|
|
|
fn with_super() {
|
|
|
|
let _ = insidefoo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mod use_explicit_should_be_replaced {
|
2023-07-02 12:35:19 +00:00
|
|
|
use crate::super_imports::foofoo;
|
2020-05-11 18:23:47 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2021-10-21 11:11:36 +00:00
|
|
|
|
|
|
|
mod attestation_should_be_replaced {
|
|
|
|
use super::foofoo;
|
|
|
|
|
|
|
|
fn with_explicit() {
|
|
|
|
let _ = foofoo();
|
|
|
|
}
|
|
|
|
}
|
2020-05-11 18:23:47 +00:00
|
|
|
}
|