Skip to content

Commit

Permalink
Fix: Move tests into a new file. stderror was too long
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarcho committed Jan 14, 2021
1 parent eb6a20d commit ffd759d
Show file tree
Hide file tree
Showing 12 changed files with 311 additions and 300 deletions.
58 changes: 58 additions & 0 deletions tests/ui/redundant_pattern_matching_drop_order.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// run-rustfix

// Issue #5746
#![warn(clippy::redundant_pattern_matching)]
#![allow(clippy::if_same_then_else)]
use std::task::Poll::{Pending, Ready};

fn main() {
let m = std::sync::Mutex::new((0, 0));

// Result
if m.lock().is_ok() {}
if Err::<(), _>(m.lock().unwrap().0).is_err() {}

{
if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok() {}
}
if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok() {
} else {
}
if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok() {}
if Err::<std::sync::MutexGuard<()>, _>(()).is_err() {}

if Ok::<_, ()>(String::new()).is_ok() {}
if Err::<(), _>((String::new(), ())).is_err() {}

// Option
if Some(m.lock()).is_some() {}
if Some(m.lock().unwrap().0).is_some() {}

{
if None::<std::sync::MutexGuard<()>>.is_none() {}
}
if None::<std::sync::MutexGuard<()>>.is_none() {
} else {
}

if None::<std::sync::MutexGuard<()>>.is_none() {}

if Some(String::new()).is_some() {}
if Some((String::new(), ())).is_some() {}

// Poll
if Ready(m.lock()).is_ready() {}
if Ready(m.lock().unwrap().0).is_ready() {}

{
if Pending::<std::sync::MutexGuard<()>>.is_pending() {}
}
if Pending::<std::sync::MutexGuard<()>>.is_pending() {
} else {
}

if Pending::<std::sync::MutexGuard<()>>.is_pending() {}

if Ready(String::new()).is_ready() {}
if Ready((String::new(), ())).is_ready() {}
}
58 changes: 58 additions & 0 deletions tests/ui/redundant_pattern_matching_drop_order.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// run-rustfix

// Issue #5746
#![warn(clippy::redundant_pattern_matching)]
#![allow(clippy::if_same_then_else)]
use std::task::Poll::{Pending, Ready};

fn main() {
let m = std::sync::Mutex::new((0, 0));

// Result
if let Ok(_) = m.lock() {}
if let Err(_) = Err::<(), _>(m.lock().unwrap().0) {}

{
if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {}
}
if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {
} else {
}
if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {}
if let Err(_) = Err::<std::sync::MutexGuard<()>, _>(()) {}

if let Ok(_) = Ok::<_, ()>(String::new()) {}
if let Err(_) = Err::<(), _>((String::new(), ())) {}

// Option
if let Some(_) = Some(m.lock()) {}
if let Some(_) = Some(m.lock().unwrap().0) {}

{
if let None = None::<std::sync::MutexGuard<()>> {}
}
if let None = None::<std::sync::MutexGuard<()>> {
} else {
}

if let None = None::<std::sync::MutexGuard<()>> {}

if let Some(_) = Some(String::new()) {}
if let Some(_) = Some((String::new(), ())) {}

// Poll
if let Ready(_) = Ready(m.lock()) {}
if let Ready(_) = Ready(m.lock().unwrap().0) {}

{
if let Pending = Pending::<std::sync::MutexGuard<()>> {}
}
if let Pending = Pending::<std::sync::MutexGuard<()>> {
} else {
}

if let Pending = Pending::<std::sync::MutexGuard<()>> {}

if let Ready(_) = Ready(String::new()) {}
if let Ready(_) = Ready((String::new(), ())) {}
}
171 changes: 171 additions & 0 deletions tests/ui/redundant_pattern_matching_drop_order.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching_drop_order.rs:12:12
|
LL | if let Ok(_) = m.lock() {}
| -------^^^^^----------- help: try this: `if m.lock().is_ok()`
|
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important

error: redundant pattern matching, consider using `is_err()`
--> $DIR/redundant_pattern_matching_drop_order.rs:13:12
|
LL | if let Err(_) = Err::<(), _>(m.lock().unwrap().0) {}
| -------^^^^^^------------------------------------ help: try this: `if Err::<(), _>(m.lock().unwrap().0).is_err()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important

error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching_drop_order.rs:16:16
|
LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {}
| -------^^^^^----------------------------------------- help: try this: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important

error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching_drop_order.rs:18:12
|
LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {
| -------^^^^^----------------------------------------- help: try this: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important

error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching_drop_order.rs:21:12
|
LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {}
| -------^^^^^----------------------------------------- help: try this: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()`

error: redundant pattern matching, consider using `is_err()`
--> $DIR/redundant_pattern_matching_drop_order.rs:22:12
|
LL | if let Err(_) = Err::<std::sync::MutexGuard<()>, _>(()) {}
| -------^^^^^^------------------------------------------ help: try this: `if Err::<std::sync::MutexGuard<()>, _>(()).is_err()`

error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching_drop_order.rs:24:12
|
LL | if let Ok(_) = Ok::<_, ()>(String::new()) {}
| -------^^^^^----------------------------- help: try this: `if Ok::<_, ()>(String::new()).is_ok()`

error: redundant pattern matching, consider using `is_err()`
--> $DIR/redundant_pattern_matching_drop_order.rs:25:12
|
LL | if let Err(_) = Err::<(), _>((String::new(), ())) {}
| -------^^^^^^------------------------------------ help: try this: `if Err::<(), _>((String::new(), ())).is_err()`

error: redundant pattern matching, consider using `is_some()`
--> $DIR/redundant_pattern_matching_drop_order.rs:28:12
|
LL | if let Some(_) = Some(m.lock()) {}
| -------^^^^^^^----------------- help: try this: `if Some(m.lock()).is_some()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important

error: redundant pattern matching, consider using `is_some()`
--> $DIR/redundant_pattern_matching_drop_order.rs:29:12
|
LL | if let Some(_) = Some(m.lock().unwrap().0) {}
| -------^^^^^^^---------------------------- help: try this: `if Some(m.lock().unwrap().0).is_some()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important

error: redundant pattern matching, consider using `is_none()`
--> $DIR/redundant_pattern_matching_drop_order.rs:32:16
|
LL | if let None = None::<std::sync::MutexGuard<()>> {}
| -------^^^^------------------------------------ help: try this: `if None::<std::sync::MutexGuard<()>>.is_none()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important

error: redundant pattern matching, consider using `is_none()`
--> $DIR/redundant_pattern_matching_drop_order.rs:34:12
|
LL | if let None = None::<std::sync::MutexGuard<()>> {
| -------^^^^------------------------------------ help: try this: `if None::<std::sync::MutexGuard<()>>.is_none()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important

error: redundant pattern matching, consider using `is_none()`
--> $DIR/redundant_pattern_matching_drop_order.rs:38:12
|
LL | if let None = None::<std::sync::MutexGuard<()>> {}
| -------^^^^------------------------------------ help: try this: `if None::<std::sync::MutexGuard<()>>.is_none()`

error: redundant pattern matching, consider using `is_some()`
--> $DIR/redundant_pattern_matching_drop_order.rs:40:12
|
LL | if let Some(_) = Some(String::new()) {}
| -------^^^^^^^---------------------- help: try this: `if Some(String::new()).is_some()`

error: redundant pattern matching, consider using `is_some()`
--> $DIR/redundant_pattern_matching_drop_order.rs:41:12
|
LL | if let Some(_) = Some((String::new(), ())) {}
| -------^^^^^^^---------------------------- help: try this: `if Some((String::new(), ())).is_some()`

error: redundant pattern matching, consider using `is_ready()`
--> $DIR/redundant_pattern_matching_drop_order.rs:44:12
|
LL | if let Ready(_) = Ready(m.lock()) {}
| -------^^^^^^^^------------------ help: try this: `if Ready(m.lock()).is_ready()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important

error: redundant pattern matching, consider using `is_ready()`
--> $DIR/redundant_pattern_matching_drop_order.rs:45:12
|
LL | if let Ready(_) = Ready(m.lock().unwrap().0) {}
| -------^^^^^^^^----------------------------- help: try this: `if Ready(m.lock().unwrap().0).is_ready()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important

error: redundant pattern matching, consider using `is_pending()`
--> $DIR/redundant_pattern_matching_drop_order.rs:48:16
|
LL | if let Pending = Pending::<std::sync::MutexGuard<()>> {}
| -------^^^^^^^--------------------------------------- help: try this: `if Pending::<std::sync::MutexGuard<()>>.is_pending()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important

error: redundant pattern matching, consider using `is_pending()`
--> $DIR/redundant_pattern_matching_drop_order.rs:50:12
|
LL | if let Pending = Pending::<std::sync::MutexGuard<()>> {
| -------^^^^^^^--------------------------------------- help: try this: `if Pending::<std::sync::MutexGuard<()>>.is_pending()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important

error: redundant pattern matching, consider using `is_pending()`
--> $DIR/redundant_pattern_matching_drop_order.rs:54:12
|
LL | if let Pending = Pending::<std::sync::MutexGuard<()>> {}
| -------^^^^^^^--------------------------------------- help: try this: `if Pending::<std::sync::MutexGuard<()>>.is_pending()`

error: redundant pattern matching, consider using `is_ready()`
--> $DIR/redundant_pattern_matching_drop_order.rs:56:12
|
LL | if let Ready(_) = Ready(String::new()) {}
| -------^^^^^^^^----------------------- help: try this: `if Ready(String::new()).is_ready()`

error: redundant pattern matching, consider using `is_ready()`
--> $DIR/redundant_pattern_matching_drop_order.rs:57:12
|
LL | if let Ready(_) = Ready((String::new(), ())) {}
| -------^^^^^^^^----------------------------- help: try this: `if Ready((String::new(), ())).is_ready()`

error: aborting due to 22 previous errors

18 changes: 0 additions & 18 deletions tests/ui/redundant_pattern_matching_option.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,6 @@ fn main() {
} else {
3
};

// Issue #5746
let m = std::sync::Mutex::new((0, 0));

if Some(m.lock()).is_some() {}
if Some(m.lock().unwrap().0).is_some() {}

{
if None::<std::sync::MutexGuard<()>>.is_none() {}
}
if None::<std::sync::MutexGuard<()>>.is_none() {
} else {
}

if None::<std::sync::MutexGuard<()>>.is_none() {}

if Some(String::new()).is_some() {}
if Some((String::new(), ())).is_some() {}
}

fn gen_opt() -> Option<()> {
Expand Down
18 changes: 0 additions & 18 deletions tests/ui/redundant_pattern_matching_option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,6 @@ fn main() {
} else {
3
};

// Issue #5746
let m = std::sync::Mutex::new((0, 0));

if let Some(_) = Some(m.lock()) {}
if let Some(_) = Some(m.lock().unwrap().0) {}

{
if let None = None::<std::sync::MutexGuard<()>> {}
}
if let None = None::<std::sync::MutexGuard<()>> {
} else {
}

if let None = None::<std::sync::MutexGuard<()>> {}

if let Some(_) = Some(String::new()) {}
if let Some(_) = Some((String::new(), ())) {}
}

fn gen_opt() -> Option<()> {
Expand Down
Loading

0 comments on commit ffd759d

Please sign in to comment.