Do not lint when imported item contains underscore

This commit is contained in:
koka 2023-02-06 21:09:39 +09:00
parent bf4c998179
commit fab90003b8
No known key found for this signature in database
GPG key ID: A5917A40697774CD
9 changed files with 207 additions and 48 deletions

View file

@ -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);

View file

@ -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::*;
let _ = (&0).deref();
dummy();
}
fn does_lint() {
use self::exports_underscore_ish::{_Deref, dummy};
let _ = (&0).deref();
dummy();
}
}
fn main() {
foo();
multi_foo();

View file

@ -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::*;
let _ = (&0).deref();
dummy();
}
fn does_lint() {
use self::exports_underscore_ish::*;
let _ = (&0).deref();
dummy();
}
}
fn main() {
foo();
multi_foo();

View file

@ -38,55 +38,61 @@ 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::
| _________^
@ -94,40 +100,40 @@ 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

View file

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

View file

@ -38,55 +38,61 @@ 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::
| _________^
@ -94,40 +100,40 @@ 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

View file

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

View file

@ -38,55 +38,61 @@ 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::
| _________^
@ -94,40 +100,40 @@ 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

View file

@ -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::*;
let _ = (&0).deref();
dummy();
}
}
fn main() {
foo();
multi_foo();