-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add better error message when using
async-trait
(#149)
* add better error message when using `async-trait` * change output file * move #121 compile tests into trybuild harness
- Loading branch information
1 parent
1381182
commit 2b43d0a
Showing
5 changed files
with
87 additions
and
4 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
34 changes: 34 additions & 0 deletions
34
autometrics/tests/result_labels/fail/async_trait_support.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,34 @@ | ||
use async_trait::async_trait; | ||
use autometrics::autometrics; | ||
|
||
// https://github.com/autometrics-dev/autometrics-rs/issues/141 | ||
|
||
#[async_trait] | ||
trait TestTrait { | ||
async fn method() -> bool; | ||
async fn self_method(&self) -> bool; | ||
} | ||
|
||
#[derive(Default)] | ||
struct TestStruct; | ||
|
||
#[autometrics] | ||
#[async_trait] | ||
impl TestTrait for TestStruct { | ||
async fn method() -> bool { | ||
true | ||
} | ||
|
||
async fn self_method(&self) -> bool { | ||
true | ||
} | ||
} | ||
|
||
fn main() { | ||
let ts = TestStruct::default(); | ||
|
||
async move { | ||
<TestStruct as TestTrait>::method().await; | ||
ts.self_method().await; | ||
}; | ||
} |
29 changes: 29 additions & 0 deletions
29
autometrics/tests/result_labels/fail/async_trait_support.stderr
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,29 @@ | ||
error: #[async_trait] must be defined BEFORE #[autometrics] | ||
--> tests/result_labels/fail/async_trait_support.rs:15:1 | ||
| | ||
15 | #[autometrics] | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: this error originates in the attribute macro `autometrics` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0277]: the trait bound `TestStruct: TestTrait` is not satisfied | ||
--> tests/result_labels/fail/async_trait_support.rs:31:9 | ||
| | ||
31 | <TestStruct as TestTrait>::method().await; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TestTrait` is not implemented for `TestStruct` | ||
|
||
error[E0599]: no method named `self_method` found for struct `TestStruct` in the current scope | ||
--> tests/result_labels/fail/async_trait_support.rs:32:12 | ||
| | ||
13 | struct TestStruct; | ||
| ----------------- method `self_method` not found for this struct | ||
... | ||
32 | ts.self_method().await; | ||
| ^^^^^^^^^^^ method not found in `TestStruct` | ||
| | ||
= help: items from traits can only be used if the trait is implemented and in scope | ||
note: `TestTrait` defines an item `self_method`, perhaps you need to implement it | ||
--> tests/result_labels/fail/async_trait_support.rs:7:1 | ||
| | ||
7 | trait TestTrait { | ||
| ^^^^^^^^^^^^^^^ |
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