Keep dyn-compatible final methods in the vtable#153696
Keep dyn-compatible final methods in the vtable#153696mu001999 wants to merge 1 commit intorust-lang:mainfrom
Conversation
|
rustbot has assigned @dingxiangfei2009. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
I don't think this is sound. If the |
|
RFC has the statement says:
And with allowing #![feature(final_associated_functions)]
trait Trait {
fn foo(&self);
final fn bar<T>(&self, x: T) -> T {
self.foo(); // Call dyn-compatible methods
x
}
}
struct Foo;
impl Trait for Foo {
fn foo(&self) {
println!("Foo");
}
}
struct Bar;
impl Trait for Bar {
fn foo(&self) {
println!("Bar");
}
}
fn foo(t: &dyn Trait) {
let _ = t.bar(0i32);
}
fn main() {
foo(&Foo);
foo(&Bar);
} |
|
Repeating a comment from IRLO: [The cited issue] is related to #57893; namely, always preferring the user defined method in cases of overlap breaks invocations of [...] If The cited issue shows that this applies to custom downcasting impls, not just |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
r? compiler |
|
@fee1-dead: I will pass this over to you, because it's stuff I know nothing about and you reviewed #151783. Thanks! r? fee1-dead |
|
|
This comment has been minimized.
This comment has been minimized.
|
Marking as blocked, if you want to push this you should probably ask for t-lang discussion. |
This comment was marked as outdated.
This comment was marked as outdated.
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
(Speaking for me with my lang hat on, but not for the team) I think we should do this. One of the things where this would be useful is https://doc.rust-lang.org/std/slice/fn.range.html, which is currently only module-scoped because putting it on a safe trait like But if you're using You can always define something inherent on |
|
I am very confused about this.
This seems like it might be something unique to the peculiarities of I think there are tradeoffs about whether a dyn-compatible I added that mention of |
|
@scottmcm wrote:
That seems a lot more complicated and less usable, and would require a duplicate implementation if you also have a definition in the trait. I don't see how that would be compatible with writing the method only once. |
|
I don't think we should do this, at least not in a semantically relevant way. #57893 and the (In cases where it's a pure performance optimization, like the |
Proposed in #156252 |
|
Based on the discussion above, I’ll close this PR for now, since
And personally, I also think this change would make the behavior of final methods harder to predict (#153649 (comment)). |
View all comments
Fixes #153649
Current implementation will exclude final methods from the trait's vtable, this PR will keep those dyn-compatible ones in the trait's vtable.