-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
12 changed files
with
636 additions
and
571 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()), | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
_ => (), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Oops, something went wrong.