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

Commit 0773d8a

Browse files
committed
move mixed_case_hex_literals to its own module
1 parent f012e0e commit 0773d8a

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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, maybe_last_sep_idx: usize, lit_snip: String) {
8+
if maybe_last_sep_idx <= 2 {
9+
// It's meaningless or causes range error.
10+
return;
11+
}
12+
let mut seen = (false, false);
13+
for ch in lit_snip.as_bytes()[2..=maybe_last_sep_idx].iter() {
14+
match ch {
15+
b'a'..=b'f' => seen.0 = true,
16+
b'A'..=b'F' => seen.1 = true,
17+
_ => {},
18+
}
19+
if seen.0 && seen.1 {
20+
span_lint(
21+
cx,
22+
MIXED_CASE_HEX_LITERALS,
23+
lit.span,
24+
"inconsistent casing in hexadecimal literal",
25+
);
26+
break;
27+
}
28+
}
29+
}

clippy_lints/src/misc_early/mod.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mod builtin_type_shadow;
22
mod double_neg;
3+
mod mixed_case_hex_literals;
34
mod redundant_pattern;
45
mod unneeded_field_pattern;
56
mod unneeded_wildcard_pattern;
@@ -351,27 +352,7 @@ impl MiscEarlyLints {
351352
}
352353

353354
if lit_snip.starts_with("0x") {
354-
if maybe_last_sep_idx <= 2 {
355-
// It's meaningless or causes range error.
356-
return;
357-
}
358-
let mut seen = (false, false);
359-
for ch in lit_snip.as_bytes()[2..=maybe_last_sep_idx].iter() {
360-
match ch {
361-
b'a'..=b'f' => seen.0 = true,
362-
b'A'..=b'F' => seen.1 = true,
363-
_ => {},
364-
}
365-
if seen.0 && seen.1 {
366-
span_lint(
367-
cx,
368-
MIXED_CASE_HEX_LITERALS,
369-
lit.span,
370-
"inconsistent casing in hexadecimal literal",
371-
);
372-
break;
373-
}
374-
}
355+
mixed_case_hex_literals::check(cx, lit, maybe_last_sep_idx, lit_snip)
375356
} else if lit_snip.starts_with("0b") || lit_snip.starts_with("0o") {
376357
/* nothing to do */
377358
} else if value != 0 && lit_snip.starts_with('0') {

0 commit comments

Comments
 (0)