`& crateType` is considered the local crate type but `* const/mut crateType` is not

use std::{future::Future, task::Poll};

struct A;

impl Future for &A{  // #1
    type Output= ();

    fn poll(self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> std::task::Poll<Self::Output> {
        Poll::Ready(())
    }
}

impl Future for * const A{  // #2
    type Output= ();

    fn poll(self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> std::task::Poll<Self::Output> {
        Poll::Ready(())
    }
}

#1 is permitted while #2 causes an error that

only traits defined in the current crate can be implemented for arbitrary types

*const A is not defined in the current crate because raw pointers are always foreign

It seems that the reference to a locally defined type is considered to be a type specified in the current crate but the pointer to a locally defined type is not. What's the concrete rule for determining whether the type is considered as a type defined in the current crate?

1 Like

You're looking for fundamental types: &Local, &mut Local, and Box<Local>.

n.b. dyn LocalTrait is also a local type.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.