Skip to content

Commit 02c2c43

Browse files
committed
Allow casting between nullptr's of different types
1 parent fd8021d commit 02c2c43

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

libcc2rs/src/rc.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ pub struct AnyPtr {
10551055
pub(crate) ptr: Rc<dyn ErasedPtr>,
10561056
}
10571057

1058-
impl<T: Clone + ByteRepr + 'static> Ptr<T> {
1058+
impl<T: ByteRepr + 'static> Ptr<T> {
10591059
pub fn to_any(&self) -> AnyPtr {
10601060
AnyPtr {
10611061
ptr: Rc::new(self.clone()),
@@ -1071,6 +1071,11 @@ impl Default for AnyPtr {
10711071

10721072
impl AnyPtr {
10731073
pub fn cast<T: 'static>(&self) -> Option<Ptr<T>> {
1074+
if let Some(p) = self.ptr.as_any().downcast_ref::<Ptr<()>>() {
1075+
if p.is_null() {
1076+
return Some(Ptr::<T>::null());
1077+
}
1078+
}
10741079
self.ptr.as_any().downcast_ref::<Ptr<T>>().cloned()
10751080
}
10761081

0 commit comments

Comments
 (0)