Closed
Description
This Compiles
struct Foo;
trait Bar{
fn some_method(&self) -> impl SomeTrait where Self: Sized;
}
trait SomeTrait{}
fn main() {
let obj : &dyn Bar;
}
This Also Compiles
struct Foo;
trait Bar{
fn some_method(&self) -> &dyn SomeTrait<Self> where Self: Sized;
}
trait SomeTrait<T>{}
fn main() {
let obj : &dyn Bar;
}
But This..
struct Foo;
trait Bar{
fn some_method(&self) -> impl SomeTrait<Self> where Self: Sized;
}
trait SomeTrait<T>{}
fn main() {
let obj : &dyn Bar;
}
Show This Error output
error[E0038]: the trait `Bar` is not dyn compatible
--> src\main.rs:7:15
|
7 | let obj : &dyn Bar;
| ^^^^^^^^ `Bar` is not dyn compatible
|
note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
--> src\main.rs:3:35
|
2 | trait Bar{
| --- this trait is not dyn compatible...
3 | fn some_method(&self) -> impl SomeTrait<Self> where Self: Sized;
| ^^^^^^^^^^^^^^^ ...because it uses `Self` as a type parameter
Even though Self : Sized. This should be valid in rust.
version:
rustc 1.86.0-nightly (a567209 2025-02-13)