Skip to content
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

Do not lint when imported item contains underscore #10300

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clippy_lints/src/wildcard_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ impl LateLintPass<'_> for WildcardImports {
if self.warn_on_all || !self.check_exceptions(item, use_path.segments);
let used_imports = cx.tcx.names_imported_by_glob_use(item.owner_id.def_id);
if !used_imports.is_empty(); // Already handled by `unused_imports`
if !used_imports.contains(&kw::Underscore);
then {
let mut applicability = Applicability::MachineApplicable;
let import_source_snippet = snippet_with_applicability(cx, use_path.span, "..", &mut applicability);
Expand Down
28 changes: 28 additions & 0 deletions tests/ui/wildcard_imports.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,34 @@ mod struct_mod {
}
}

// issue 9942
mod underscore_mod {
// allow use of `deref` so that `clippy --fix` includes `Deref`.
#![allow(noop_method_call)]
xFrednet marked this conversation as resolved.
Show resolved Hide resolved

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();
}
}

fn main() {
foo();
multi_foo();
Expand Down
28 changes: 28 additions & 0 deletions tests/ui/wildcard_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,34 @@ mod struct_mod {
}
}

// 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::*;
xFrednet marked this conversation as resolved.
Show resolved Hide resolved
let _ = (&0).deref();
dummy();
}

fn does_lint() {
use self::exports_underscore_ish::*;
let _ = (&0).deref();
dummy();
}
}

fn main() {
foo();
multi_foo();
Expand Down
38 changes: 22 additions & 16 deletions tests/ui/wildcard_imports.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -38,96 +38,102 @@ LL | use wildcard_imports_helper::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`

error: usage of wildcard import
--> $DIR/wildcard_imports.rs:97:13
--> $DIR/wildcard_imports.rs:94:13
|
LL | use self::exports_underscore_ish::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `self::exports_underscore_ish::{_Deref, dummy}`

error: usage of wildcard import
--> $DIR/wildcard_imports.rs:125:13
|
LL | use crate::fn_mod::*;
| ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`

error: usage of wildcard import
--> $DIR/wildcard_imports.rs:103:75
--> $DIR/wildcard_imports.rs:131: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.rs:104:13
--> $DIR/wildcard_imports.rs:132:13
|
LL | use wildcard_imports_helper::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`

error: usage of wildcard import
--> $DIR/wildcard_imports.rs:116:20
--> $DIR/wildcard_imports.rs:144:20
|
LL | use self::{inner::*, inner2::*};
| ^^^^^^^^ help: try: `inner::inner_foo`

error: usage of wildcard import
--> $DIR/wildcard_imports.rs:116:30
--> $DIR/wildcard_imports.rs:144:30
|
LL | use self::{inner::*, inner2::*};
| ^^^^^^^^^ help: try: `inner2::inner_bar`

error: usage of wildcard import
--> $DIR/wildcard_imports.rs:123:13
--> $DIR/wildcard_imports.rs:151:13
|
LL | use wildcard_imports_helper::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}`

error: usage of wildcard import
--> $DIR/wildcard_imports.rs:152:9
--> $DIR/wildcard_imports.rs:180:9
|
LL | use crate::in_fn_test::*;
| ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}`

error: usage of wildcard import
--> $DIR/wildcard_imports.rs:161:9
--> $DIR/wildcard_imports.rs:189:9
|
LL | use crate:: in_fn_test:: * ;
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported`

error: usage of wildcard import
--> $DIR/wildcard_imports.rs:162:9
--> $DIR/wildcard_imports.rs:190:9
|
LL | use crate:: fn_mod::
| _________^
LL | | *;
| |_________^ help: try: `crate:: fn_mod::foo`

error: usage of wildcard import
--> $DIR/wildcard_imports.rs:173:13
--> $DIR/wildcard_imports.rs:201:13
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::foofoo`

error: usage of wildcard import
--> $DIR/wildcard_imports.rs:208:17
--> $DIR/wildcard_imports.rs:236:17
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::insidefoo`

error: usage of wildcard import
--> $DIR/wildcard_imports.rs:216:13
--> $DIR/wildcard_imports.rs:244:13
|
LL | use crate::super_imports::*;
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::super_imports::foofoo`

error: usage of wildcard import
--> $DIR/wildcard_imports.rs:225:17
--> $DIR/wildcard_imports.rs:253:17
|
LL | use super::super::*;
| ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`

error: usage of wildcard import
--> $DIR/wildcard_imports.rs:234:13
--> $DIR/wildcard_imports.rs:262:13
|
LL | use super::super::super_imports::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`

error: usage of wildcard import
--> $DIR/wildcard_imports.rs:242:13
--> $DIR/wildcard_imports.rs:270:13
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::foofoo`

error: aborting due to 21 previous errors
error: aborting due to 22 previous errors

28 changes: 28 additions & 0 deletions tests/ui/wildcard_imports_2021.edition2018.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,34 @@ mod struct_mod {
}
}

// 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 exports_underscore::*;
let _ = (&0).deref();
dummy();
}

fn does_lint() {
use exports_underscore_ish::{_Deref, dummy};
let _ = (&0).deref();
dummy();
}
}

fn main() {
foo();
multi_foo();
Expand Down
38 changes: 22 additions & 16 deletions tests/ui/wildcard_imports_2021.edition2018.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -38,96 +38,102 @@ 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
--> $DIR/wildcard_imports_2021.rs:89:13
|
LL | use exports_underscore_ish::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `exports_underscore_ish::{_Deref, dummy}`

error: usage of wildcard import
--> $DIR/wildcard_imports_2021.rs:119:13
|
LL | use crate::fn_mod::*;
| ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`

error: usage of wildcard import
--> $DIR/wildcard_imports_2021.rs:97:75
--> $DIR/wildcard_imports_2021.rs:125: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
--> $DIR/wildcard_imports_2021.rs:126:13
|
LL | use wildcard_imports_helper::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`

error: usage of wildcard import
--> $DIR/wildcard_imports_2021.rs:110:20
--> $DIR/wildcard_imports_2021.rs:138:20
|
LL | use self::{inner::*, inner2::*};
| ^^^^^^^^ help: try: `inner::inner_foo`

error: usage of wildcard import
--> $DIR/wildcard_imports_2021.rs:110:30
--> $DIR/wildcard_imports_2021.rs:138:30
|
LL | use self::{inner::*, inner2::*};
| ^^^^^^^^^ help: try: `inner2::inner_bar`

error: usage of wildcard import
--> $DIR/wildcard_imports_2021.rs:117:13
--> $DIR/wildcard_imports_2021.rs:145: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:146:9
--> $DIR/wildcard_imports_2021.rs:174: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:155:9
--> $DIR/wildcard_imports_2021.rs:183:9
|
LL | use crate:: in_fn_test:: * ;
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported`

error: usage of wildcard import
--> $DIR/wildcard_imports_2021.rs:156:9
--> $DIR/wildcard_imports_2021.rs:184:9
|
LL | use crate:: fn_mod::
| _________^
LL | | *;
| |_________^ help: try: `crate:: fn_mod::foo`

error: usage of wildcard import
--> $DIR/wildcard_imports_2021.rs:167:13
--> $DIR/wildcard_imports_2021.rs:195:13
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::foofoo`

error: usage of wildcard import
--> $DIR/wildcard_imports_2021.rs:202:17
--> $DIR/wildcard_imports_2021.rs:230:17
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::insidefoo`

error: usage of wildcard import
--> $DIR/wildcard_imports_2021.rs:210:13
--> $DIR/wildcard_imports_2021.rs:238:13
|
LL | use crate::super_imports::*;
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::super_imports::foofoo`

error: usage of wildcard import
--> $DIR/wildcard_imports_2021.rs:219:17
--> $DIR/wildcard_imports_2021.rs:247:17
|
LL | use super::super::*;
| ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`

error: usage of wildcard import
--> $DIR/wildcard_imports_2021.rs:228:13
--> $DIR/wildcard_imports_2021.rs:256:13
|
LL | use super::super::super_imports::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`

error: usage of wildcard import
--> $DIR/wildcard_imports_2021.rs:236:13
--> $DIR/wildcard_imports_2021.rs:264:13
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::foofoo`

error: aborting due to 21 previous errors
error: aborting due to 22 previous errors

28 changes: 28 additions & 0 deletions tests/ui/wildcard_imports_2021.edition2021.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,34 @@ mod struct_mod {
}
}

// 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 exports_underscore::*;
let _ = (&0).deref();
dummy();
}

fn does_lint() {
use exports_underscore_ish::{_Deref, dummy};
let _ = (&0).deref();
dummy();
}
}

fn main() {
foo();
multi_foo();
Expand Down
Loading