Skip to content

Commit

Permalink
Remove/move comments to prevent weird rustfmt wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jul 28, 2023
1 parent 3c68f06 commit c4e4641
Show file tree
Hide file tree
Showing 45 changed files with 819 additions and 589 deletions.
24 changes: 16 additions & 8 deletions tests/ui/bytecount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@
fn main() {
let x = vec![0_u8; 16];

let _ = x.iter().filter(|&&a| a == 0).count(); // naive byte count
// naive byte count
let _ = x.iter().filter(|&&a| a == 0).count();

let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); // naive byte count
// naive byte count
let _ = (&x[..]).iter().filter(|&a| *a == 0).count();

let _ = x.iter().filter(|a| **a > 0).count(); // not an equality count, OK.
// not an equality count, OK.
let _ = x.iter().filter(|a| **a > 0).count();

let _ = x.iter().map(|a| a + 1).filter(|&a| a < 15).count(); // not a slice
// not a slice
let _ = x.iter().map(|a| a + 1).filter(|&a| a < 15).count();

let b = 0;

let _ = x.iter().filter(|_| b > 0).count(); // woah there
// woah there
let _ = x.iter().filter(|_| b > 0).count();

let _ = x.iter().filter(|_a| b == b + 1).count(); // nothing to see here, move along
// nothing to see here, move along
let _ = x.iter().filter(|_a| b == b + 1).count();

let _ = x.iter().filter(|a| b + 1 == **a).count(); // naive byte count
// naive byte count
let _ = x.iter().filter(|a| b + 1 == **a).count();

let y = vec![0_u16; 3];

let _ = y.iter().filter(|&&a| a == 0).count(); // naive count, but not bytes
// naive count, but not bytes
let _ = y.iter().filter(|&&a| a == 0).count();
}
12 changes: 6 additions & 6 deletions tests/ui/bytecount.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error: you appear to be counting bytes the naive way
--> $DIR/bytecount.rs:7:13
--> $DIR/bytecount.rs:8:13
|
LL | let _ = x.iter().filter(|&&a| a == 0).count(); // naive byte count
LL | let _ = x.iter().filter(|&&a| a == 0).count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count(x, 0)`
|
note: the lint level is defined here
Expand All @@ -11,15 +11,15 @@ LL | #[deny(clippy::naive_bytecount)]
| ^^^^^^^^^^^^^^^^^^^^^^^

error: you appear to be counting bytes the naive way
--> $DIR/bytecount.rs:9:13
--> $DIR/bytecount.rs:11:13
|
LL | let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); // naive byte count
LL | let _ = (&x[..]).iter().filter(|&a| *a == 0).count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count((&x[..]), 0)`

