std::ptr::Unique

The compiler (version 1.68.2) issues an error which (after a little sanitization) contains

 help: the trait `Sync` is not implemented for             `dyn for<'a> Fn(&'a [A]) -> Option<B>`
   = note: required for                   `std::ptr::Unique<dyn for<'a> Fn(&'a [A]) -> Option<B>>` to implement `Sync`
   = note: required because it appears within the type `Box<dyn for<'a> Fn(&'a [A]) -> Option<B>>`

This is the first time that I consciously see std::ptr::Unique. A search suggests that it is something that was unstable and was removed (at least under that name) 4 years ago.

What do I need to know about std::ptr::Unique in order to write Rust using modern tooling in 2023?

It still exists as an implementation detail. You can ignore the middle line.

Basically, what it's saying is that Box<dyn for<'a> Fn(&'a [A]) -> Option<B>> is not Sync because dyn for<'a> Fn(&'a [A]) -> Option<B> is not Sync.

I also stumbled upon Unique at some point and it also confused me. Maybe it would be better to not expose it in error messages if it's a (perma-unstable?) implementation detail?

1 Like

As far as the compiler is concerned, it's no different from mentioning that Vec<my_crate::Foo> is !Sync because my_crate::Foo is !Sync. The std::ptr::Unique type is just another private item which is contributing to the error.

Well, the compiler does know std is special, so it could theoretically choose to not show specifically private std items in the type trace.

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.