Skip to content

Commit d7cf3ef

Browse files
committed
Allow casting between nullptr's of different types
1 parent 5d84938 commit d7cf3ef

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
@@ -1077,7 +1077,7 @@ pub struct AnyPtr {
10771077
ptr: Rc<dyn ErasedPtr>,
10781078
}
10791079

1080-
impl<T: Clone + ByteRepr + 'static> Ptr<T> {
1080+
impl<T: ByteRepr + 'static> Ptr<T> {
10811081
pub fn to_any(&self) -> AnyPtr {
10821082
AnyPtr {
10831083
ptr: Rc::new(self.clone()),
@@ -1093,6 +1093,11 @@ impl Default for AnyPtr {
10931093

10941094
impl AnyPtr {
10951095
pub fn cast<T: 'static>(&self) -> Option<Ptr<T>> {
1096+
if let Some(p) = self.ptr.as_any().downcast_ref::<Ptr<()>>() {
1097+
if p.is_null() {
1098+
return Some(Ptr::<T>::null());
1099+
}
1100+
}
10961101
self.ptr.as_any().downcast_ref::<Ptr<T>>().cloned()
10971102
}
10981103

0 commit comments

Comments
 (0)