Closed
Description
Receiving info about MIR or some other intermediate form in a user error report.
I tried this code which most likely has some lifetime issue that I am yet to resolve:
pub fn accept_cmd(tcp_ctx: &Arc<RwLock<TCP>>, dl_ctx: &Arc<RwLock<DataLink>>, port: u16) {
let s = (*tcp_ctx.write().unwrap()).v_socket();
{
let tcp = &mut (*tcp_ctx.write().unwrap());
match s {
Ok(ref sock) => {
match tcp.v_bind(dl_ctx, *sock, None, port) {
Ok(_) => {
match tcp.v_listen(dl_ctx, *sock) {
Ok(_) => trace!("v_listen() succeeded"),
Err(e) => error!("v_listen: {}", e),
}
}
Err(e) => error!("v_bind: {}", e),
}
}
Err(ref e) => error!("v_socket: {}", e),
}
}
let sock = s.unwrap();
let tcp_ctx_clone = tcp_ctx.clone(); // <------------- Error here
thread::spawn(move || {
loop {
match tcp::v_accept(&tcp_ctx_clone, sock, None) {
Ok(socket) => trace!("v_accept returned {}", socket),
Err(e) => error!("v_accept: {}", e),
}
}
});
}
I should have received information about the scope defined by some part of my code or if the issue is with auto-generated code then possibly no information about an internal scope.
Instead, this happened:
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
--> src/main.rs:128:33
|
128 | let tcp_ctx_clone = tcp_ctx.clone();
| ^^^^^
|
= note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on unknown free region bounded by scope CodeExtent(9898/CallSiteScope { fn_id: NodeId(4519), body_id: NodeId(18425) })...
note: ...so that types are compatible (expected &std::sync::Arc<std::sync::RwLock<tcp::TCP<'_>>>, found &std::sync::Arc<std::sync::RwLock<tcp::TCP<'_>>>)
--> src/main.rs:128:33
|
128 | let tcp_ctx_clone = tcp_ctx.clone();
| ^^^^^
= note: but, the lifetime must be valid for the static lifetime...
note: ...so that the type `[closure@src/main.rs:129:19: 136:6 tcp_ctx_clone:std::sync::Arc<std::sync::RwLock<tcp::TCP<'_>>>, sock:usize]` will meet its required lifetime bounds
--> src/main.rs:129:5
|
129 | thread::spawn(move || {
| ^^^^^^^^^^^^^
Meta
rustc --version --verbose
:
rustc 1.15.0-nightly (ba872f270 2016-11-17)
binary: rustc
commit-hash: ba872f270781ada15426cfac7db20b30b81777dc
commit-date: 2016-11-17
host: x86_64-unknown-linux-gnu
release: 1.15.0-nightly
LLVM version: 3.9