Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 64eb18e

Browse files
committed
move builtin_type_shadow to its own module
1 parent 91a8611 commit 64eb18e

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use clippy_utils::diagnostics::span_lint;
2+
use rustc_ast::ast::{GenericParam, GenericParamKind};
3+
use rustc_hir::PrimTy;
4+
use rustc_lint::EarlyContext;
5+
6+
use super::BUILTIN_TYPE_SHADOW;
7+
8+
pub(super) fn check(cx: &EarlyContext<'_>, param: &GenericParam) {
9+
if let GenericParamKind::Type { .. } = param.kind {
10+
if let Some(prim_ty) = PrimTy::from_name(param.ident.name) {
11+
span_lint(
12+
cx,
13+
BUILTIN_TYPE_SHADOW,
14+
param.ident.span,
15+
&format!("this generic shadows the built-in type `{}`", prim_ty.name()),
16+
);
17+
}
18+
}
19+
}

clippy_lints/src/misc_early/mod.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
mod builtin_type_shadow;
2+
13
use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then};
24
use clippy_utils::source::snippet_opt;
35
use rustc_ast::ast::{
4-
BindingMode, Expr, ExprKind, GenericParamKind, Generics, Lit, LitFloatType, LitIntType, LitKind, Mutability,
5-
NodeId, Pat, PatKind, UnOp,
6+
BindingMode, Expr, ExprKind, Generics, Lit, LitFloatType, LitIntType, LitKind, Mutability, NodeId, Pat, PatKind,
7+
UnOp,
68
};
79
use rustc_ast::visit::FnKind;
810
use rustc_data_structures::fx::FxHashMap;
911
use rustc_errors::Applicability;
10-
use rustc_hir::PrimTy;
1112
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
1213
use rustc_middle::lint::in_external_macro;
1314
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -265,16 +266,7 @@ declare_lint_pass!(MiscEarlyLints => [
265266
impl EarlyLintPass for MiscEarlyLints {
266267
fn check_generics(&mut self, cx: &EarlyContext<'_>, gen: &Generics) {
267268
for param in &gen.params {
268-
if let GenericParamKind::Type { .. } = param.kind {
269-
if let Some(prim_ty) = PrimTy::from_name(param.ident.name) {
270-
span_lint(
271-
cx,
272-
BUILTIN_TYPE_SHADOW,
273-
param.ident.span,
274-
&format!("this generic shadows the built-in type `{}`", prim_ty.name()),
275-
);
276-
}
277-
}
269+
builtin_type_shadow::check(cx, param);
278270
}
279271
}
280272

File renamed without changes.

tests/ui/builtin-type-shadow.stderr renamed to tests/ui/builtin_type_shadow.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: this generic shadows the built-in type `u32`
2-
--> $DIR/builtin-type-shadow.rs:4:8
2+
--> $DIR/builtin_type_shadow.rs:4:8
33
|
44
LL | fn foo<u32>(a: u32) -> u32 {
55
| ^^^
66
|
77
= note: `-D clippy::builtin-type-shadow` implied by `-D warnings`
88

99
error[E0308]: mismatched types
10-
--> $DIR/builtin-type-shadow.rs:5:5
10+
--> $DIR/builtin_type_shadow.rs:5:5
1111
|
1212
LL | fn foo<u32>(a: u32) -> u32 {
1313
| --- --- expected `u32` because of return type

0 commit comments

Comments
 (0)