Closed
Description
The select! macro doesn't work if you try to reference a Receiver (Port) in a struct. huon reviewed this in the IRC room and agreed I should file an issue on it.
Here are two attempts to do this and both fail at compile time:
use std::io::Timer;
struct A {
c: Sender<~str>,
p: Receiver<~str>
}
fn does_not_compile() {
let (ch, pt): (Sender<~str>, Receiver<~str>) = channel();
let a = A{c: ch, p: pt};
let mut timer = Timer::new().unwrap();
let timeout = timer.oneshot(1000);
select! (
s = a.p.recv() => println!("{:s}", s), // error: no rules expected the token `.`
() = timeout.recv() => println!("time out!")
);
}
fn also_does_not_compile() {
let (ch, pt): (Sender<~str>, Receiver<~str>) = channel();
let a = A{c: ch, p: pt};
let mut timer = Timer::new().unwrap();
let timeout = timer.oneshot(1000);
let p = &a.p;
select! (
s = p.recv() => println!("{:s}", s), // see error below
() = timeout.recv() => println!("time out!")
);
}
/*
<std macros>:7:37: 7:41 error: mismatched types: expected `&std::comm::Receiver<<generic #45>>` but found `&&std::comm::Receiver<~str>` (expected struct std::comm::Receiver but found &-ptr)
<std macros>:7 $( let mut $rx = sel.handle(&$rx); )+
^~~~
<std macros>:1:1: 15:2 note: in expansion of select!
selfport.rs:21:5: 24:7 note: expansion site
selfport.rs:22:42: 22:43 error: cannot determine a type for this bounded type parameter: unconstrained type
selfport.rs:22 s = p.recv() => println!("{:s}", s), // error: no rules expected the token `.`
*/