dtolnay / async-trait

Type erasure for async trait methods
Apache License 2.0
1.84k stars 85 forks source link

Traits cannot be made into trait objects #114

Closed valeth closed 4 years ago

valeth commented 4 years ago

I'm currently getting this warning in a little test project of mine.

warning: the trait `miniplug_runtime::plugin::Plugin` cannot be made into an object
 --> /run/system/data/data.valeth/Workspace/Scratch/miniplug/miniplug-runtime/src/plugin.rs:7:14
  |
7 |     async fn run(&self) {}
  |              ^^^ the trait cannot be made into an object because method `run` references the `Self` type in its `where` clause
  |
  = 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>

So any trait that implements an async function will no longer be able to be used as a trait object in some future release.

taiki-e commented 4 years ago

As described in the documentation, it may be able to fix this warning by adding a supertrait or by bounding that method with Self: Sized.

If the ways described in the documentation cannot fix this warning, please provide a minimal repro.

valeth commented 4 years ago

This did indeed fix the warning message, thank you.

Diggsey commented 4 years ago

@taiki-e It seems this only works if Send is a direct super-trait. If Send is a super-trait of a super-trait, the warning is still present, despite the bound being guaranteed... I'm guessing because it's not visible to the proc-macro in this case...