-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
[-]Cannot return impl Trait<Self> despite adding constraint "where Self : Sized"[/-][+]Self as generic trait parameter is not properly ignored by Self: Sized bound[/+]konnorandrews commentedon Feb 15, 2025
@rustbot modify labels: -I-ICE
konnorandrews commentedon Feb 15, 2025
Here is a smaller example without RPITIT.
Rollup merge of rust-lang#137097 - compiler-errors:sized-bound-self, …
Unrolled build for rust-lang#137097