Skip to content

Commit eb9caf3

Browse files
author
Michael Wright
committed
literal representation restructure 11
Rename `grouping_hint` to `format` and use the term consistently.
1 parent a8ca8a2 commit eb9caf3

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

clippy_lints/src/excessive_precision.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl ExcessivePrecision {
8787
None
8888
} else {
8989
let num_lit = super::literal_representation::NumericLiteral::new(&s, None, true);
90-
Some(num_lit.grouping_hint())
90+
Some(num_lit.format())
9191
}
9292
} else {
9393
None

clippy_lints/src/literal_representation.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl<'a> NumericLiteral<'a> {
219219
}
220220

221221
/// Returns literal formatted in a sensible way.
222-
crate fn grouping_hint(&self) -> String {
222+
crate fn format(&self) -> String {
223223
let mut output = String::new();
224224

225225
if let Some(prefix) = self.prefix {
@@ -324,15 +324,15 @@ enum WarningType {
324324
}
325325

326326
impl WarningType {
327-
crate fn display(&self, grouping_hint: &str, cx: &EarlyContext<'_>, span: syntax_pos::Span) {
327+
crate fn display(&self, suggested_format: String, cx: &EarlyContext<'_>, span: syntax_pos::Span) {
328328
match self {
329329
Self::MistypedLiteralSuffix => span_lint_and_sugg(
330330
cx,
331331
MISTYPED_LITERAL_SUFFIXES,
332332
span,
333333
"mistyped literal suffix",
334334
"did you mean to write",
335-
grouping_hint.to_string(),
335+
suggested_format,
336336
Applicability::MaybeIncorrect,
337337
),
338338
Self::UnreadableLiteral => span_lint_and_sugg(
@@ -341,7 +341,7 @@ impl WarningType {
341341
span,
342342
"long literal lacking separators",
343343
"consider",
344-
grouping_hint.to_owned(),
344+
suggested_format,
345345
Applicability::MachineApplicable,
346346
),
347347
Self::LargeDigitGroups => span_lint_and_sugg(
@@ -350,7 +350,7 @@ impl WarningType {
350350
span,
351351
"digit groups should be smaller",
352352
"consider",
353-
grouping_hint.to_owned(),
353+
suggested_format,
354354
Applicability::MachineApplicable,
355355
),
356356
Self::InconsistentDigitGrouping => span_lint_and_sugg(
@@ -359,7 +359,7 @@ impl WarningType {
359359
span,
360360
"digits grouped inconsistently by underscores",
361361
"consider",
362-
grouping_hint.to_owned(),
362+
suggested_format,
363363
Applicability::MachineApplicable,
364364
),
365365
Self::DecimalRepresentation => span_lint_and_sugg(
@@ -368,7 +368,7 @@ impl WarningType {
368368
span,
369369
"integer literal has a better hexadecimal representation",
370370
"consider",
371-
grouping_hint.to_owned(),
371+
suggested_format,
372372
Applicability::MachineApplicable,
373373
),
374374
};
@@ -425,7 +425,7 @@ impl LiteralDigitGrouping {
425425

426426

427427
if let Err(warning_type) = result {
428-
warning_type.display(&num_lit.grouping_hint(), cx, lit.span)
428+
warning_type.display(num_lit.format(), cx, lit.span)
429429
}
430430
}
431431
}
@@ -453,11 +453,11 @@ impl LiteralDigitGrouping {
453453
let last_group = split.next().expect("At least one group");
454454
if split.next().is_some() && mistyped_suffixes.contains(&last_group) {
455455
*part = &part[..part.len() - last_group.len()];
456-
let mut hint = num_lit.grouping_hint();
457-
hint.push('_');
458-
hint.push(missing_char);
459-
hint.push_str(last_group);
460-
WarningType::MistypedLiteralSuffix.display(&hint, cx, span);
456+
let mut sugg = num_lit.format();
457+
sugg.push('_');
458+
sugg.push(missing_char);
459+
sugg.push_str(last_group);
460+
WarningType::MistypedLiteralSuffix.display(sugg, cx, span);
461461
false
462462
} else {
463463
true
@@ -546,7 +546,7 @@ impl DecimalLiteralRepresentation {
546546
let hex = format!("{:#X}", val);
547547
let num_lit = NumericLiteral::new(&hex, None, false);
548548
let _ = Self::do_lint(num_lit.integer).map_err(|warning_type| {
549-
warning_type.display(&num_lit.grouping_hint(), cx, lit.span)
549+
warning_type.display(num_lit.format(), cx, lit.span)
550550
});
551551
}
552552
}

0 commit comments

Comments
 (0)