tokio-rs / tokio

A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...
https://tokio.rs
MIT License
26.77k stars 2.47k forks source link

`#[tokio::main]` proc macro attaches questionable spans to user code #5518

Open jonas-schievink opened 1 year ago

jonas-schievink commented 1 year ago

Version tokio-macros 1.8.2

Platform n/a

Description

In the following code, the variable; statement has incorrect spans attached to itself:

#[tokio::main]
async fn main() {
    let variable = "";
    variable;
}

The spans of variable; point to tokio::runtime::Builder::new_multi_thread() in the output of the macro. This causes rust-analyzer to (correctly) highlight variable as a function call and to show the new_multi_thread function on hover.

Please consider not doing this, as it degrades IDE functionality.

Darksonn commented 1 year ago

Thanks for reporting this bug. You are correct that it seems to be using the wrong span. Perhaps the #[tokio::main] macro's span would be better?

jonas-schievink commented 1 year ago

Yeah, Span::call_site() should be a good default

taiki-e commented 1 year ago

These were intended to improve diagnostics (https://github.com/tokio-rs/tokio/pull/3766), but I would accept a patch to improve compatibility with rust-analyzer as long as there are no diagnostics regressions.