-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Enabling Rc<Trait> #981
Comments
|
While the example implementation feels alien, it made me realize that the language-level pivot pointers ( Actually, just remembered my reasoning: one of the concerns was Still, it's a start and should be backwards-compatible to switch some structures in |
Summarizing some discussion from IRC:
I believe that right now there is no way to have a type whose alignment is larger than 2*sizeof(usize) (at least on 64 bit). In the future we'll hopefully be able to specify larger alignment. Then the Shared type could be written like this: #[repr(C)]
struct Shared<T> {
_padding: [u8; align_of::<T>().saturating_sub(2 * size_of::<usize>())],
strong: Cell<usize>,
weak: Cell<usize>
value: T,
}
What I want is to express that there is a function that maps &Y to &X. So trait As<X: ?Sized> {
fn as(&self) -> &X;
}
impl<T: ?Sized> Rc<T> {
pub fn new<X: As<T>>(value: X) -> Rc<T> {
// ...
let _ref = mem::transmute::<&T, *const T>((&shared.value).as()); Still probably has to be built-in as long as one cannot automatically implement |
|
@bluss it doesn't use the efficient "pivot pointer" scheme, though. |
closing in favor of rust-lang/rust#54898. |
Given some additional intrinsics and extended subtyping support in function signatures, it's possible to write
Rc<Trait>
:Extended subtyping support means that we can always write
<X, Y: X>
which means thatY
is a subtype ofX
. Right now this syntax only works ifX
is a trait, but it should also work ifX == Y
. See the implementation below.cc @nikomatsakis
The text was updated successfully, but these errors were encountered: