Skip to content
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

Bad diagnostics when using async fn's and attributes #102823

Closed
matheus-consoli opened this issue Oct 9, 2022 · 2 comments
Closed

Bad diagnostics when using async fn's and attributes #102823

matheus-consoli opened this issue Oct 9, 2022 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matheus-consoli
Copy link

rustexplorer (rustexplorer is a playground alternative, I'm using it because play.rust-lang.org doesn't exposes tracing attributes)

This is probably related to some other issues, like #71968, but I decided to open it either way because the diagnostics differ from the async and sync version.

Simplifying my real case, given some struct:

#[derive(Debug)]
struct Foo;

I've tried implementing some instrumented associated async fn and hit check before finishing the code:

impl Foo {
    #[tracing::instrument()]
    async fn missing_implementation(&self) -> char {}

    #[tracing::instrument()]
    async fn missing_wrapper(&self) -> Option<char> {
        'a'
    }
}

which gave me weird diagnostics, especially the last one:

  --> src/main.rs:10:5
   |
10 |     #[tracing::instrument()]
   |     ^^^^^^^^^^^^^^^^^^^^^^^^ expected `char`, found `()`

error[E0308]: mismatched types
  --> src/main.rs:13:5
   |
13 |     #[tracing::instrument()]
   |     ^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `Option`, found `char`
   |
   = note: expected enum `Option<char>`
              found type `char`
help: try wrapping the expression in `Some`
   |
13 |     Some(#[tracing::instrument()])
   |     +++++                        +

but, to my surprise, testing with the sync version:

impl Foo {
    #[tracing::instrument()]
    fn missing_implementation(&self) -> char {}

    #[tracing::instrument()]
    fn missing_wrapper(&self) -> Option<char> {
        'a'
    }
}

outputs:

error[E0308]: mismatched types
  --> src/main.rs:19:51
   |
19 |     fn missing_implementation(&self) -> char {}
   |                                              ^^ expected `char`, found `()`

error[E0308]: mismatched types
  --> src/main.rs:23:9
   |
22 |     fn missing_wrapper(&self) -> Option<char> {
   |                                  ------------ expected `Option<char>` because of return type
23 |         'a'
   |         ^^^ expected enum `Option`, found `char`
   |
   = note: expected enum `Option<char>`
              found type `char`
help: try wrapping the expression in `Some`
   |
23 |         Some('a')
   |         +++++   +

I expect the async version outputs the same diagnostics as the sync version.

@matheus-consoli matheus-consoli added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 9, 2022
@compiler-errors
Copy link
Member

@matheus-consoli this isn't really a rustc bug, but a bug in the proc macro expansion of tracing. I think I fixed it in tokio-rs/tracing#2270, can you try updating your tracing version and seeing if that fixes it? Thanks!

@matheus-consoli
Copy link
Author

oh, sorry for opening it in the wrong repo!

it's fixed, thank you for your work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants