Skip to content

Commit 72bfe07

Browse files
committed
Review comments
1 parent 8208309 commit 72bfe07

File tree

3 files changed

+44
-55
lines changed

3 files changed

+44
-55
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ enum TaskRef<'a> {
862862

863863
impl TaskRef<'_> {
864864
/// Tells if this task will wake up the other task.
865+
#[allow(unreachable_patterns)]
865866
fn will_wake(self, other: Self) -> bool {
866867
match (self, other) {
867868
(Self::Waker(a), Self::Waker(b)) => a.will_wake(b),
@@ -870,7 +871,6 @@ impl TaskRef<'_> {
870871
// TODO: Use unreleased will_unpark API.
871872
false
872873
}
873-
#[cfg(feature = "std")]
874874
_ => false,
875875
}
876876
}

src/no_std.rs

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -287,38 +287,46 @@ enum Entry {
287287
Sentinel,
288288
}
289289

290-
impl fmt::Debug for Entry {
290+
struct TakenState<'a> {
291+
slot: &'a Cell<State>,
292+
state: State,
293+
}
294+
295+
impl Drop for TakenState<'_> {
296+
fn drop(&mut self) {
297+
self.slot
298+
.set(mem::replace(&mut self.state, State::NotifiedTaken));
299+
}
300+
}
301+
302+
impl fmt::Debug for TakenState<'_> {
291303
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
292-
struct TakenState<'a> {
293-
state: Option<State>,
294-
cell: &'a Cell<State>,
295-
}
304+
fmt::Debug::fmt(&self.state, f)
305+
}
306+
}
296307

297-
impl Drop for TakenState<'_> {
298-
fn drop(&mut self) {
299-
self.cell.set(self.state.take().unwrap());
300-
}
301-
}
308+
impl PartialEq for TakenState<'_> {
309+
fn eq(&self, other: &Self) -> bool {
310+
self.state == other.state
311+
}
312+
}
302313

303-
impl fmt::Debug for TakenState<'_> {
304-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
305-
fmt::Debug::fmt(self.state.as_ref().unwrap(), f)
306-
}
307-
}
314+
impl<'a> TakenState<'a> {
315+
fn new(slot: &'a Cell<State>) -> Self {
316+
let state = slot.replace(State::NotifiedTaken);
317+
Self { slot, state }
318+
}
319+
}
308320

321+
impl fmt::Debug for Entry {
322+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
309323
match self {
310-
Entry::Listener { state, next, prev } => {
311-
let taken = TakenState {
312-
state: Some(state.replace(State::Created)),
313-
cell: state,
314-
};
315-
316-
f.debug_struct("Listener")
317-
.field("state", &taken)
318-
.field("prev", prev)
319-
.field("next", next)
320-
.finish()
321-
}
324+
Entry::Listener { state, next, prev } => f
325+
.debug_struct("Listener")
326+
.field("state", &TakenState::new(state))
327+
.field("prev", prev)
328+
.field("next", next)
329+
.finish(),
322330
Entry::Empty(next) => f.debug_tuple("Empty").field(next).finish(),
323331
Entry::Sentinel => f.debug_tuple("Sentinel").finish(),
324332
}
@@ -327,17 +335,6 @@ impl fmt::Debug for Entry {
327335

328336
impl PartialEq for Entry {
329337
fn eq(&self, other: &Entry) -> bool {
330-
struct RestoreState<'a> {
331-
state: Option<State>,
332-
cell: &'a Cell<State>,
333-
}
334-
335-
impl Drop for RestoreState<'_> {
336-
fn drop(&mut self) {
337-
self.cell.set(self.state.take().unwrap());
338-
}
339-
}
340-
341338
match (self, other) {
342339
(
343340
Self::Listener {
@@ -351,17 +348,7 @@ impl PartialEq for Entry {
351348
next: next2,
352349
},
353350
) => {
354-
let taken1 = RestoreState {
355-
state: Some(state1.replace(State::Created)),
356-
cell: state1,
357-
};
358-
359-
let taken2 = RestoreState {
360-
state: Some(state2.replace(State::Created)),
361-
cell: state2,
362-
};
363-
364-
if taken1.state != taken2.state {
351+
if TakenState::new(state1) != TakenState::new(state2) {
365352
return false;
366353
}
367354

src/std.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,13 @@ impl crate::Inner {
141141

142142
State::Task(other_task) => {
143143
// Only replace the task if it's different.
144-
if !task.will_wake(other_task.as_task_ref()) {
145-
entry.state.set(State::Task(task.into_task()));
146-
} else {
147-
entry.state.set(State::Task(other_task));
148-
}
144+
entry.state.set(State::Task({
145+
if !task.will_wake(other_task.as_task_ref()) {
146+
task.into_task()
147+
} else {
148+
other_task
149+
}
150+
}));
149151

150152
Some(false)
151153
}

0 commit comments

Comments
 (0)