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

Instrumenting async_trait methods drops location of compilation errors #768

Closed
kleimkuhler opened this issue Jun 25, 2020 · 9 comments
Closed
Labels
closed/wontfix This will not be worked on crate/attributes Related to the `tracing-attributes` crate kind/bug Something isn't working

Comments

@kleimkuhler
Copy link
Contributor

Bug Report

Version

  • tracing v0.1.15
  • tracing-futures v0.2.4

Platform

Linux

Crates

  • async-trait v0.1.36

Description

Instrumenting an async_trait method drops the location of compilation errors.

use async_trait::async_trait;

#[derive(Debug)]
struct A {
    x: usize,
}

#[async_trait]
trait Set {
    async fn set(&mut self);
}

#[async_trait]
impl Set for A {
    #[tracing::instrument]
    async fn set(&mut self) {
        self.x = "error";
    }
}

fn main() {
    println!("Hello, world!");
}

I expected to see the following error from the above:

error[E0308]: mismatched types
  --> src/main.rs:17:18
   |
17 |         self.x = "error";
   |                  ^^^^^^^ expected `usize`, found `&str`

error: aborting due to previous error

Instead, this is the error:

error[E0308]: mismatched types
  --> src/main.rs:15:5
   |
15 |     #[tracing::instrument]
   |     ^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&str`

error: aborting due to previous error

Extra details

I originally came across this error in a less minimal reproduction, but the
error had even less location details as the above.

error[E0277]: the trait bound `(): core::future::future::Future` is not satisfied
  |
  = note: required by `core::future::future::Future::poll`
error: aborting due to previous error

Note that there is no file or code location mentioned!

It was unable to point at the actual #[tracing::instrument] attribute, and on
top of that the error ended up being in a subdirectory of the crate.

I haven't been able to reproduce that in this example.

@hawkw
Copy link
Member

hawkw commented Jun 25, 2020

This is pretty weird. I'm CCing @nightmared, who wrote the original instrument/async_trait integration --- it looks like a compiler diagnostic span (not to be confused with a tracing::Span!) is getting misplaced someplace in there.

@hawkw hawkw added crate/attributes Related to the `tracing-attributes` crate kind/bug Something isn't working labels Jun 25, 2020
@hawkw
Copy link
Member

hawkw commented Jun 25, 2020

At a glance, I think that maybe this quote!, here:

quote!(
#(#attrs) *
#sig {
#(#stmts) *
}
)
.into()

needs to be a quote_spanned! to propagate the span of the input function, but I'm not sure --- haven't tested it or anything.

@nightmared
Copy link
Contributor

I fear this may be the same underlying issue as #755.

nightmared@placebo:tracing-async-trait-bug-repro$ cargo build
    Updating crates.io index
  Downloaded async-trait v0.1.36
  Downloaded 1 crate (24.4 KB) in 0.67s
   Compiling tracing-core v0.1.10
   Compiling tracing-attributes v0.1.8
   Compiling async-trait v0.1.36
   Compiling tracing v0.1.15
   Compiling tracing-futures v0.2.4
   Compiling bug-repro v0.1.0 (/home/nightmared/dev/tmp/tracing-async-trait-bug-repro)
error[E0308]: mismatched types
  --> src/lib.rs:17:18
   |
17 |         self.x = "error";
   |                  ^^^^^^^ expected `usize`, found `&str`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: could not compile `bug-repro`.

To learn more, run the command again with --verbose.
nightmared@placebo:tracing-async-trait-bug-repro$ cargo +stable  build
   Compiling proc-macro2 v1.0.6
   Compiling unicode-xid v0.2.0
   Compiling syn v1.0.5
   Compiling lazy_static v1.4.0
   Compiling cfg-if v0.1.10
   Compiling tracing-core v0.1.10
   Compiling quote v1.0.2
   Compiling pin-project-internal v0.4.13
   Compiling tracing-attributes v0.1.8
   Compiling async-trait v0.1.36
   Compiling tracing v0.1.15
   Compiling pin-project v0.4.13
   Compiling tracing-futures v0.2.4
   Compiling bug-repro v0.1.0 (/home/nightmared/dev/tmp/tracing-async-trait-bug-repro)
error[E0308]: mismatched types
  --> src/lib.rs:15:5
   |
15 |     #[tracing::instrument]
   |     ^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&str`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: could not compile `bug-repro`.

To learn more, run the command again with --verbose.

TL;DR: works in nightly, but not on stable.

@hawkw
Copy link
Member

hawkw commented Jun 25, 2020

Hmm, that's interesting --- @kleimkuhler, do you have a minute to try with a nightly compiler?

@kleimkuhler
Copy link
Contributor Author

Yep it looks like this is not an error on nightly. The example I provided:

error[E0308]: mismatched types
  --> src/main.rs:17:18
   |
17 |         self.x = "error";
   |                  ^^^^^^^ expected `usize`, found `&str`

error: aborting due to previous error

In the original situation I came across this error, it also provides the file and line number.

@hawkw
Copy link
Member

hawkw commented Jun 25, 2020

In that case, this seems like a compiler bug --- we can check rust-lang/rust for issues related to spans in nested proc-macros?

@taiki-e
Copy link
Member

taiki-e commented Jun 25, 2020

This is due to rust-lang/rust#43081, and should be fixed by rust-lang/rust#72287, rust-lang/rust#72393, rust-lang/rust#72388, or rust-lang/rust#72306 (see rust-lang/rust#43081 (comment))

@hawkw
Copy link
Member

hawkw commented Jun 25, 2020

Thanks @taiki-e!

@hawkw hawkw added the closed/wontfix This will not be worked on label Jun 25, 2020
@hawkw
Copy link
Member

hawkw commented Jun 25, 2020

Closing this, since it's an upstream issue and the fix should make it to stable eventually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed/wontfix This will not be worked on crate/attributes Related to the `tracing-attributes` crate kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants