Skip to content

Commit 678f506

Browse files
committed
fix recv_ready for Port to take &self and not need to return a tuple. Close #8192.
1 parent 29ffbba commit 678f506

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/libstd/rt/comm.rs

+25-4
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,11 @@ impl<T> Peekable<T> for Port<T> {
508508
}
509509
}
510510

511-
impl<T> Select for Port<T> {
511+
// XXX: Kind of gross. A Port<T> should be selectable so you can make an array
512+
// of them, but a &Port<T> should also be selectable so you can select2 on it
513+
// alongside a PortOne<U> without passing the port by value in recv_ready.
514+
515+
impl<'self, T> Select for &'self Port<T> {
512516
#[inline]
513517
fn optimistic_check(&mut self) -> bool {
514518
do self.next.with_mut_ref |pone| { pone.optimistic_check() }
@@ -526,12 +530,29 @@ impl<T> Select for Port<T> {
526530
}
527531
}
528532

529-
impl<T> SelectPort<(T, Port<T>)> for Port<T> {
530-
fn recv_ready(self) -> Option<(T, Port<T>)> {
533+
impl<T> Select for Port<T> {
534+
#[inline]
535+
fn optimistic_check(&mut self) -> bool {
536+
(&*self).optimistic_check()
537+
}
538+
539+
#[inline]
540+
fn block_on(&mut self, sched: &mut Scheduler, task: BlockedTask) -> bool {
541+
(&*self).block_on(sched, task)
542+
}
543+
544+
#[inline]
545+
fn unblock_from(&mut self) -> bool {
546+
(&*self).unblock_from()
547+
}
548+
}
549+
550+
impl<'self, T> SelectPort<T> for &'self Port<T> {
551+
fn recv_ready(self) -> Option<T> {
531552
match self.next.take().recv_ready() {
532553
Some(StreamPayload { val, next }) => {
533554
self.next.put_back(next);
534-
Some((val, self))
555+
Some(val)
535556
}
536557
None => None
537558
}

src/libstd/rt/select.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@ mod test {
199199
// get it back out
200200
util::swap(port.get_mut_ref(), &mut ports[index]);
201201
// NB. Not recv(), because optimistic_check randomly fails.
202-
let (data, new_port) = port.take_unwrap().recv_ready().unwrap();
203-
assert!(data == 31337);
204-
port = Some(new_port);
202+
assert!(port.get_ref().recv_ready().unwrap() == 31337);
205203
}
206204
}
207205
}

0 commit comments

Comments
 (0)