]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/clippy_lints/src/misc_early/mixed_case_hex_literals.rs
Rollup merge of #104182 - gabhijit:ipv6-in6addr-any-doc-fix, r=m-ou-se
[rust.git] / src / tools / clippy / clippy_lints / src / misc_early / mixed_case_hex_literals.rs
1 use clippy_utils::diagnostics::span_lint;
2 use rustc_lint::EarlyContext;
3 use rustc_span::Span;
4
5 use super::MIXED_CASE_HEX_LITERALS;
6
7 pub(super) fn check(cx: &EarlyContext<'_>, lit_span: Span, suffix: &str, lit_snip: &str) {
8     let Some(maybe_last_sep_idx) = lit_snip.len().checked_sub(suffix.len() + 1) else {
9         return; // It's useless so shouldn't lint.
10     };
11     if maybe_last_sep_idx <= 2 {
12         // It's meaningless or causes range error.
13         return;
14     }
15     let mut seen = (false, false);
16     for ch in lit_snip.as_bytes()[2..=maybe_last_sep_idx].iter() {
17         match ch {
18             b'a'..=b'f' => seen.0 = true,
19             b'A'..=b'F' => seen.1 = true,
20             _ => {},
21         }
22         if seen.0 && seen.1 {
23             span_lint(
24                 cx,
25                 MIXED_CASE_HEX_LITERALS,
26                 lit_span,
27                 "inconsistent casing in hexadecimal literal",
28             );
29             break;
30         }
31     }
32 }