Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f012e0e

Browse files
committed
move unseparated_literal_suffix to its own module
1 parent 829fde5 commit f012e0e

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

clippy_lints/src/misc_early/mod.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod double_neg;
33
mod redundant_pattern;
44
mod unneeded_field_pattern;
55
mod unneeded_wildcard_pattern;
6+
mod unseparated_literal_suffix;
67

78
use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then};
89
use clippy_utils::source::snippet_opt;
@@ -396,23 +397,7 @@ impl MiscEarlyLints {
396397
);
397398
}
398399
} else if let LitKind::Float(_, LitFloatType::Suffixed(float_ty)) = lit.kind {
399-
let suffix = float_ty.name_str();
400-
let maybe_last_sep_idx = if let Some(val) = lit_snip.len().checked_sub(suffix.len() + 1) {
401-
val
402-
} else {
403-
return; // It's useless so shouldn't lint.
404-
};
405-
if lit_snip.as_bytes()[maybe_last_sep_idx] != b'_' {
406-
span_lint_and_sugg(
407-
cx,
408-
UNSEPARATED_LITERAL_SUFFIX,
409-
lit.span,
410-
"float type suffix should be separated by an underscore",
411-
"add an underscore",
412-
format!("{}_{}", &lit_snip[..=maybe_last_sep_idx], suffix),
413-
Applicability::MachineApplicable,
414-
);
415-
}
400+
unseparated_literal_suffix::check(cx, lit, float_ty, lit_snip)
416401
}
417402
}
418403
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use clippy_utils::diagnostics::span_lint_and_sugg;
2+
use rustc_ast::ast::FloatTy;
3+
use rustc_ast::ast::Lit;
4+
use rustc_errors::Applicability;
5+
use rustc_lint::EarlyContext;
6+
7+
use super::UNSEPARATED_LITERAL_SUFFIX;
8+
9+
pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, float_ty: FloatTy, lit_snip: String) {
10+
let suffix = float_ty.name_str();
11+
let maybe_last_sep_idx = if let Some(val) = lit_snip.len().checked_sub(suffix.len() + 1) {
12+
val
13+
} else {
14+
return; // It's useless so shouldn't lint.
15+
};
16+
if lit_snip.as_bytes()[maybe_last_sep_idx] != b'_' {
17+
span_lint_and_sugg(
18+
cx,
19+
UNSEPARATED_LITERAL_SUFFIX,
20+
lit.span,
21+
"float type suffix should be separated by an underscore",
22+
"add an underscore",
23+
format!("{}_{}", &lit_snip[..=maybe_last_sep_idx], suffix),
24+
Applicability::MachineApplicable,
25+
);
26+
}
27+
}

0 commit comments

Comments
 (0)