Skip to content

Rustc doesn't report line numbers for type errors within proc macro async fn within macro_rules macro #68430

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 $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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-proc-macrosArea: Procedural macrosAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    • Status

      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions