1 use clippy_utils::diagnostics::span_lint_and_sugg;
2 use rustc_errors::Applicability;
3 use rustc_lint::EarlyContext;
6 use super::{SEPARATED_LITERAL_SUFFIX, UNSEPARATED_LITERAL_SUFFIX};
8 pub(super) fn check(cx: &EarlyContext<'_>, lit_span: Span, lit_snip: &str, suffix: &str, sugg_type: &str) {
9 let Some(maybe_last_sep_idx) = lit_snip.len().checked_sub(suffix.len() + 1) else {
10 return; // It's useless so shouldn't lint.
12 // Do not lint when literal is unsuffixed.
13 if !suffix.is_empty() {
14 if lit_snip.as_bytes()[maybe_last_sep_idx] == b'_' {
17 SEPARATED_LITERAL_SUFFIX,
19 &format!("{sugg_type} type suffix should not be separated by an underscore"),
20 "remove the underscore",
21 format!("{}{suffix}", &lit_snip[..maybe_last_sep_idx]),
22 Applicability::MachineApplicable,
27 UNSEPARATED_LITERAL_SUFFIX,
29 &format!("{sugg_type} type suffix should be separated by an underscore"),
31 format!("{}_{suffix}", &lit_snip[..=maybe_last_sep_idx]),
32 Applicability::MachineApplicable,