1 use clippy_utils::diagnostics::span_lint_and_then;
2 use rustc_errors::Applicability;
3 use rustc_lint::EarlyContext;
6 use super::ZERO_PREFIXED_LITERAL;
8 pub(super) fn check(cx: &EarlyContext<'_>, lit_span: Span, lit_snip: &str) {
9 let trimmed_lit_snip = lit_snip.trim_start_matches(|c| c == '_' || c == '0');
12 ZERO_PREFIXED_LITERAL,
14 "this is a decimal constant",
18 "if you mean to use a decimal constant, remove the `0` to avoid confusion",
19 trimmed_lit_snip.to_string(),
20 Applicability::MaybeIncorrect,
22 // do not advise to use octal form if the literal cannot be expressed in base 8.
23 if !lit_snip.contains(|c| c == '8' || c == '9') {
26 "if you mean to use an octal constant, use `0o`",
27 format!("0o{trimmed_lit_snip}"),
28 Applicability::MaybeIncorrect,