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 $beforeline 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)
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:
I expected to see this happen:
Error including line number information (you will get this output if you just comment out the
$beforeline in the test fn)Instead, this happened:
Error including no line number information
Meta
rustc --version --verbose: Tested on Playground with stable 1.40.0 and nightly 1.42.0 (2020-01-20)