about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTakayuki <takoyaki0316@gmail.com>2021-05-04 17:04:10 +0900
committerTakayuki <takoyaki0316@gmail.com>2021-05-04 17:04:10 +0900
commit64eb18e6759f4375d01d7e3352447ff6b4305184 (patch)
tree8ecf61ec757bc41fee0faec18aa345524339d05c
parent91a8611b4426c7da8c72317516626affb812d20b (diff)
downloadrust-64eb18e6759f4375d01d7e3352447ff6b4305184.tar.gz
rust-64eb18e6759f4375d01d7e3352447ff6b4305184.zip
move builtin_type_shadow to its own module
-rw-r--r--clippy_lints/src/misc_early/builtin_type_shadow.rs19
-rw-r--r--clippy_lints/src/misc_early/mod.rs18
-rw-r--r--tests/ui/builtin_type_shadow.rs (renamed from tests/ui/builtin-type-shadow.rs)0
-rw-r--r--tests/ui/builtin_type_shadow.stderr (renamed from tests/ui/builtin-type-shadow.stderr)4
4 files changed, 26 insertions, 15 deletions
diff --git a/clippy_lints/src/misc_early/builtin_type_shadow.rs b/clippy_lints/src/misc_early/builtin_type_shadow.rs
new file mode 100644
index 00000000000..9f6b0bdc7a4
--- /dev/null
+++ b/clippy_lints/src/misc_early/builtin_type_shadow.rs
@@ -0,0 +1,19 @@
+use clippy_utils::diagnostics::span_lint;
+use rustc_ast::ast::{GenericParam, GenericParamKind};
+use rustc_hir::PrimTy;
+use rustc_lint::EarlyContext;
+
+use super::BUILTIN_TYPE_SHADOW;
+
+pub(super) fn check(cx: &EarlyContext<'_>, param: &GenericParam) {
+    if let GenericParamKind::Type { .. } = param.kind {
+        if let Some(prim_ty) = PrimTy::from_name(param.ident.name) {
+            span_lint(
+                cx,
+                BUILTIN_TYPE_SHADOW,
+                param.ident.span,
+                &format!("this generic shadows the built-in type `{}`", prim_ty.name()),
+            );
+        }
+    }
+}
diff --git a/clippy_lints/src/misc_early/mod.rs b/clippy_lints/src/misc_early/mod.rs
index 3c6a7071c24..94740093d3b 100644
--- a/clippy_lints/src/misc_early/mod.rs
+++ b/clippy_lints/src/misc_early/mod.rs
@@ -1,13 +1,14 @@
+mod builtin_type_shadow;
+
 use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then};
 use clippy_utils::source::snippet_opt;
 use rustc_ast::ast::{
-    BindingMode, Expr, ExprKind, GenericParamKind, Generics, Lit, LitFloatType, LitIntType, LitKind, Mutability,
-    NodeId, Pat, PatKind, UnOp,
+    BindingMode, Expr, ExprKind, Generics, Lit, LitFloatType, LitIntType, LitKind, Mutability, NodeId, Pat, PatKind,
+    UnOp,
 };
 use rustc_ast::visit::FnKind;
 use rustc_data_structures::fx::FxHashMap;
 use rustc_errors::Applicability;
-use rustc_hir::PrimTy;
 use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
 use rustc_middle::lint::in_external_macro;
 use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -265,16 +266,7 @@ declare_lint_pass!(MiscEarlyLints => [
 impl EarlyLintPass for MiscEarlyLints {
     fn check_generics(&mut self, cx: &EarlyContext<'_>, gen: &Generics) {
         for param in &gen.params {
-            if let GenericParamKind::Type { .. } = param.kind {
-                if let Some(prim_ty) = PrimTy::from_name(param.ident.name) {
-                    span_lint(
-                        cx,
-                        BUILTIN_TYPE_SHADOW,
-                        param.ident.span,
-                        &format!("this generic shadows the built-in type `{}`", prim_ty.name()),
-                    );
-                }
-            }
+            builtin_type_shadow::check(cx, param);
         }
     }
 
diff --git a/tests/ui/builtin-type-shadow.rs b/tests/ui/builtin_type_shadow.rs
index 69b8b6a0e68..69b8b6a0e68 100644
--- a/tests/ui/builtin-type-shadow.rs
+++ b/tests/ui/builtin_type_shadow.rs
diff --git a/tests/ui/builtin-type-shadow.stderr b/tests/ui/builtin_type_shadow.stderr
index f42b246afd2..47a8a1e623e 100644
--- a/tests/ui/builtin-type-shadow.stderr
+++ b/tests/ui/builtin_type_shadow.stderr
@@ -1,5 +1,5 @@
 error: this generic shadows the built-in type `u32`
-  --> $DIR/builtin-type-shadow.rs:4:8
+  --> $DIR/builtin_type_shadow.rs:4:8
    |
 LL | fn foo<u32>(a: u32) -> u32 {
    |        ^^^
@@ -7,7 +7,7 @@ LL | fn foo<u32>(a: u32) -> u32 {
    = note: `-D clippy::builtin-type-shadow` implied by `-D warnings`
 
 error[E0308]: mismatched types
-  --> $DIR/builtin-type-shadow.rs:5:5
+  --> $DIR/builtin_type_shadow.rs:5:5
    |
 LL | fn foo<u32>(a: u32) -> u32 {
    |        ---             --- expected `u32` because of return type