Apply requested changes

This commit is contained in:
flip1995 2018-01-23 15:29:31 +01:00
parent d7677fb2b6
commit 600147926b
9 changed files with 77 additions and 75 deletions

View File

@ -488,7 +488,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
literal_representation::INCONSISTENT_DIGIT_GROUPING, literal_representation::INCONSISTENT_DIGIT_GROUPING,
literal_representation::LARGE_DIGIT_GROUPS, literal_representation::LARGE_DIGIT_GROUPS,
literal_representation::UNREADABLE_LITERAL, literal_representation::UNREADABLE_LITERAL,
literal_representation::BAD_LITERAL_REPRESENTATION, literal_representation::DECIMAL_LITERAL_REPRESENTATION,
loops::EMPTY_LOOP, loops::EMPTY_LOOP,
loops::EXPLICIT_COUNTER_LOOP, loops::EXPLICIT_COUNTER_LOOP,
loops::EXPLICIT_INTO_ITER_LOOP, loops::EXPLICIT_INTO_ITER_LOOP,

View File

@ -75,7 +75,7 @@ declare_lint! {
/// `65_535` => `0xFFFF` /// `65_535` => `0xFFFF`
/// `4_042_322_160` => `0xF0F0_F0F0` /// `4_042_322_160` => `0xF0F0_F0F0`
declare_lint! { declare_lint! {
pub BAD_LITERAL_REPRESENTATION, pub DECIMAL_LITERAL_REPRESENTATION,
Warn, Warn,
"using decimal representation when hexadecimal would be better" "using decimal representation when hexadecimal would be better"
} }
@ -217,7 +217,7 @@ enum WarningType {
UnreadableLiteral, UnreadableLiteral,
InconsistentDigitGrouping, InconsistentDigitGrouping,
LargeDigitGroups, LargeDigitGroups,
BadRepresentation, DecimalRepresentation,
} }
impl WarningType { impl WarningType {
@ -244,11 +244,11 @@ impl WarningType {
"digits grouped inconsistently by underscores", "digits grouped inconsistently by underscores",
&format!("consider: {}", grouping_hint), &format!("consider: {}", grouping_hint),
), ),
WarningType::BadRepresentation => span_help_and_lint( WarningType::DecimalRepresentation => span_help_and_lint(
cx, cx,
BAD_LITERAL_REPRESENTATION, DECIMAL_LITERAL_REPRESENTATION,
*span, *span,
"bad representation of integer literal", "integer literal has a better hexadecimal representation",
&format!("consider: {}", grouping_hint), &format!("consider: {}", grouping_hint),
), ),
}; };
@ -400,7 +400,7 @@ pub struct LiteralRepresentation {
impl LintPass for LiteralRepresentation { impl LintPass for LiteralRepresentation {
fn get_lints(&self) -> LintArray { fn get_lints(&self) -> LintArray {
lint_array!(BAD_LITERAL_REPRESENTATION) lint_array!(DECIMAL_LITERAL_REPRESENTATION)
} }
} }
@ -456,7 +456,7 @@ impl LiteralRepresentation {
if digits == "1" || digits == "2" || digits == "4" || digits == "8" || digits == "3" || digits == "7" if digits == "1" || digits == "2" || digits == "4" || digits == "8" || digits == "3" || digits == "7"
|| digits == "F" || digits == "F"
{ {
return Err(WarningType::BadRepresentation); return Err(WarningType::DecimalRepresentation);
} }
} else if digits.len() < 4 { } else if digits.len() < 4 {
// Lint for Literals with a hex-representation of 2 or 3 digits // Lint for Literals with a hex-representation of 2 or 3 digits
@ -467,7 +467,7 @@ impl LiteralRepresentation {
// Powers of 2 minus 1 // Powers of 2 minus 1
|| ((f.eq("1") || f.eq("3") || f.eq("7") || f.eq("F")) && s.chars().all(|c| c == 'F')) || ((f.eq("1") || f.eq("3") || f.eq("7") || f.eq("F")) && s.chars().all(|c| c == 'F'))
{ {
return Err(WarningType::BadRepresentation); return Err(WarningType::DecimalRepresentation);
} }
} else { } else {
// Lint for Literals with a hex-representation of 4 digits or more // Lint for Literals with a hex-representation of 4 digits or more
@ -481,7 +481,7 @@ impl LiteralRepresentation {
// digit // digit
|| ((f.eq("7") || f.eq("F")) && s.chars().all(|c| c == '0' || c == 'F')) || ((f.eq("7") || f.eq("F")) && s.chars().all(|c| c == '0' || c == 'F'))
{ {
return Err(WarningType::BadRepresentation); return Err(WarningType::DecimalRepresentation);
} }
} }

View File

@ -177,7 +177,7 @@ define_Conf! {
(enum_variant_size_threshold, "enum_variant_size_threshold", 200 => u64), (enum_variant_size_threshold, "enum_variant_size_threshold", 200 => u64),
/// Lint: VERBOSE_BIT_MASK. The maximum allowed size of a bit mask before suggesting to use 'trailing_zeros' /// Lint: VERBOSE_BIT_MASK. The maximum allowed size of a bit mask before suggesting to use 'trailing_zeros'
(verbose_bit_mask_threshold, "verbose_bit_mask_threshold", 1 => u64), (verbose_bit_mask_threshold, "verbose_bit_mask_threshold", 1 => u64),
/// Lint: BAD_LITERAL_REPRESENTATION. The lower bound for linting decimal literals /// Lint: DECIMAL_LITERAL_REPRESENTATION. The lower bound for linting decimal literals
(literal_representation_threshold, "literal_representation_threshold", 4096 => u64), (literal_representation_threshold, "literal_representation_threshold", 4096 => u64),
} }

View File

@ -1,59 +0,0 @@
error: bad representation of integer literal
--> $DIR/bad_literal_representation.rs:10:9
|
10 | 4096, // 0x1000
| ^^^^
|
= note: `-D bad-literal-representation` implied by `-D warnings`
= help: consider: 0x1000
error: bad representation of integer literal
--> $DIR/bad_literal_representation.rs:11:9
|
11 | 16_371, // 0x3FF3
| ^^^^^^
|
= help: consider: 0x3FF3
error: bad representation of integer literal
--> $DIR/bad_literal_representation.rs:12:9
|
12 | 32_773, // 0x8005
| ^^^^^^
|
= help: consider: 0x8005
error: bad representation of integer literal
--> $DIR/bad_literal_representation.rs:13:9
|
13 | 65_280, // 0xFF00
| ^^^^^^
|
= help: consider: 0xFF00
error: bad representation of integer literal
--> $DIR/bad_literal_representation.rs:14:9
|
14 | 2_131_750_927, // 0x7F0F_F00F
| ^^^^^^^^^^^^^
|
= help: consider: 0x7F0F_F00F
error: bad representation of integer literal
--> $DIR/bad_literal_representation.rs:15:9
|
15 | 2_147_483_647, // 0x7FFF_FFFF
| ^^^^^^^^^^^^^
|
= help: consider: 0x7FFF_FFFF
error: bad representation of integer literal
--> $DIR/bad_literal_representation.rs:16:9
|
16 | 4_042_322_160, // 0xF0F0_F0F0
| ^^^^^^^^^^^^^
|
= help: consider: 0xF0F0_F0F0
error: aborting due to 7 previous errors

View File

@ -1,7 +1,7 @@
#[warn(bad_literal_representation)] #[warn(decimal_literal_representation)]
#[allow(unused_variables)] #[allow(unused_variables)]
fn main() { fn main() {
// Hex: 7F, 80, 100, 1FF, 800, FFA, F0F3, 7F0F_F00D // Hex: 7F, 80, 100, 1FF, 800, FFA, F0F3, 7F0F_F00D

View File

@ -0,0 +1,59 @@
error: integer literal has a better hexadecimal representation
--> $DIR/decimal_literal_representation.rs:10:9
|
10 | 4096, // 0x1000
| ^^^^
|
= note: `-D decimal-literal-representation` implied by `-D warnings`
= help: consider: 0x1000
error: integer literal has a better hexadecimal representation
--> $DIR/decimal_literal_representation.rs:11:9
|
11 | 16_371, // 0x3FF3
| ^^^^^^
|
= help: consider: 0x3FF3
error: integer literal has a better hexadecimal representation
--> $DIR/decimal_literal_representation.rs:12:9
|
12 | 32_773, // 0x8005
| ^^^^^^
|
= help: consider: 0x8005
error: integer literal has a better hexadecimal representation
--> $DIR/decimal_literal_representation.rs:13:9
|
13 | 65_280, // 0xFF00
| ^^^^^^
|
= help: consider: 0xFF00
error: integer literal has a better hexadecimal representation
--> $DIR/decimal_literal_representation.rs:14:9
|
14 | 2_131_750_927, // 0x7F0F_F00F
| ^^^^^^^^^^^^^
|
= help: consider: 0x7F0F_F00F
error: integer literal has a better hexadecimal representation
--> $DIR/decimal_literal_representation.rs:15:9
|
15 | 2_147_483_647, // 0x7FFF_FFFF
| ^^^^^^^^^^^^^
|
= help: consider: 0x7FFF_FFFF
error: integer literal has a better hexadecimal representation
--> $DIR/decimal_literal_representation.rs:16:9
|
16 | 4_042_322_160, // 0xF0F0_F0F0
| ^^^^^^^^^^^^^
|
= help: consider: 0xF0F0_F0F0
error: aborting due to 7 previous errors

View File

@ -42,7 +42,7 @@ fn main() {
forget(s4); forget(s4);
forget(s5); forget(s5);
let a1 = AnotherStruct {x: 0xFF, y: 0, z: vec![1, 2, 3]}; let a1 = AnotherStruct {x: 255, y: 0, z: vec![1, 2, 3]};
let a2 = &a1; let a2 = &a1;
let mut a3 = a1.clone(); let mut a3 = a1.clone();
let ref a4 = a1; let ref a4 = a1;

View File

@ -29,5 +29,5 @@ fn main() {
-1 & x; -1 & x;
let u : u8 = 0; let u : u8 = 0;
u & 0xFF; u & 255;
} }

View File

@ -45,6 +45,8 @@ error: the operation is ineffective. Consider reducing it to `x`
error: the operation is ineffective. Consider reducing it to `u` error: the operation is ineffective. Consider reducing it to `u`
--> $DIR/identity_op.rs:32:5 --> $DIR/identity_op.rs:32:5
| |
32 | u & 0xFF; 32 | u & 255;
| ^^^^^^^^ | ^^^^^^^
error: aborting due to 8 previous errors