Use snippet_with_context more

This commit is contained in:
Jason Newcomb 2023-03-02 14:29:45 -05:00
parent 113c704d22
commit efbcb99b73
17 changed files with 159 additions and 129 deletions

View file

@ -16,7 +16,7 @@ fn str_to_int_ok(x: &str) -> i32 {
#[rustfmt::skip]
fn strange_some_no_else(x: &str) -> i32 {
{
if let Ok(y) = x . parse() {
if let Ok(y) = x . parse() {
return y;
};
0

View file

@ -18,7 +18,7 @@ LL | if let Some(y) = x . parse() . ok () {
|
help: consider matching on `Ok(y)` and removing the call to `ok` instead
|
LL | if let Ok(y) = x . parse() {
LL | if let Ok(y) = x . parse() {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: matching on `Some` with `ok()` is redundant

View file

@ -65,19 +65,19 @@ fn xor_swap_locals() {
// This is an xor-based swap of local variables.
let mut a = 0;
let mut b = 1;
std::mem::swap(&mut a, &mut b)
std::mem::swap(&mut a, &mut b);
}
fn xor_field_swap() {
// This is an xor-based swap of fields in a struct.
let mut bar = Bar { a: 0, b: 1 };
std::mem::swap(&mut bar.a, &mut bar.b)
std::mem::swap(&mut bar.a, &mut bar.b);
}
fn xor_slice_swap() {
// This is an xor-based swap of a slice
let foo = &mut [1, 2];
foo.swap(0, 1)
foo.swap(0, 1);
}
fn xor_no_swap() {

View file

@ -4,7 +4,7 @@ error: this looks like you are swapping `bar.a` and `bar.b` manually
LL | / let temp = bar.a;
LL | | bar.a = bar.b;
LL | | bar.b = temp;
| |________________^ help: try: `std::mem::swap(&mut bar.a, &mut bar.b)`
| |_________________^ help: try: `std::mem::swap(&mut bar.a, &mut bar.b);`
|
= note: or maybe you should use `std::mem::replace`?
= note: `-D clippy::manual-swap` implied by `-D warnings`
@ -15,7 +15,7 @@ error: this looks like you are swapping elements of `foo` manually
LL | / let temp = foo[0];
LL | | foo[0] = foo[1];
LL | | foo[1] = temp;
| |_________________^ help: try: `foo.swap(0, 1)`
| |__________________^ help: try: `foo.swap(0, 1);`
error: this looks like you are swapping elements of `foo` manually
--> $DIR/swap.rs:46:5
@ -23,7 +23,7 @@ error: this looks like you are swapping elements of `foo` manually
LL | / let temp = foo[0];
LL | | foo[0] = foo[1];
LL | | foo[1] = temp;
| |_________________^ help: try: `foo.swap(0, 1)`
| |__________________^ help: try: `foo.swap(0, 1);`
error: this looks like you are swapping elements of `foo` manually
--> $DIR/swap.rs:65:5
@ -31,7 +31,7 @@ error: this looks like you are swapping elements of `foo` manually
LL | / let temp = foo[0];
LL | | foo[0] = foo[1];
LL | | foo[1] = temp;
| |_________________^ help: try: `foo.swap(0, 1)`
| |__________________^ help: try: `foo.swap(0, 1);`
error: this looks like you are swapping `a` and `b` manually
--> $DIR/swap.rs:76:5
@ -39,7 +39,7 @@ error: this looks like you are swapping `a` and `b` manually
LL | / a ^= b;
LL | | b ^= a;
LL | | a ^= b;
| |___________^ help: try: `std::mem::swap(&mut a, &mut b)`
| |___________^ help: try: `std::mem::swap(&mut a, &mut b);`
error: this looks like you are swapping `bar.a` and `bar.b` manually
--> $DIR/swap.rs:84:5
@ -47,7 +47,7 @@ error: this looks like you are swapping `bar.a` and `bar.b` manually
LL | / bar.a ^= bar.b;
LL | | bar.b ^= bar.a;
LL | | bar.a ^= bar.b;
| |___________________^ help: try: `std::mem::swap(&mut bar.a, &mut bar.b)`
| |___________________^ help: try: `std::mem::swap(&mut bar.a, &mut bar.b);`
error: this looks like you are swapping elements of `foo` manually
--> $DIR/swap.rs:92:5
@ -55,7 +55,7 @@ error: this looks like you are swapping elements of `foo` manually
LL | / foo[0] ^= foo[1];
LL | | foo[1] ^= foo[0];
LL | | foo[0] ^= foo[1];
| |_____________________^ help: try: `foo.swap(0, 1)`
| |_____________________^ help: try: `foo.swap(0, 1);`
error: this looks like you are swapping `foo[0][1]` and `bar[1][0]` manually
--> $DIR/swap.rs:121:5
@ -63,7 +63,7 @@ error: this looks like you are swapping `foo[0][1]` and `bar[1][0]` manually
LL | / let temp = foo[0][1];
LL | | foo[0][1] = bar[1][0];
LL | | bar[1][0] = temp;
| |____________________^ help: try: `std::mem::swap(&mut foo[0][1], &mut bar[1][0])`
| |_____________________^ help: try: `std::mem::swap(&mut foo[0][1], &mut bar[1][0]);`
|
= note: or maybe you should use `std::mem::replace`?
@ -74,7 +74,7 @@ LL | ; let t = a;
| _______^
LL | | a = b;
LL | | b = t;
| |_________^ help: try: `std::mem::swap(&mut a, &mut b)`
| |__________^ help: try: `std::mem::swap(&mut a, &mut b);`
|
= note: or maybe you should use `std::mem::replace`?
@ -85,7 +85,7 @@ LL | ; let t = c.0;
| _______^
LL | | c.0 = a;
LL | | a = t;
| |_________^ help: try: `std::mem::swap(&mut c.0, &mut a)`
| |__________^ help: try: `std::mem::swap(&mut c.0, &mut a);`
|
= note: or maybe you should use `std::mem::replace`?
@ -95,7 +95,7 @@ error: this looks like you are swapping `b` and `a` manually
LL | / let t = b;
LL | | b = a;
LL | | a = t;
| |_________^ help: try: `std::mem::swap(&mut b, &mut a)`
| |__________^ help: try: `std::mem::swap(&mut b, &mut a);`
|
= note: or maybe you should use `std::mem::replace`?
@ -151,7 +151,7 @@ error: this looks like you are swapping `s.0.x` and `s.0.y` manually
LL | / let t = s.0.x;
LL | | s.0.x = s.0.y;
LL | | s.0.y = t;
| |_____________^ help: try: `std::mem::swap(&mut s.0.x, &mut s.0.y)`
| |______________^ help: try: `std::mem::swap(&mut s.0.x, &mut s.0.y);`
|
= note: or maybe you should use `std::mem::replace`?