]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/clippy_lints/src/misc_early/mixed_case_hex_literals.rs
Add tests for `#[no_mangle]` in `impl` blocks that looks like generic `impl` blocks...
[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_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, suffix: &str, lit_snip: &str) {
8     let maybe_last_sep_idx = if let Some(val) = lit_snip.len().checked_sub(suffix.len() + 1) {
9         val
10     } else {
11         return; // It's useless so shouldn't lint.
12     };
13     if maybe_last_sep_idx <= 2 {
14         // It's meaningless or causes range error.
15         return;
16     }
17     let mut seen = (false, false);
18     for ch in lit_snip.as_bytes()[2..=maybe_last_sep_idx].iter() {
19         match ch {
20             b'a'..=b'f' => seen.0 = true,
21             b'A'..=b'F' => seen.1 = true,
22             _ => {},
23         }
24         if seen.0 && seen.1 {
25             span_lint(
26                 cx,
27                 MIXED_CASE_HEX_LITERALS,
28                 lit.span,
29                 "inconsistent casing in hexadecimal literal",
30             );
31             break;
32         }
33     }
34 }