Skip to content

Commit cb43feb

Browse files
authored
Merge pull request #2495 from alexheretic/fix-2494
Fix #2494 add suggestion for unreadable_literal
2 parents adb8f7e + 42000c6 commit cb43feb

12 files changed

+40
-65
lines changed

clippy_lints/src/literal_representation.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use rustc::lint::*;
55
use syntax::ast::*;
66
use syntax_pos;
7-
use utils::{in_external_macro, snippet_opt, span_help_and_lint};
7+
use utils::{in_external_macro, snippet_opt, span_lint_and_sugg};
88

99
/// **What it does:** Warns if a long integral or floating-point constant does
1010
/// not contain underscores.
@@ -222,33 +222,37 @@ enum WarningType {
222222
impl WarningType {
223223
pub fn display(&self, grouping_hint: &str, cx: &EarlyContext, span: &syntax_pos::Span) {
224224
match *self {
225-
WarningType::UnreadableLiteral => span_help_and_lint(
225+
WarningType::UnreadableLiteral => span_lint_and_sugg(
226226
cx,
227227
UNREADABLE_LITERAL,
228228
*span,
229229
"long literal lacking separators",
230-
&format!("consider: {}", grouping_hint),
230+
"consider",
231+
grouping_hint.to_owned(),
231232
),
232-
WarningType::LargeDigitGroups => span_help_and_lint(
233+
WarningType::LargeDigitGroups => span_lint_and_sugg(
233234
cx,
234235
LARGE_DIGIT_GROUPS,
235236
*span,
236237
"digit groups should be smaller",
237-
&format!("consider: {}", grouping_hint),
238+
"consider",
239+
grouping_hint.to_owned(),
238240
),
239-
WarningType::InconsistentDigitGrouping => span_help_and_lint(
241+
WarningType::InconsistentDigitGrouping => span_lint_and_sugg(
240242
cx,
241243
INCONSISTENT_DIGIT_GROUPING,
242244
*span,
243245
"digits grouped inconsistently by underscores",
244-
&format!("consider: {}", grouping_hint),
246+
"consider",
247+
grouping_hint.to_owned(),
245248
),
246-
WarningType::DecimalRepresentation => span_help_and_lint(
249+
WarningType::DecimalRepresentation => span_lint_and_sugg(
247250
cx,
248251
DECIMAL_LITERAL_REPRESENTATION,
249252
*span,
250253
"integer literal has a better hexadecimal representation",
251-
&format!("consider: {}", grouping_hint),
254+
"consider",
255+
grouping_hint.to_owned(),
252256
),
253257
};
254258
}

tests/ui/builtin-type-shadow.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ error[E0308]: mismatched types
1919

2020
error: aborting due to 2 previous errors
2121

22+
If you want more information on this error, try using "rustc --explain E0308"

tests/ui/conf_bad_arg.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ error[E0658]: compiler plugins are experimental and possibly buggy (see issue #2
88

99
error: aborting due to previous error
1010

11+
If you want more information on this error, try using "rustc --explain E0658"

tests/ui/conf_bad_toml.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ error[E0658]: compiler plugins are experimental and possibly buggy (see issue #2
88

99
error: aborting due to previous error
1010

11+
If you want more information on this error, try using "rustc --explain E0658"

tests/ui/conf_bad_type.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ error[E0658]: compiler plugins are experimental and possibly buggy (see issue #2
88

99
error: aborting due to previous error
1010

11+
If you want more information on this error, try using "rustc --explain E0658"

tests/ui/conf_french_blacklisted_name.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ error[E0658]: compiler plugins are experimental and possibly buggy (see issue #2
88

99
error: aborting due to previous error
1010

11+
If you want more information on this error, try using "rustc --explain E0658"

tests/ui/conf_path_non_string.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ error[E0658]: compiler plugins are experimental and possibly buggy (see issue #2
88

99
error: aborting due to previous error
1010

11+
If you want more information on this error, try using "rustc --explain E0658"

tests/ui/conf_unknown_key.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ error[E0658]: compiler plugins are experimental and possibly buggy (see issue #2
88

99
error: aborting due to previous error
1010

11+
If you want more information on this error, try using "rustc --explain E0658"

tests/ui/decimal_literal_representation.stderr

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,33 @@ error: integer literal has a better hexadecimal representation
22
--> $DIR/decimal_literal_representation.rs:18:9
33
|
44
18 | 32_773, // 0x8005
5-
| ^^^^^^
5+
| ^^^^^^ help: consider: `0x8005`
66
|
77
= note: `-D decimal-literal-representation` implied by `-D warnings`
8-
= help: consider: 0x8005
98

109
error: integer literal has a better hexadecimal representation
1110
--> $DIR/decimal_literal_representation.rs:19:9
1211
|
1312
19 | 65_280, // 0xFF00
14-
| ^^^^^^
15-
|
16-
= help: consider: 0xFF00
13+
| ^^^^^^ help: consider: `0xFF00`
1714

1815
error: integer literal has a better hexadecimal representation
1916
--> $DIR/decimal_literal_representation.rs:20:9
2017
|
2118
20 | 2_131_750_927, // 0x7F0F_F00F
22-
| ^^^^^^^^^^^^^
23-
|
24-
= help: consider: 0x7F0F_F00F
19+
| ^^^^^^^^^^^^^ help: consider: `0x7F0F_F00F`
2520

2621
error: integer literal has a better hexadecimal representation
2722
--> $DIR/decimal_literal_representation.rs:21:9
2823
|
2924
21 | 2_147_483_647, // 0x7FFF_FFFF
30-
| ^^^^^^^^^^^^^
31-
|
32-
= help: consider: 0x7FFF_FFFF
25+
| ^^^^^^^^^^^^^ help: consider: `0x7FFF_FFFF`
3326

3427
error: integer literal has a better hexadecimal representation
3528
--> $DIR/decimal_literal_representation.rs:22:9
3629
|
3730
22 | 4_042_322_160, // 0xF0F0_F0F0
38-
| ^^^^^^^^^^^^^
39-
|
40-
= help: consider: 0xF0F0_F0F0
31+
| ^^^^^^^^^^^^^ help: consider: `0xF0F0_F0F0`
4132

4233
error: aborting due to 5 previous errors
4334

tests/ui/inconsistent_digit_grouping.stderr

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,33 @@ error: digits grouped inconsistently by underscores
22
--> $DIR/inconsistent_digit_grouping.rs:7:16
33
|
44
7 | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32);
5-
| ^^^^^^^^
5+
| ^^^^^^^^ help: consider: `123_456`
66
|
77
= note: `-D inconsistent-digit-grouping` implied by `-D warnings`
8-
= help: consider: 123_456
98

109
error: digits grouped inconsistently by underscores
1110
--> $DIR/inconsistent_digit_grouping.rs:7:26
1211
|
1312
7 | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32);
14-
| ^^^^^^^^^^
15-
|
16-
= help: consider: 12_345_678
13+
| ^^^^^^^^^^ help: consider: `12_345_678`
1714

1815
error: digits grouped inconsistently by underscores
1916
--> $DIR/inconsistent_digit_grouping.rs:7:38
2017
|
2118
7 | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32);
22-
| ^^^^^^^^
23-
|
24-
= help: consider: 1_234_567
19+
| ^^^^^^^^ help: consider: `1_234_567`
2520

2621
error: digits grouped inconsistently by underscores
2722
--> $DIR/inconsistent_digit_grouping.rs:7:48
2823
|
2924
7 | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32);
30-
| ^^^^^^^^^^^^^^
31-
|
32-
= help: consider: 1_234.567_8_f32
25+
| ^^^^^^^^^^^^^^ help: consider: `1_234.567_8_f32`
3326

3427
error: digits grouped inconsistently by underscores
3528
--> $DIR/inconsistent_digit_grouping.rs:7:64
3629
|
3730
7 | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32);
38-
| ^^^^^^^^^^^^^^
39-
|
40-
= help: consider: 1.234_567_8_f32
31+
| ^^^^^^^^^^^^^^ help: consider: `1.234_567_8_f32`
4132

4233
error: aborting due to 5 previous errors
4334

0 commit comments

Comments
 (0)