Skip to content

Commit 7191675

Browse files
committed
Auto merge of #7166 - TaKO8Ki:refactor_misc_early_module, r=llogiq
Refactor: arrange lints in misc_early module This PR arranges misc_early lints so that they can be accessed more easily. Basically, I refactored them following the instruction described in #6680. cc: `@Y-Nak,` `@flip1995,` `@magurotuna` changelog: Move lints in misc_early module into their own modules.
2 parents 9dd8705 + 3fbb060 commit 7191675

12 files changed

+636
-571
lines changed

clippy_lints/src/misc_early.rs

-569
This file was deleted.
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+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use super::MiscEarlyLints;
2+
use clippy_utils::diagnostics::span_lint;
3+
use rustc_ast::ast::{Expr, ExprKind, UnOp};
4+
use rustc_lint::EarlyContext;
5+
6+
use super::DOUBLE_NEG;
7+
8+
pub(super) fn check(cx: &EarlyContext<'_>, expr: &Expr) {
9+
match expr.kind {
10+
ExprKind::Unary(UnOp::Neg, ref inner) => {
11+
if let ExprKind::Unary(UnOp::Neg, _) = inner.kind {
12+
span_lint(
13+
cx,
14+
DOUBLE_NEG,
15+
expr.span,
16+
"`--x` could be misinterpreted as pre-decrement by C programmers, is usually a no-op",
17+
);
18+
}
19+
},
20+
ExprKind::Lit(ref lit) => MiscEarlyLints::check_lit(cx, lit),
21+
_ => (),
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use clippy_utils::diagnostics::span_lint;
2+
use rustc_ast::ast::Lit;
3+
use rustc_lint::EarlyContext;
4+
5+
use super::MIXED_CASE_HEX_LITERALS;
6+
7+
pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, suffix: &str, lit_snip: &str) {
8+
let maybe_last_sep_idx = if let Some(val) = lit_snip.len().checked_sub(suffix.len() + 1) {
9+
val
10+
} else {
11+
return; // It's useless so shouldn't lint.
12+
};
13+
if maybe_last_sep_idx <= 2 {
14+
// It's meaningless or causes range error.
15+
return;
16+
}
17+
let mut seen = (false, false);
18+
for ch in lit_snip.as_bytes()[2..=maybe_last_sep_idx].iter() {
19+
match ch {
20+
b'a'..=b'f' => seen.0 = true,
21+
b'A'..=b'F' => seen.1 = true,
22+
_ => {},
23+
}
24+
if seen.0 && seen.1 {
25+
span_lint(
26+
cx,
27+
MIXED_CASE_HEX_LITERALS,
28+
lit.span,
29+
"inconsistent casing in hexadecimal literal",
30+
);
31+
break;
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)