mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 06:28:42 +00:00
Apply requested changes
This commit is contained in:
parent
d7677fb2b6
commit
600147926b
9 changed files with 77 additions and 75 deletions
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
@ -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
|
59
tests/ui/decimal_literal_representation.stderr
Normal file
59
tests/ui/decimal_literal_representation.stderr
Normal 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
|
||||
|
|
@ -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;
|
||||
|
|
|
@ -29,5 +29,5 @@ fn main() {
|
|||
-1 & x;
|
||||
|
||||
let u : u8 = 0;
|
||||
u & 0xFF;
|
||||
u & 255;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue