Skip to content

Commit

Permalink
Cleanup the code
Browse files Browse the repository at this point in the history
  • Loading branch information
popzxc committed Jun 22, 2021
1 parent 0f256d4 commit abf50bd
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 30 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/blacklisted_name.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clippy_utils::{diagnostics::span_lint, test_module::is_test_module_or_function};
use clippy_utils::{diagnostics::span_lint, is_test_module_or_function};
use rustc_data_structures::fx::FxHashSet;
use rustc_hir::{Item, Pat, PatKind};
use rustc_lint::{LateContext, LateLintPass};
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/wildcard_imports.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::in_macro;
use clippy_utils::source::{snippet, snippet_with_applicability};
use clippy_utils::test_module::is_test_module_or_function;
use clippy_utils::{in_macro, is_test_module_or_function};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::{
Expand Down
13 changes: 12 additions & 1 deletion clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ pub mod ptr;
pub mod qualify_min_const_fn;
pub mod source;
pub mod sugg;
pub mod test_module;
pub mod ty;
pub mod usage;
pub mod visitors;
Expand Down Expand Up @@ -1728,3 +1727,15 @@ pub fn is_hir_ty_cfg_dependant(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
}
}
}

/// Checks whether item either has `test` attribute applied, or
/// is a module with `test` in its name.
pub fn is_test_module_or_function(tcx: TyCtxt<'_>, item: &Item<'_>) -> bool {
if let Some(def_id) = tcx.hir().opt_local_def_id(item.hir_id()) {
if tcx.has_attr(def_id.to_def_id(), sym::test) {
return true;
}
}

matches!(item.kind, ItemKind::Mod(..)) && item.ident.name.as_str().contains("test")
}
13 changes: 0 additions & 13 deletions clippy_utils/src/test_module.rs

This file was deleted.

4 changes: 0 additions & 4 deletions tests/ui/blacklisted_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ mod tests {
// `blackisted_name` lint should not be triggered inside of the test code.
let foo = 0;

// However, we an additional problematic code here that triggers another lint
// just to ensure that this code was compiled & processed.
let nOn_SnakeCase_ident = 10u8;

// Check that even in nested functions warning is still not triggere.
fn nested() {
let foo = 0;
Expand Down
10 changes: 1 addition & 9 deletions tests/ui/blacklisted_name.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,5 @@ error: use of a blacklisted/placeholder name `quux`
LL | if let Some(ref mut quux) = Some(42) {}
| ^^^^

error: variable `nOn_SnakeCase_ident` should have a snake case name
--> $DIR/blacklisted_name.rs:54:13
|
LL | let nOn_SnakeCase_ident = 10u8;
| ^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `n_on_snake_case_ident`
|
= note: `-D non-snake-case` implied by `-D warnings`

error: aborting due to 15 previous errors
error: aborting due to 14 previous errors

0 comments on commit abf50bd

Please sign in to comment.