Skip to content
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

Switch to CoercePointee macro, with examples #1130

Draft
wants to merge 2 commits into
base: rust-next
Choose a base branch
from

Conversation

dingxiangfei2009
Copy link

This draft demonstrates the new capability from the current Rust Nightly, which now supports the #[derive(CoercePointee)] macro to derive the key trait implementations, in place of use of unstable language features such as Unsize and DispatchFromDyn.

An illustrative example is attached for more details in the Rust sample kernel module.

TODO(@wieDasDing): work on the patch epilogue a bit more

Comment on lines -444 to -460
// This is to allow coercion from `ListArc<T>` to `ListArc<U>` if `T` can be converted to the
// dynamically-sized type (DST) `U`.
impl<T, U, const ID: u64> core::ops::CoerceUnsized<ListArc<U, ID>> for ListArc<T, ID>
where
T: ListArcSafe<ID> + Unsize<U> + ?Sized,
U: ListArcSafe<ID> + ?Sized,
{
}

// This is to allow `ListArc<U>` to be dispatched on when `ListArc<T>` can be coerced into
// `ListArc<U>`.
impl<T, U, const ID: u64> core::ops::DispatchFromDyn<ListArc<U, ID>> for ListArc<T, ID>
where
T: ListArcSafe<ID> + Unsize<U> + ?Sized,
U: ListArcSafe<ID> + ?Sized,
{
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't delete these due to support for older rustc releases. Please see this doc for info on conditional compilation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, our current minimum version is 1.78.0, so you can use that to test.

Copy link
Author

@dingxiangfei2009 dingxiangfei2009 Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will revert those chunks and wrap it with a conditional

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants