Skip to content

Commit

Permalink
Add trybuild test for instrumented async fn type mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Aug 8, 2022
1 parent 8af39a7 commit cd2f3a1
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions tracing-attributes/Cargo.toml
Expand Up @@ -45,6 +45,7 @@ tokio-test = "0.4.2"
tracing-core = { path = "../tracing-core", version = "0.2"}
tracing-subscriber = { path = "../tracing-subscriber", version = "0.3", features = ["env-filter"] }
async-trait = "0.1.56"
trybuild = "1.0.64"

[badges]
maintenance = { status = "experimental" }
5 changes: 5 additions & 0 deletions tracing-attributes/tests/ui.rs
@@ -0,0 +1,5 @@
#[test]
fn ui() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/*.rs");
}
32 changes: 32 additions & 0 deletions tracing-attributes/tests/ui/async_instrument.rs
@@ -0,0 +1,32 @@
#![allow(unreachable_code)]

#[tracing::instrument]
async fn unit() {
""
}

#[tracing::instrument]
async fn simple_mismatch() -> String {
""
}

// FIXME: this span is still pretty poor
#[tracing::instrument]
async fn opaque_unsatisfied() -> impl std::fmt::Display {
("",)
}

struct Wrapper<T>(T);

// FIXME: this span is still pretty poor
#[tracing::instrument]
async fn mismatch_with_opaque() -> Wrapper<impl std::fmt::Display> {
""
}

fn main() {
let _ = unit();
let _ = simple_mismatch();
let _ = opaque_unsatisfied();
let _ = mismatch_with_opaque();
}
56 changes: 56 additions & 0 deletions tracing-attributes/tests/ui/async_instrument.stderr
@@ -0,0 +1,56 @@
error[E0308]: mismatched types
--> tests/ui/async_instrument.rs:5:5
|
5 | ""
| ^^ expected `()`, found `&str`

error[E0308]: mismatched types
--> tests/ui/async_instrument.rs:10:5
|
10 | ""
| ^^- help: try using a conversion method: `.to_string()`
| |
| expected struct `String`, found `&str`
|
note: return type inferred to be `String` here
--> tests/ui/async_instrument.rs:9:31
|
9 | async fn simple_mismatch() -> String {
| ^^^^^^

error[E0277]: `(&str,)` doesn't implement `std::fmt::Display`
--> tests/ui/async_instrument.rs:14:1
|
14 | #[tracing::instrument]
| ^^^^^^^^^^^^^^^^^^^^^^ `(&str,)` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `(&str,)`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= note: this error originates in the attribute macro `tracing::instrument` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: `(&str,)` doesn't implement `std::fmt::Display`
--> tests/ui/async_instrument.rs:15:34
|
15 | async fn opaque_unsatisfied() -> impl std::fmt::Display {
| ^^^^^^^^^^^^^^^^^^^^^^ `(&str,)` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `(&str,)`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead

error[E0308]: mismatched types
--> tests/ui/async_instrument.rs:24:5
|
24 | ""
| ^^ expected struct `Wrapper`, found `&str`
|
= note: expected struct `Wrapper<_>`
found reference `&'static str`
note: return type inferred to be `Wrapper<_>` here
--> tests/ui/async_instrument.rs:23:36
|
23 | async fn mismatch_with_opaque() -> Wrapper<impl std::fmt::Display> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: try wrapping the expression in `Wrapper`
|
24 | Wrapper("")
| ++++++++ +

0 comments on commit cd2f3a1

Please sign in to comment.