mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-03-01 13:57:21 +00:00
Now the lint ignores any crates with --cfg test
This commit is contained in:
parent
5acc2993e7
commit
ba0e7e88cb
6 changed files with 7 additions and 74 deletions
|
@ -7,7 +7,6 @@ use rustc_hir::{
|
||||||
def::{DefKind, Res},
|
def::{DefKind, Res},
|
||||||
Item, ItemKind, PathSegment, UseKind,
|
Item, ItemKind, PathSegment, UseKind,
|
||||||
};
|
};
|
||||||
use rustc_hir::{HirId, Mod};
|
|
||||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||||
|
@ -119,15 +118,10 @@ impl WildcardImports {
|
||||||
impl_lint_pass!(WildcardImports => [ENUM_GLOB_USE, WILDCARD_IMPORTS]);
|
impl_lint_pass!(WildcardImports => [ENUM_GLOB_USE, WILDCARD_IMPORTS]);
|
||||||
|
|
||||||
impl LateLintPass<'_> for WildcardImports {
|
impl LateLintPass<'_> for WildcardImports {
|
||||||
fn check_mod(&mut self, cx: &LateContext<'_>, module: &Mod<'_>, _: HirId) {
|
fn check_crate(&mut self, cx: &LateContext<'_>) {
|
||||||
let filename = cx
|
if cx.sess().opts.test {
|
||||||
.sess()
|
self.ignore = true;
|
||||||
.source_map()
|
}
|
||||||
.span_to_filename(module.spans.inner_span)
|
|
||||||
.display(rustc_span::FileNameDisplayPreference::Local)
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
self.ignore = filename.ends_with("test.rs") || filename.ends_with("tests.rs");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
// run-rustfix
|
|
||||||
#![warn(clippy::wildcard_imports)]
|
|
||||||
#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
|
|
||||||
|
|
||||||
// Test for #10580, the lint should **not** ignore it.
|
|
||||||
|
|
||||||
fn foofoo() {}
|
|
||||||
|
|
||||||
mod outer {
|
|
||||||
mod inner {
|
|
||||||
use super::super::foofoo;
|
|
||||||
fn barbar() {
|
|
||||||
let _ = foofoo();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
|
@ -1,10 +0,0 @@
|
||||||
error: usage of wildcard import
|
|
||||||
--> $DIR/another_file.rs:11:13
|
|
||||||
|
|
|
||||||
LL | use super::super::*;
|
|
||||||
| ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
|
|
||||||
|
|
|
||||||
= note: `-D clippy::wildcard-imports` implied by `-D warnings`
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
#![warn(clippy::wildcard_imports)]
|
|
||||||
#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
|
|
||||||
|
|
||||||
// Test for #10580, the lint **should** not ignore it.
|
|
||||||
|
|
||||||
fn foofoo() {}
|
|
||||||
|
|
||||||
mod outer {
|
|
||||||
mod inner {
|
|
||||||
use super::super::*;
|
|
||||||
fn barbar() {
|
|
||||||
let _ = foofoo();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
|
@ -1,17 +0,0 @@
|
||||||
#![warn(clippy::wildcard_imports)]
|
|
||||||
#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
|
|
||||||
|
|
||||||
// Test for #10580, the lint **should** ignore it.
|
|
||||||
|
|
||||||
fn foofoo() {}
|
|
||||||
|
|
||||||
mod outer {
|
|
||||||
mod inner {
|
|
||||||
use super::super::*;
|
|
||||||
fn barbar() {
|
|
||||||
let _ = foofoo();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
|
@ -1,8 +1,9 @@
|
||||||
// run-rustfix
|
// compile-flags: --test
|
||||||
|
|
||||||
#![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)]
|
||||||
|
|
||||||
// Test for #10580, the lint should **not** ignore it.
|
// Test for #10580, the lint should ignore it because of the crate's cfg test flag.
|
||||||
|
|
||||||
fn foofoo() {}
|
fn foofoo() {}
|
||||||
|
|
Loading…
Add table
Reference in a new issue