-
Notifications
You must be signed in to change notification settings - Fork 14k
DispatchFromDyn: require additional checks #149068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
DispatchFromDyn: require additional checks #149068
Conversation
|
rustbot has assigned @WaffleLapkin. Use |
This comment has been minimized.
This comment has been minimized.
|
@theemathas What do you think? Can we break |
75de383 to
88de0f9
Compare
This comment has been minimized.
This comment has been minimized.
88de0f9 to
b7f84d2
Compare
|
This code causes an ICE with this PR: #![feature(dispatch_from_dyn, unsize, arbitrary_self_types)]
use std::{
marker::{PhantomData, Unsize},
ops::{DispatchFromDyn, Receiver},
};
struct Ptr<T: ?Sized>(PhantomData<T>, Box<T>);
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a Ptr<U>> for &'a Ptr<T> {}
impl<T: ?Sized> Receiver for Ptr<T> {
type Target = T;
}
trait Trait {
fn method(self: &Ptr<Self>) {}
}
struct Thing;
impl Trait for Thing {}
fn main() {
let x: Ptr<dyn Trait> = Ptr(PhantomData, Box::new(Thing));
x.method();
}The compiler is probably attempting to do an dyn dispatch through two pointers, which is not possible Error output |
|
The documentation for DispatchFromDyn also needs to be changed. |
I am not sure. We have an option to make it possible. The question is, would it be a bad idea? In any case, let me add a stop-gap to disallow this case. |
b7f84d2 to
8c95fd8
Compare
|
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. |
The new checks are we check the pair of constituent types for same shapes structurally, and demand capability for dispatch for ADTs as usual; and we demand source generic parameter to be unsized of another for sanity. Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
8c95fd8 to
fdf32a0
Compare
|
r? types |
The new checks are we check the pair of constituent types for same shapes structurally, and demand capability for dispatch for ADTs as usual; and we demand source generic parameter to be unsized of another for sanity.
Fix #148727
cc @theemathas