move builtin_type_shadow to its own module
This commit is contained in:
parent
91a8611b44
commit
64eb18e675
19
clippy_lints/src/misc_early/builtin_type_shadow.rs
Normal file
19
clippy_lints/src/misc_early/builtin_type_shadow.rs
Normal file
@ -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()),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user