-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add trybuild test for instrumented async fn type mismatch
- Loading branch information
1 parent
8af39a7
commit b4dcdcb
Showing
4 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#[test] | ||
fn ui() { | ||
let t = trybuild::TestCases::new(); | ||
t.compile_fail("tests/ui/*.rs"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#![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); | ||
|
||
#[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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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("") | ||
| ++++++++ + |