- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Closed
Copy link
Labels
A-dyn-compatibilityArea: Dyn compatibility (formerly: object safety)Area: Dyn compatibility (formerly: object safety)A-dyn-traitArea: trait objects, vtable layoutArea: trait objects, vtable layoutC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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)
fmease
Metadata
Metadata
Assignees
Labels
A-dyn-compatibilityArea: Dyn compatibility (formerly: object safety)Area: Dyn compatibility (formerly: object safety)A-dyn-traitArea: trait objects, vtable layoutArea: trait objects, vtable layoutC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.