Closed
Description
When using a macro to generate an async fn with a proc macro inside it, if the generated function includes a type error, rustc will not report any line number information. This makes finding and debugging type errors in large async applications extremely difficult.
I tried this code:
async fn foo() {}
macro_rules! gen_test {
($before:expr) => {
#[tokio::test]
async fn test_foo() {
$before;
let x: () = foo();
}
}
}
gen_test!(dbg!(4));
I expected to see this happen:
Error including line number information (you will get this output if you just comment out the $before
line in the test fn)
error[E0308]: mismatched types
--> src/lib.rs:8:25
|
8 | let x: () = foo();
| ^^^^^
| |
| expected (), found opaque type
| help: consider using `.await` here: `foo().await`
...
13 | gen_test!(dbg!(4));
| ------------------- in this macro invocation
|
= note: expected type `()`
found type `impl std::future::Future`
Instead, this happened:
Error including no line number information
error[E0308]: mismatched types
|
= note: expected type `()`
found type `impl std::future::Future`
error: aborting due to previous error
Meta
rustc --version --verbose
: Tested on Playground with stable 1.40.0 and nightly 1.42.0 (2020-01-20)
Metadata
Metadata
Assignees
Labels
Area: Async & AwaitArea: Messages for errors, warnings, and lintsArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: Procedural macrosAsync-await issues that have been triaged during a working group meeting.Category: This is a bug.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.High priorityRelevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Status
Done