-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #6568 - Jarcho:redundant_pattern_matching, r=flip1995
Fix: redundant_pattern_matching drop order Fixes #5746 A note about the change in drop order is added when the scrutinee (or any temporary in the expression) isn't known to be safe to drop in any order (i.e. doesn't implement the `Drop` trait, or contain such a type). There is a whitelist for some `std` types, but it's incomplete. Currently just `Vec<_>`, `Box<_>`, `Rc<_>` and `Arc<_>`, but only if the contained type is also safe to drop in any order. Another lint for when the drop order changes could be added as allowed by default, but the drop order requirement is pretty subtle in this case. I think the note added to the lint should be enough to make someone think before applying the change. changelog: Added a note to `redundant_pattern_matching` when the change in drop order might matter
- Loading branch information
Showing
13 changed files
with
581 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} | ||
} |
Oops, something went wrong.