dtolnay / async-trait

Type erasure for async trait methods
Apache License 2.0
1.81k stars 84 forks source link

`async fn() -> !` triggers "unreachable expression" warning #266

Closed dtolnay closed 5 months ago

dtolnay commented 5 months ago
#![feature(never_type)]

use async_trait::async_trait;

#[async_trait]
pub trait Trait {
    async fn f() -> !;
}

#[async_trait]
impl Trait for () {
    async fn f() -> ! {
        loop {
            std::thread::sleep(std::time::Duration::from_millis(1));
        }
    }
}
warning: unreachable expression
  --> src/lib.rs:10:1
   |
10 | #[async_trait]
   | ^^^^^^^^^^^^^^
   | |
   | unreachable expression
   | any code following this expression is unreachable
   |
   = note: `#[warn(unreachable_code)]` on by default
   = note: this warning originates in the attribute macro `async_trait` (in Nightly builds, run with -Z macro-backtrace for more info)