Skip to content

Commit

Permalink
literal representation restructure 11
Browse files Browse the repository at this point in the history
Rename `grouping_hint` to `format` and use the term consistently.
  • Loading branch information
Michael Wright committed Nov 13, 2019
1 parent a8ca8a2 commit eb9caf3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/excessive_precision.rs
Expand Up @@ -87,7 +87,7 @@ impl ExcessivePrecision {
None
} else {
let num_lit = super::literal_representation::NumericLiteral::new(&s, None, true);
Some(num_lit.grouping_hint())
Some(num_lit.format())
}
} else {
None
Expand Down
28 changes: 14 additions & 14 deletions clippy_lints/src/literal_representation.rs
Expand Up @@ -219,7 +219,7 @@ impl<'a> NumericLiteral<'a> {
}

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

if let Some(prefix) = self.prefix {
Expand Down Expand Up @@ -324,15 +324,15 @@ enum WarningType {
}

impl WarningType {
crate fn display(&self, grouping_hint: &str, cx: &EarlyContext<'_>, span: syntax_pos::Span) {
crate fn display(&self, suggested_format: String, cx: &EarlyContext<'_>, span: syntax_pos::Span) {
match self {
Self::MistypedLiteralSuffix => span_lint_and_sugg(
cx,
MISTYPED_LITERAL_SUFFIXES,
span,
"mistyped literal suffix",
"did you mean to write",
grouping_hint.to_string(),
suggested_format,
Applicability::MaybeIncorrect,
),
Self::UnreadableLiteral => span_lint_and_sugg(
Expand All @@ -341,7 +341,7 @@ impl WarningType {
span,
"long literal lacking separators",
"consider",
grouping_hint.to_owned(),
suggested_format,
Applicability::MachineApplicable,
),
Self::LargeDigitGroups => span_lint_and_sugg(
Expand All @@ -350,7 +350,7 @@ impl WarningType {
span,
"digit groups should be smaller",
"consider",
grouping_hint.to_owned(),
suggested_format,
Applicability::MachineApplicable,
),
Self::InconsistentDigitGrouping => span_lint_and_sugg(
Expand All @@ -359,7 +359,7 @@ impl WarningType {
span,
"digits grouped inconsistently by underscores",
"consider",
grouping_hint.to_owned(),
suggested_format,
Applicability::MachineApplicable,
),
Self::DecimalRepresentation => span_lint_and_sugg(
Expand All @@ -368,7 +368,7 @@ impl WarningType {
span,
"integer literal has a better hexadecimal representation",
"consider",
grouping_hint.to_owned(),
suggested_format,
Applicability::MachineApplicable,
),
};
Expand Down Expand Up @@ -425,7 +425,7 @@ impl LiteralDigitGrouping {


if let Err(warning_type) = result {
warning_type.display(&num_lit.grouping_hint(), cx, lit.span)
warning_type.display(num_lit.format(), cx, lit.span)
}
}
}
Expand Down Expand Up @@ -453,11 +453,11 @@ impl LiteralDigitGrouping {
let last_group = split.next().expect("At least one group");
if split.next().is_some() && mistyped_suffixes.contains(&last_group) {
*part = &part[..part.len() - last_group.len()];
let mut hint = num_lit.grouping_hint();
hint.push('_');
hint.push(missing_char);
hint.push_str(last_group);
WarningType::MistypedLiteralSuffix.display(&hint, cx, span);
let mut sugg = num_lit.format();
sugg.push('_');
sugg.push(missing_char);
sugg.push_str(last_group);
WarningType::MistypedLiteralSuffix.display(sugg, cx, span);
false
} else {
true
Expand Down Expand Up @@ -546,7 +546,7 @@ impl DecimalLiteralRepresentation {
let hex = format!("{:#X}", val);
let num_lit = NumericLiteral::new(&hex, None, false);
let _ = Self::do_lint(num_lit.integer).map_err(|warning_type| {
warning_type.display(&num_lit.grouping_hint(), cx, lit.span)
warning_type.display(num_lit.format(), cx, lit.span)
});
}
}
Expand Down

0 comments on commit eb9caf3

Please sign in to comment.