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