literal representation restructure 1

Combine macro expansion checks. Indentation is a little strange to
avoid rustfmt issue.
This commit is contained in:
Michael Wright 2019-11-13 08:26:52 +02:00
parent 180f87065f
commit 8f5b4f3f5c

View File

@ -358,28 +358,24 @@ impl EarlyLintPass for LiteralDigitGrouping {
impl LiteralDigitGrouping { impl LiteralDigitGrouping {
fn check_lit(cx: &EarlyContext<'_>, lit: &Lit) { fn check_lit(cx: &EarlyContext<'_>, lit: &Lit) {
let in_macro = in_macro(lit.span); let in_macro = in_macro(lit.span);
match lit.kind {
LitKind::Int(..) => {
// Lint integral literals.
if_chain! { if_chain! {
if let Some(src) = snippet_opt(cx, lit.span); if let Some(src) = snippet_opt(cx, lit.span);
if let Some(firstch) = src.chars().next(); if let Some(firstch) = src.chars().next();
if char::is_digit(firstch, 10); if char::is_digit(firstch, 10);
then { then {
match lit.kind {
LitKind::Int(..) => {
// Lint integral literals.
let digit_info = DigitInfo::new(&src, false); let digit_info = DigitInfo::new(&src, false);
let _ = Self::do_lint(digit_info.digits, digit_info.suffix, in_macro).map_err(|warning_type| { let _ = Self::do_lint(digit_info.digits, digit_info.suffix, in_macro).map_err(|warning_type| {
warning_type.display(&digit_info.grouping_hint(), cx, lit.span) warning_type.display(&digit_info.grouping_hint(), cx, lit.span)
}); });
}
}
}, },
LitKind::Float(..) => { LitKind::Float(..) => {
// Lint floating-point literals. // Lint floating-point literals.
if_chain! {
if let Some(src) = snippet_opt(cx, lit.span);
if let Some(firstch) = src.chars().next();
if char::is_digit(firstch, 10);
then {
let digit_info = DigitInfo::new(&src, true); let digit_info = DigitInfo::new(&src, true);
// Separate digits into integral and fractional parts. // Separate digits into integral and fractional parts.
let parts: Vec<&str> = digit_info let parts: Vec<&str> = digit_info
@ -414,12 +410,12 @@ impl LiteralDigitGrouping {
} }
}) })
.map_err(|warning_type| warning_type.display(&digit_info.grouping_hint(), cx, lit.span)); .map_err(|warning_type| warning_type.display(&digit_info.grouping_hint(), cx, lit.span));
}
}
}, },
_ => (), _ => (),
} }
} }
}
}
/// Given the sizes of the digit groups of both integral and fractional /// Given the sizes of the digit groups of both integral and fractional
/// parts, and the length /// parts, and the length