move mixed_case_hex_literals to its own module
This commit is contained in:
parent
f012e0e3de
commit
0773d8afdb
29
clippy_lints/src/misc_early/mixed_case_hex_literals.rs
Normal file
29
clippy_lints/src/misc_early/mixed_case_hex_literals.rs
Normal file
@ -0,0 +1,29 @@
|
||||
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, maybe_last_sep_idx: usize, lit_snip: String) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
mod builtin_type_shadow;
|
||||
mod double_neg;
|
||||
mod mixed_case_hex_literals;
|
||||
mod redundant_pattern;
|
||||
mod unneeded_field_pattern;
|
||||
mod unneeded_wildcard_pattern;
|
||||
@ -351,27 +352,7 @@ fn check_lit(cx: &EarlyContext<'_>, lit: &Lit) {
|
||||
}
|
||||
|
||||
if lit_snip.starts_with("0x") {
|
||||
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;
|
||||
}
|
||||
}
|
||||
mixed_case_hex_literals::check(cx, lit, maybe_last_sep_idx, lit_snip)
|
||||
} else if lit_snip.starts_with("0b") || lit_snip.starts_with("0o") {
|
||||
/* nothing to do */
|
||||
} else if value != 0 && lit_snip.starts_with('0') {
|
||||
|
Loading…
Reference in New Issue
Block a user