-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: better spans in #[tokio::main] output #5619
Conversation
There are a few other |
Looks like my patch breaks errors which should point to user code, e.g. when the body of
becomes
This can be fixed by asserting the right type for the body earlier within a span that points back to user code. One thing I've tried is changing the tokio/tokio-macros/src/entry.rs Lines 415 to 417 in e10ffa2
and annotating the type there via let body: ??? = async #body , so that typechecking fails there instead of inside the block_on .
However, I can't figure out what type to put there: rustc complains about my variations on
is what you get on
|
I figured it out: doing let body = async { let x: #output_type = body; x }; solves the problem — although it does complain about unreachable code when |
I think this is ready for review. Remaining issues:
I'm clearly doing something wrong around identifiers/quoting here, but I can't spot the issue.
since the type is already there in the test's source. (I suppose annotating a value as
|
I'm unable to run tests etc on the MSRV (1.56.0 currently) because I get:
|
Thanks for the PR.
See #5244, which fixed the same issue in the past.
If the return type contains an unstable type such as impl trait or never type, the type annotation needs to be omitted.
This is due to rust-lang/cargo#10623 (predicates uses weak and namespaced features). |
I just merged #5621, which conflicts with your PR. Sorry about that. |
Would you like to continue this PR? |
Superseded by #5762. |
Fix #5518.
Motivation
The
#[tokio::main]
macro in its current state produces output that degrades IDE functionality — code generated by the proc macro is annotated with spans that point back to the end of the (user-provided) contents ofasync fn main
, resulting in IDE plugins (correctly) treating the last binding inmain
as a call to a Tokio function.As an example, if one adds a typo to the generated code, the error produced on
master
points to user code:Solution
We replace the span attached to the Tokio-generated code with one that points to the invocation site of the
#[tokio::main]
macro itself: