From 600147926bfd18b67ac53b6800dc23c09fb60704 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Tue, 23 Jan 2018 15:29:31 +0100 Subject: [PATCH] Apply requested changes --- clippy_lints/src/lib.rs | 2 +- clippy_lints/src/literal_representation.rs | 18 +++--- clippy_lints/src/utils/conf.rs | 2 +- tests/ui/bad_literal_representation.stderr | 59 ------------------- ...n.rs => decimal_literal_representation.rs} | 2 +- .../ui/decimal_literal_representation.stderr | 59 +++++++++++++++++++ tests/ui/drop_forget_copy.rs | 2 +- tests/ui/identity_op.rs | 2 +- tests/ui/identity_op.stderr | 6 +- 9 files changed, 77 insertions(+), 75 deletions(-) delete mode 100644 tests/ui/bad_literal_representation.stderr rename tests/ui/{bad_literal_representation.rs => decimal_literal_representation.rs} (92%) create mode 100644 tests/ui/decimal_literal_representation.stderr diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index f57092b7ff5..e14e20011e1 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -488,7 +488,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { literal_representation::INCONSISTENT_DIGIT_GROUPING, literal_representation::LARGE_DIGIT_GROUPS, literal_representation::UNREADABLE_LITERAL, - literal_representation::BAD_LITERAL_REPRESENTATION, + literal_representation::DECIMAL_LITERAL_REPRESENTATION, loops::EMPTY_LOOP, loops::EXPLICIT_COUNTER_LOOP, loops::EXPLICIT_INTO_ITER_LOOP, diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index 0d0e985f994..a0c4f537a15 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -75,7 +75,7 @@ declare_lint! { /// `65_535` => `0xFFFF` /// `4_042_322_160` => `0xF0F0_F0F0` declare_lint! { - pub BAD_LITERAL_REPRESENTATION, + pub DECIMAL_LITERAL_REPRESENTATION, Warn, "using decimal representation when hexadecimal would be better" } @@ -217,7 +217,7 @@ enum WarningType { UnreadableLiteral, InconsistentDigitGrouping, LargeDigitGroups, - BadRepresentation, + DecimalRepresentation, } impl WarningType { @@ -244,11 +244,11 @@ impl WarningType { "digits grouped inconsistently by underscores", &format!("consider: {}", grouping_hint), ), - WarningType::BadRepresentation => span_help_and_lint( + WarningType::DecimalRepresentation => span_help_and_lint( cx, - BAD_LITERAL_REPRESENTATION, + DECIMAL_LITERAL_REPRESENTATION, *span, - "bad representation of integer literal", + "integer literal has a better hexadecimal representation", &format!("consider: {}", grouping_hint), ), }; @@ -400,7 +400,7 @@ pub struct LiteralRepresentation { impl LintPass for LiteralRepresentation { 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" || digits == "F" { - return Err(WarningType::BadRepresentation); + return Err(WarningType::DecimalRepresentation); } } else if digits.len() < 4 { // Lint for Literals with a hex-representation of 2 or 3 digits @@ -467,7 +467,7 @@ impl LiteralRepresentation { // Powers of 2 minus 1 || ((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 { // Lint for Literals with a hex-representation of 4 digits or more @@ -481,7 +481,7 @@ impl LiteralRepresentation { // digit || ((f.eq("7") || f.eq("F")) && s.chars().all(|c| c == '0' || c == 'F')) { - return Err(WarningType::BadRepresentation); + return Err(WarningType::DecimalRepresentation); } } diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index e1298be81e5..2906da3c028 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -177,7 +177,7 @@ define_Conf! { (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' (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), } diff --git a/tests/ui/bad_literal_representation.stderr b/tests/ui/bad_literal_representation.stderr deleted file mode 100644 index ed687c4026e..00000000000 --- a/tests/ui/bad_literal_representation.stderr +++ /dev/null @@ -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 - diff --git a/tests/ui/bad_literal_representation.rs b/tests/ui/decimal_literal_representation.rs similarity index 92% rename from tests/ui/bad_literal_representation.rs rename to tests/ui/decimal_literal_representation.rs index ab12d605596..3ac33d7ac4a 100644 --- a/tests/ui/bad_literal_representation.rs +++ b/tests/ui/decimal_literal_representation.rs @@ -1,7 +1,7 @@ -#[warn(bad_literal_representation)] +#[warn(decimal_literal_representation)] #[allow(unused_variables)] fn main() { // Hex: 7F, 80, 100, 1FF, 800, FFA, F0F3, 7F0F_F00D diff --git a/tests/ui/decimal_literal_representation.stderr b/tests/ui/decimal_literal_representation.stderr new file mode 100644 index 00000000000..bd3c727b728 --- /dev/null +++ b/tests/ui/decimal_literal_representation.stderr @@ -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 + diff --git a/tests/ui/drop_forget_copy.rs b/tests/ui/drop_forget_copy.rs index a4d38d99c95..9fef06b0ede 100644 --- a/tests/ui/drop_forget_copy.rs +++ b/tests/ui/drop_forget_copy.rs @@ -42,7 +42,7 @@ fn main() { forget(s4); 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 mut a3 = a1.clone(); let ref a4 = a1; diff --git a/tests/ui/identity_op.rs b/tests/ui/identity_op.rs index d4bc7df4424..1ed9f974d43 100644 --- a/tests/ui/identity_op.rs +++ b/tests/ui/identity_op.rs @@ -29,5 +29,5 @@ fn main() { -1 & x; let u : u8 = 0; - u & 0xFF; + u & 255; } diff --git a/tests/ui/identity_op.stderr b/tests/ui/identity_op.stderr index b3f7bb713e6..45f579ce832 100644 --- a/tests/ui/identity_op.stderr +++ b/tests/ui/identity_op.stderr @@ -45,6 +45,8 @@ error: the operation is ineffective. Consider reducing it to `x` error: the operation is ineffective. Consider reducing it to `u` --> $DIR/identity_op.rs:32:5 | -32 | u & 0xFF; - | ^^^^^^^^ +32 | u & 255; + | ^^^^^^^ + +error: aborting due to 8 previous errors