]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/clippy_lints/src/misc_early/zero_prefixed_literal.rs
Rollup merge of #99742 - sigaloid:master, r=thomcc
[rust.git] / src / tools / clippy / clippy_lints / src / misc_early / zero_prefixed_literal.rs
1 use clippy_utils::diagnostics::span_lint_and_then;
2 use rustc_ast::ast::Lit;
3 use rustc_errors::Applicability;
4 use rustc_lint::EarlyContext;
5
6 use super::ZERO_PREFIXED_LITERAL;
7
8 pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, lit_snip: &str) {
9     span_lint_and_then(
10         cx,
11         ZERO_PREFIXED_LITERAL,
12         lit.span,
13         "this is a decimal constant",
14         |diag| {
15             diag.span_suggestion(
16                 lit.span,
17                 "if you mean to use a decimal constant, remove the `0` to avoid confusion",
18                 lit_snip.trim_start_matches(|c| c == '_' || c == '0').to_string(),
19                 Applicability::MaybeIncorrect,
20             );
21             diag.span_suggestion(
22                 lit.span,
23                 "if you mean to use an octal constant, use `0o`",
24                 format!("0o{}", lit_snip.trim_start_matches(|c| c == '_' || c == '0')),
25                 Applicability::MaybeIncorrect,
26             );
27         },
28     );
29 }