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
Platform
Darwin 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:02:27 PDT 2024; root:xnu-11215.41.3~2/RELEASE_X86_64 x86_64
Description
Extra code for Infallible type gives false warning.
What's wrong in writing a service as an infinite loop? And an infinite loop clearly has type Infallible.
asyncfnserver() -> Infallible{loop{
...occasionally it may panic!()}}
And I usually run this as
#[tokio::main]asyncfnmain(){let s = tokio::spawn(server());let r = tokio::try_join!(s1);
...}
Because I want to know about errors inside that server().
And that compiles and works perfectly.
But what if I want to put several workers/servers in the same process?
#[tokio::main]asyncfnmain(){let s1 = tokio::spawn(server());let s2 = tokio::spawn(server());let r = tokio::try_join!(s1, s2);// (A)println!("reachable unreachable, r = {:?}", r);// (B)}
This still compiles and works perfectly, but now the compiler complains about unreachable code.
warning: unreachable definition
--> src/main.rs:11:13
|
11 | let r = tokio::try_join!(s1, s2);// (A)
| ^^^^^^^^^^^^^^^^^^^^^^^^
| |
| unreachable definition
| any code following this expression is unreachable
|
note: this expression has type `Infallible`, which is uninhabited
--> src/main.rs:11:13
|
11 | let r = tokio::try_join!(s1, s2);// (A)
| ^^^^^^^^^^^^^^^^^^^^^^^^
= note: `#[warn(unreachable_code)]` on by default
= note: this warning originates in the macro `$crate::try_join` which comes from the expansion of the macro `tokio::try_join` (in Nightlybuilds, run with -Z macro-backtrace for more info)
Actually, my code is reachable, because Result<Infallible, JoinError> is inhabited, and line (B) prints something like reachable unreachable, r = Err(JoinError::Panic(Id(10), "explicit panic", ...)).
The unreacheble part is the block inside try_join that creates successful result.
Can we skip generating impossible code or at least hush this warning inside the macro?
The text was updated successfully, but these errors were encountered:
Version
1.42.0
Platform
Darwin 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:02:27 PDT 2024; root:xnu-11215.41.3~2/RELEASE_X86_64 x86_64
Description
Extra code for Infallible type gives false warning.
What's wrong in writing a service as an infinite loop? And an infinite loop clearly has type
Infallible
.And I usually run this as
Because I want to know about errors inside that server().
And that compiles and works perfectly.
But what if I want to put several workers/servers in the same process?
This still compiles and works perfectly, but now the compiler complains about unreachable code.
Actually, my code is reachable, because
Result<Infallible, JoinError>
is inhabited, and line (B) prints something likereachable unreachable, r = Err(JoinError::Panic(Id(10), "explicit panic", ...))
.The unreacheble part is the block inside
try_join
that creates successful result.Can we skip generating impossible code or at least hush this warning inside the macro?
The text was updated successfully, but these errors were encountered: