-
Notifications
You must be signed in to change notification settings - Fork 0
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
Remove unsafe
code from expansion
#7
Comments
@tyranron For now we can use the When foreign type is delegated we expands the following wrapper: #[automatically_derived]
#[derive(Clone, Copy, Debug, ::delegation::private::ref_cast::RefCast)]
#[doc(hidden)]
#[repr(transparent)]
pub struct __delegate_AsRefDef__Wrapper<T>(T)
where
T: ?::core::marker::Sized;
impl<T> From<T> for __delegate_AsRefDef__Wrapper<T> {
fn from(inner: T) -> Self {
Self(inner)
}
} but Solution 1 (not working)Also, we can't just use // `codegen` crate.
let definition = quote! {
pub struct #wrapper_ty<T>(T)
where
T: ?::core::marker::Sized;
};
let definition = ref_cast_impl::derive_ref_cast(definition.to_token_stream()); // ERROR: `ref_cast_impl::derive_ref_cast` not found. will not work. Solution 2 (
|
And we also can't rely on |
We can wait for TokenStream::expand_expr stabilization to get this work:
|
@50U10FCA7 I think we will wait for years until that will work. It's implemented only for literals for now:
And generalization for any AST doesn't seem to happen in near future. |
Background
Removing
unsafe
code from macro expansion.Problem to solve
Usage of
unsafe
transmute to convert from typeT
intoWrapper<T>
.Possible solutions
Replace
transmute
with:Into::into
- for methods withself
receiver;RefCast::ref_cast
- for methods with&self
receiver;RefCast::ref_cast_mut
- for methods with&mut self
receiver.The text was updated successfully, but these errors were encountered: