tokio-rs / tokio

A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...

Home Page:https://tokio.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`tokio::main` `v1.37.0` break lint `forbid(unreachable_code)` on rust `1.76`

afifurrohman-id opened this issue · comments

Version
Cargo.toml

[package]
name = "app"
edition = "2021"

[dependencies]
tokio = { version = "1.37.0", features = ["rt", "macros"] }

Platform
The output of uname -a (UNIX), or version and 32 or 64-bit (Windows)

Linux 🦀 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023 x86_64 GNU/Linux

Description
When using tokio::main macro with rust 1.76 it break the forbid(unreachable_code) and throw compile error, using ? for std::env::var() function, but using rust 1.77 it doesn't happen.

I tried this code:

#![forbid(unreachable_code)]

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let e = std::env::var("OK")?;
    println!("{e}");
    Ok(())
}

I expected to see this happen: no compile error, as rust 1.77 does.

Instead, this happened:

  --> src/main.rs:6:13
   |
 2 | #![forbid(unreachable_code)]
   |           ---------------- `forbid` level set here
 ...
 6 |     let e = std::env::var("OK")?;
   |             ^^^^^^^^^^^^^^^^^^^^ overruled by previous forbid
 
 For more information about this error, try `rustc --explain E0453`

I definitely do not recommend using forbid on the lints other than unsafe_code lint. They will constant improvement/change, and code that was not warned at the release time may become unavailable.
See taiki-e/pin-project-lite#33 (comment) and taiki-e/pin-project-lite#33 (comment) for more.

As explained in the comments linked above, I believe this is a problem on the part of the user using forbid.