the async_trait macro adds a where clause to the end of the trait functions so it breaks object safety:
and the compiler result :
warning: the trait Foo cannot be made into an object
--> src/main.rs:13:14
|
13 | async fn bar(&self) {
| ^^^
|
= note: `#[warn(where_clauses_object_safety)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #51443 <https://github.com/rust-lang/rust/issues/51443>
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> src/main.rs:13:14
|
11 | trait Foo {
| --- this trait cannot be made into an object...
12 | async fn foo(&self);
13 | async fn bar(&self) {
| ^^^ ...because method `bar` references the `Self` type in its `where` clause
= help: consider moving `bar` to another trait
error[E0277]: `dyn Foo` cannot be shared between threads safely
--> src/main.rs:29:7
|
29 | e.bar().await;
| ^^^ `dyn Foo` cannot be shared between threads safely
|
= help: the trait `Sync` is not implemented for `dyn Foo`
For more information about this error, try `rustc --explain E0277`.
warning: `async-trait-expand-test` (bin "async-trait-expand-test") generated 1 warning
error: could not compile `async-trait-expand-test` due to previous error; 1 warning emitted
the macro does not working properly with default implementation of traits look at this :
expanded result : ( using cargo expand
the async_trait macro adds a where clause to the end of the trait functions so it breaks object safety: and the compiler result :
warning: the trait
Foo
cannot be made into an object