error: you appear to be counting bytes the naive way
--> $DIR/bytecount.rs:21:13
--> $DIR/bytecount.rs:28:13
|
LL | let _ = x.iter().filter(|a| b + 1 == **a).count(); // naive byte count
LL | let _ = x.iter().filter(|a| b + 1 == **a).count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count(x, b + 1)`

error: aborting due to 3 previous errors
Expand Down
81 changes: 54 additions & 27 deletions tests/ui/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,22 @@ fn main() {
1u32 as i32;
1u64 as i64;
1usize as isize;
1usize as i8; // should not wrap, usize is never 8 bits
1usize as i16; // wraps on 16 bit ptr size
1usize as i32; // wraps on 32 bit ptr size
1usize as i64; // wraps on 64 bit ptr size
1u8 as isize; // should not wrap, isize is never 8 bits
1u16 as isize; // wraps on 16 bit ptr size
1u32 as isize; // wraps on 32 bit ptr size
1u64 as isize; // wraps on 64 bit ptr size
// should not wrap, usize is never 8 bits
1usize as i8;
// wraps on 16 bit ptr size
1usize as i16;
// wraps on 32 bit ptr size
1usize as i32;
// wraps on 64 bit ptr size
1usize as i64;
// should not wrap, isize is never 8 bits
1u8 as isize;
// wraps on 16 bit ptr size
1u16 as isize;
// wraps on 32 bit ptr size
1u32 as isize;
// wraps on 64 bit ptr size
1u64 as isize;
// Test clippy::cast_sign_loss
1i32 as u32;
-1i32 as u32;
Expand Down Expand Up @@ -120,7 +128,8 @@ fn main() {
let _ = s as i32;

// Test for signed min
(-99999999999i64).min(1) as i8; // should be linted because signed
// should be linted because signed
(-99999999999i64).min(1) as i8;

// Test for various operations that remove enough bits for the result to fit
(999999u64 & 1) as u8;
Expand All @@ -132,7 +141,8 @@ fn main() {
x.min(1)
}) as u8;
999999u64.clamp(0, 255) as u8;
999999u64.clamp(0, 256) as u8; // should still be linted
// should still be linted
999999u64.clamp(0, 256) as u8;

#[derive(Clone, Copy)]
enum E1 {
Expand All @@ -142,7 +152,8 @@ fn main() {
}
impl E1 {
fn test(self) {
let _ = self as u8; // Don't lint. `0..=2` fits in u8
// Don't lint. `0..=2` fits in u8
let _ = self as u8;
}
}

Expand All @@ -155,8 +166,10 @@ fn main() {
fn test(self) {
let _ = self as u8;
let _ = Self::B as u8;
let _ = self as i16; // Don't lint. `255..=256` fits in i16
let _ = Self::A as u8; // Don't lint.
// Don't lint. `255..=256` fits in i16
let _ = self as i16;
// Don't lint.
let _ = Self::A as u8;
}
}

Expand All @@ -168,7 +181,8 @@ fn main() {
}
impl E3 {
fn test(self) {
let _ = self as i8; // Don't lint. `-1..=50` fits in i8
// Don't lint. `-1..=50` fits in i8
let _ = self as i8;
}
}

Expand All @@ -179,7 +193,8 @@ fn main() {
}
impl E4 {
fn test(self) {
let _ = self as i8; // Don't lint. `-128..=-127` fits in i8
// Don't lint. `-128..=-127` fits in i8
let _ = self as i8;
}
}

Expand All @@ -192,8 +207,10 @@ fn main() {
fn test(self) {
let _ = self as i8;
let _ = Self::A as i8;
let _ = self as i16; // Don't lint. `-129..=127` fits in i16
let _ = Self::B as u8; // Don't lint.
// Don't lint. `-129..=127` fits in i16
let _ = self as i16;
// Don't lint.
let _ = Self::B as u8;
}
}

Expand All @@ -206,9 +223,12 @@ fn main() {
impl E6 {
fn test(self) {
let _ = self as i16;
let _ = Self::A as u16; // Don't lint. `2^16-1` fits in u16
let _ = self as u32; // Don't lint. `2^16-1..=2^16` fits in u32
let _ = Self::A as u16; // Don't lint.
// Don't lint. `2^16-1` fits in u16
let _ = Self::A as u16;
// Don't lint. `2^16-1..=2^16` fits in u32
let _ = self as u32;
// Don't lint.
let _ = Self::A as u16;
}
}

Expand All @@ -221,8 +241,10 @@ fn main() {
impl E7 {
fn test(self) {
let _ = self as usize;
let _ = Self::A as usize; // Don't lint.
let _ = self as u64; // Don't lint. `2^32-1..=2^32` fits in u64
// Don't lint.
let _ = Self::A as usize;
// Don't lint. `2^32-1..=2^32` fits in u64
let _ = self as u64;
}
}

Expand All @@ -236,7 +258,8 @@ fn main() {
}
impl E8 {
fn test(self) {
let _ = self as i128; // Don't lint. `-(2^127)..=2^127-1` fits it i128
// Don't lint. `-(2^127)..=2^127-1` fits it i128
let _ = self as i128;
}
}

Expand All @@ -248,8 +271,10 @@ fn main() {
}
impl E9 {
fn test(self) {
let _ = Self::A as u8; // Don't lint.
let _ = self as u128; // Don't lint. `0..=2^128-1` fits in u128
// Don't lint.
let _ = Self::A as u8;
// Don't lint. `0..=2^128-1` fits in u128
let _ = self as u128;
}
}

Expand All @@ -262,8 +287,10 @@ fn main() {
impl E10 {
fn test(self) {
let _ = self as u16;
let _ = Self::B as u32; // Don't lint.
let _ = self as u64; // Don't lint.
// Don't lint.
let _ = Self::B as u32;
// Don't lint.
let _ = self as u64;
}
}
}
Expand Down
Loading

0 comments on commit c4e4641

Please sign in to comment.