Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace non-binding if let statements #4735

Merged
merged 2 commits into from Jun 3, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions tokio/src/sync/notify.rs
Expand Up @@ -501,7 +501,7 @@ impl Notify {
// transition out of WAITING while the lock is held.
let curr = self.state.load(SeqCst);

if let EMPTY | NOTIFIED = get_state(curr) {
if matches!(get_state(curr), EMPTY | NOTIFIED) {
// There are no waiting tasks. All we need to do is increment the
// number of times this method was called.
atomic_inc_num_notify_waiters_calls(&self.state);
Expand Down Expand Up @@ -896,7 +896,7 @@ impl Drop for Notified<'_> {
// This is where we ensure safety. The `Notified` value is being
// dropped, which means we must ensure that the waiter entry is no
// longer stored in the linked list.
if let Waiting = *state {
if matches!(*state, Waiting) {
djkoloski marked this conversation as resolved.
Show resolved Hide resolved
let mut waiters = notify.waiters.lock();
let mut notify_state = notify.state.load(SeqCst);

Expand All @@ -907,7 +907,7 @@ impl Drop for Notified<'_> {
unsafe { waiters.remove(NonNull::new_unchecked(waiter.get())) };

if waiters.is_empty() {
if let WAITING = get_state(notify_state) {
if get_state(notify_state) == WAITING {
notify_state = set_state(notify_state, EMPTY);
notify.state.store(notify_state, SeqCst);
}
Expand All @@ -919,7 +919,7 @@ impl Drop for Notified<'_> {
//
// Safety: with the entry removed from the linked list, there can be
// no concurrent access to the entry
if let Some(NotificationType::OneWaiter) = unsafe { (*waiter.get()).notified } {
if matches!(unsafe { (*waiter.get()).notified }, Some(NotificationType::OneWaiter)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a rustfmt warning here.

if let Some(waker) = notify_locked(&mut waiters, &notify.state, notify_state) {
drop(waiters);
waker.wake();
Expand Down