Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: arrange lints in misc_early module #7166

Merged
merged 11 commits into from
May 6, 2021
569 changes: 0 additions & 569 deletions clippy_lints/src/misc_early.rs

This file was deleted.

19 changes: 19 additions & 0 deletions clippy_lints/src/misc_early/builtin_type_shadow.rs
Original file line number Diff line number Diff line change
@@ -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()),
);
}
}
}
23 changes: 23 additions & 0 deletions clippy_lints/src/misc_early/double_neg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use super::MiscEarlyLints;
use clippy_utils::diagnostics::span_lint;
use rustc_ast::ast::{Expr, ExprKind, UnOp};
use rustc_lint::EarlyContext;

use super::DOUBLE_NEG;

pub(super) fn check(cx: &EarlyContext<'_>, expr: &Expr) {
match expr.kind {
ExprKind::Unary(UnOp::Neg, ref inner) => {
if let ExprKind::Unary(UnOp::Neg, _) = inner.kind {
span_lint(
cx,
DOUBLE_NEG,
expr.span,
"`--x` could be misinterpreted as pre-decrement by C programmers, is usually a no-op",
);
}
},
ExprKind::Lit(ref lit) => MiscEarlyLints::check_lit(cx, lit),
_ => (),
}
}
34 changes: 34 additions & 0 deletions clippy_lints/src/misc_early/mixed_case_hex_literals.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use clippy_utils::diagnostics::span_lint;
use rustc_ast::ast::Lit;
use rustc_lint::EarlyContext;

use super::MIXED_CASE_HEX_LITERALS;

pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, suffix: &str, lit_snip: &str) {
let maybe_last_sep_idx = if let Some(val) = lit_snip.len().checked_sub(suffix.len() + 1) {
val
} else {
return; // It's useless so shouldn't lint.
};
if maybe_last_sep_idx <= 2 {
// It's meaningless or causes range error.
return;
}
let mut seen = (false, false);
for ch in lit_snip.as_bytes()[2..=maybe_last_sep_idx].iter() {
match ch {
b'a'..=b'f' => seen.0 = true,
b'A'..=b'F' => seen.1 = true,
_ => {},
}
if seen.0 && seen.1 {
span_lint(
cx,
MIXED_CASE_HEX_LITERALS,
lit.span,
"inconsistent casing in hexadecimal literal",
);
break;
}
}
}
Loading