You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
charmander on #rust discussed an interesting issue where unreachability of code was inconsistently reported when threads return !. We reduced it to the following example:
#![feature(never_type)]fnrun() -> ! {loop{}}#[allow(dead_code)]fnspawny<F>(closure:F) -> std::thread::JoinHandle<!>whereF:Send + 'static + FnOnce() -> !,{
std::thread::spawn(closure)}fnmain(){// This one results in the println!() being marked unreachablelet handle = spawny(move || run());// This one does not// let handle = std::thread::spawn(move || run());let _res = handle.join().unwrap();println!("hello, world");}
If the thread is spawned via the spawny() function, then println!() is marked unreachable, otherwise if spawned via an in-line std::thread::spawn() call, it is not. In both cases _res has the type !.
The text was updated successfully, but these errors were encountered:
I tested the first snippet and for the second case _res doesn't have the type ! anymore but it is of type (), and handle is of type JoinHandle<()> instead of JoinHandle<!> for the first case, probably why it doesn't warn.
I don't why it does that though because according to the signature of spawn the function should return JoinHandle<T> where T is the return type of the closure
Also the second snippet warns correctly because run() returns never and the compiler directly flags the rest of the code unreachable when there is a never somewhere if I understood correctly
Hi,
charmander
on#rust
discussed an interesting issue where unreachability of code was inconsistently reported when threads return!
. We reduced it to the following example:If the thread is spawned via the
spawny()
function, thenprintln!()
is marked unreachable, otherwise if spawned via an in-linestd::thread::spawn()
call, it is not. In both cases_res
has the type!
.The text was updated successfully, but these errors were encountered: