-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
derive(SmartPointer): rewrite bounds in where and generic bounds
- Loading branch information
1 parent
a5ee5cb
commit 48421e9
Showing
4 changed files
with
308 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//@ check-pass | ||
//@ compile-flags: -Zunpretty=expanded | ||
#![feature(derive_smart_pointer)] | ||
use std::marker::SmartPointer; | ||
|
||
pub trait MyTrait<T: ?Sized> {} | ||
|
||
#[derive(SmartPointer)] | ||
#[repr(transparent)] | ||
struct MyPointer<'a, #[pointee] T: ?Sized> { | ||
ptr: &'a T, | ||
} | ||
|
||
#[derive(core::marker::SmartPointer)] | ||
#[repr(transparent)] | ||
pub struct MyPointer2<'a, Y, Z: MyTrait<T>, #[pointee] T: ?Sized + MyTrait<T>, X: MyTrait<T>> | ||
where | ||
Y: MyTrait<T>, | ||
{ | ||
data: &'a mut T, | ||
x: core::marker::PhantomData<X>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#![feature(prelude_import)] | ||
#![no_std] | ||
//@ check-pass | ||
//@ compile-flags: -Zunpretty=expanded | ||
#![feature(derive_smart_pointer)] | ||
#[prelude_import] | ||
use ::std::prelude::rust_2015::*; | ||
#[macro_use] | ||
extern crate std; | ||
use std::marker::SmartPointer; | ||
|
||
pub trait MyTrait<T: ?Sized> {} | ||
|
||
#[repr(transparent)] | ||
struct MyPointer<'a, #[pointee] T: ?Sized> { | ||
ptr: &'a T, | ||
} | ||
#[automatically_derived] | ||
impl<'a, T: ?Sized + ::core::marker::Unsize<__S>, __S: ?Sized> | ||
::core::ops::DispatchFromDyn<MyPointer<'a, __S>> for MyPointer<'a, T> { | ||
} | ||
#[automatically_derived] | ||
impl<'a, T: ?Sized + ::core::marker::Unsize<__S>, __S: ?Sized> | ||
::core::ops::CoerceUnsized<MyPointer<'a, __S>> for MyPointer<'a, T> { | ||
} | ||
|
||
#[repr(transparent)] | ||
pub struct MyPointer2<'a, Y, Z: MyTrait<T>, #[pointee] T: ?Sized + MyTrait<T>, | ||
X: MyTrait<T>> where Y: MyTrait<T> { | ||
data: &'a mut T, | ||
x: core::marker::PhantomData<X>, | ||
} | ||
#[automatically_derived] | ||
impl<'a, Y, Z: MyTrait<T> + MyTrait<__S>, T: ?Sized + MyTrait<T> + | ||
::core::marker::Unsize<__S>, __S: ?Sized + MyTrait<__S>, X: MyTrait<T> + | ||
MyTrait<__S>> ::core::ops::DispatchFromDyn<MyPointer2<'a, Y, Z, __S, X>> | ||
for MyPointer2<'a, Y, Z, T, X> where Y: MyTrait<T>, Y: MyTrait<__S> { | ||
} | ||
#[automatically_derived] | ||
impl<'a, Y, Z: MyTrait<T> + MyTrait<__S>, T: ?Sized + MyTrait<T> + | ||
::core::marker::Unsize<__S>, __S: ?Sized + MyTrait<__S>, X: MyTrait<T> + | ||
MyTrait<__S>> ::core::ops::CoerceUnsized<MyPointer2<'a, Y, Z, __S, X>> for | ||
MyPointer2<'a, Y, Z, T, X> where Y: MyTrait<T>, Y: MyTrait<__S> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//@ check-pass | ||
|
||
#![feature(derive_smart_pointer)] | ||
|
||
#[derive(core::marker::SmartPointer)] | ||
#[repr(transparent)] | ||
pub struct Ptr<'a, #[pointee] T: OnDrop + ?Sized, X> { | ||
data: &'a mut T, | ||
x: core::marker::PhantomData<X>, | ||
} | ||
|
||
pub trait OnDrop { | ||
fn on_drop(&mut self); | ||
} | ||
|
||
#[derive(core::marker::SmartPointer)] | ||
#[repr(transparent)] | ||
pub struct Ptr2<'a, #[pointee] T: ?Sized, X> | ||
where | ||
T: OnDrop, | ||
{ | ||
data: &'a mut T, | ||
x: core::marker::PhantomData<X>, | ||
} | ||
|
||
pub trait MyTrait<T: ?Sized> {} | ||
|
||
#[derive(core::marker::SmartPointer)] | ||
#[repr(transparent)] | ||
pub struct Ptr3<'a, #[pointee] T: ?Sized, X> | ||
where | ||
T: MyTrait<T>, | ||
{ | ||
data: &'a mut T, | ||
x: core::marker::PhantomData<X>, | ||
} | ||
|
||
#[derive(core::marker::SmartPointer)] | ||
#[repr(transparent)] | ||
pub struct Ptr4<'a, #[pointee] T: MyTrait<T> + ?Sized, X> { | ||
data: &'a mut T, | ||
x: core::marker::PhantomData<X>, | ||
} | ||
|
||
#[derive(core::marker::SmartPointer)] | ||
#[repr(transparent)] | ||
pub struct Ptr5<'a, #[pointee] T: ?Sized, X> | ||
where | ||
Ptr5Companion<T>: MyTrait<T>, | ||
Ptr5Companion2: MyTrait<T>, | ||
{ | ||
data: &'a mut T, | ||
x: core::marker::PhantomData<X>, | ||
} | ||
|
||
pub struct Ptr5Companion<T: ?Sized>(core::marker::PhantomData<T>); | ||
pub struct Ptr5Companion2; | ||
|
||
#[derive(core::marker::SmartPointer)] | ||
#[repr(transparent)] | ||
pub struct Ptr6<'a, #[pointee] T: ?Sized, X: MyTrait<T>> { | ||
data: &'a mut T, | ||
x: core::marker::PhantomData<X>, | ||
} | ||
|
||
// a reduced example from https://lore.kernel.org/all/20240402-linked-list-v1-1-b1c59ba7ae3b@google.com/ | ||
#[repr(transparent)] | ||
#[derive(core::marker::SmartPointer)] | ||
pub struct ListArc<#[pointee] T, const ID: u64 = 0> | ||
where | ||
T: ListArcSafe<ID> + ?Sized, | ||
{ | ||
arc: *const T, | ||
} | ||
|
||
pub trait ListArcSafe<const ID: u64> {} | ||
|
||
fn main() {} |