diff options
| author | Takayuki <takoyaki0316@gmail.com> | 2021-05-05 02:10:24 +0900 |
|---|---|---|
| committer | Takayuki <takoyaki0316@gmail.com> | 2021-05-05 02:10:24 +0900 |
| commit | f012e0e3de04ca5b8022a0b8856a12d47d746b5b (patch) | |
| tree | 52672c6d5396795e19c6988257f6d42d0c72aaa7 | |
| parent | 829fde5e1f1163b3218409244863ce64d8c7dd19 (diff) | |
move unseparated_literal_suffix to its own module
| -rw-r--r-- | clippy_lints/src/misc_early/mod.rs | 19 | ||||
| -rw-r--r-- | clippy_lints/src/misc_early/unseparated_literal_suffix.rs | 27 |
2 files changed, 29 insertions, 17 deletions
diff --git a/clippy_lints/src/misc_early/mod.rs b/clippy_lints/src/misc_early/mod.rs index ee1bff8bf8a..182218e77f6 100644 --- a/clippy_lints/src/misc_early/mod.rs +++ b/clippy_lints/src/misc_early/mod.rs @@ -3,6 +3,7 @@ mod double_neg; mod redundant_pattern; mod unneeded_field_pattern; mod unneeded_wildcard_pattern; +mod unseparated_literal_suffix; use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::snippet_opt; @@ -396,23 +397,7 @@ impl MiscEarlyLints { ); } } else if let LitKind::Float(_, LitFloatType::Suffixed(float_ty)) = lit.kind { - let suffix = float_ty.name_str(); - let maybe_last_sep_idx = if let Some(val) = lit_snip.len().checked_sub(suffix.len() + 1) { - val - } else { - return; // It's useless so shouldn't lint. - }; - if lit_snip.as_bytes()[maybe_last_sep_idx] != b'_' { - span_lint_and_sugg( - cx, - UNSEPARATED_LITERAL_SUFFIX, - lit.span, - "float type suffix should be separated by an underscore", - "add an underscore", - format!("{}_{}", &lit_snip[..=maybe_last_sep_idx], suffix), - Applicability::MachineApplicable, - ); - } + unseparated_literal_suffix::check(cx, lit, float_ty, lit_snip) } } } diff --git a/clippy_lints/src/misc_early/unseparated_literal_suffix.rs b/clippy_lints/src/misc_early/unseparated_literal_suffix.rs new file mode 100644 index 00000000000..ffdd5d93a38 --- /dev/null +++ b/clippy_lints/src/misc_early/unseparated_literal_suffix.rs @@ -0,0 +1,27 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; +use rustc_ast::ast::FloatTy; +use rustc_ast::ast::Lit; +use rustc_errors::Applicability; +use rustc_lint::EarlyContext; + +use super::UNSEPARATED_LITERAL_SUFFIX; + +pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, float_ty: FloatTy, lit_snip: String) { + let suffix = float_ty.name_str(); + let maybe_last_sep_idx = if let Some(val) = lit_snip.len().checked_sub(suffix.len() + 1) { + val + } else { + return; // It's useless so shouldn't lint. + }; + if lit_snip.as_bytes()[maybe_last_sep_idx] != b'_' { + span_lint_and_sugg( + cx, + UNSEPARATED_LITERAL_SUFFIX, + lit.span, + "float type suffix should be separated by an underscore", + "add an underscore", + format!("{}_{}", &lit_snip[..=maybe_last_sep_idx], suffix), + Applicability::MachineApplicable, + ); + } +} |
