Skip to content

Commit

Permalink
Partially work around ridiculous rust-analyzer behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Aug 17, 2023
1 parent 43ccc82 commit fcbb99c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub unsafe trait RefCastCustom<From: ?Sized> {
fn __static_assert() {}
}

#[doc(hidden)]
pub unsafe trait RefCastOkay<From>: Sealed<From> {
type CurrentCrate;
type Target: ?Sized;
Expand All @@ -28,6 +29,7 @@ where
type Target = To;
}

#[doc(hidden)]
pub trait Sealed<From> {}

impl<'a, From, To> Sealed<&'a From> for &'a To
Expand All @@ -44,8 +46,10 @@ where
{
}

#[doc(hidden)]
pub type CurrentCrate<From, To> = <To as RefCastOkay<From>>::CurrentCrate;

#[doc(hidden)]
pub fn ref_cast_custom<From, To>(_arg: From)
where
To: RefCastOkay<From>,
Expand Down
3 changes: 3 additions & 0 deletions src/layout.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use core::{mem, usize};

#[doc(hidden)]
pub struct Layout<T: ?Sized>(T);

#[doc(hidden)]
pub trait LayoutUnsized<T: ?Sized> {
const SIZE: usize = usize::MAX;
const ALIGN: usize = usize::MAX;
Expand All @@ -14,6 +16,7 @@ impl<T> Layout<T> {
pub const ALIGN: usize = mem::align_of::<T>();
}

#[doc(hidden)]
#[inline]
pub fn assert_layout<Outer: ?Sized, Inner: ?Sized>(
name: &'static str,
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,12 @@ pub trait RefCast {
// Not public API.
#[doc(hidden)]
pub mod __private {
#[doc(hidden)]
pub use crate::custom::{ref_cast_custom, CurrentCrate, RefCastCustom};
#[doc(hidden)]
pub use crate::layout::{assert_layout, Layout, LayoutUnsized};
#[doc(hidden)]
pub use crate::trivial::assert_trivial;
#[doc(hidden)]
pub use core::mem::transmute;
}
2 changes: 2 additions & 0 deletions src/trivial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use core::marker::PhantomData;
#[cfg(not(no_phantom_pinned))]
use core::marker::PhantomPinned;

#[doc(hidden)]
pub trait Trivial {}

impl Trivial for () {}
Expand All @@ -10,4 +11,5 @@ impl<T: ?Sized> Trivial for PhantomData<T> {}
#[cfg(not(no_phantom_pinned))]
impl Trivial for PhantomPinned {}

#[doc(hidden)]
pub fn assert_trivial<T: Trivial>() {}

0 comments on commit fcbb99c

Please sign in to comment.