pub unsafe fn map_unchecked<U, F>(self, func: F) -> Pin<&'a U>
where
F: FnOnce(&T) -> &U,
U: ?Sized,
FnOnce(&T) -> &U params is a reference so it can't move T anyway. Why is this function unsafe?
There is a same question here, but can't understand this example:

Almost all
unsafefunctions in the Rust standard library have documentation explaining why. From the documentation forPin::map_unchecked:This is essentially the same reason why
Pin::new_uncheckedis unsafe. Pinning a value means that it must never move again not just while protected by thePin. However, this function alone cannot ensure that guarantee and must be provided by the developer using it.The
pinmodule that is linked includes many requirements that must be followed for structural pinning i.e. if getting a field fromPin<&Self>requires the field to also be pinned which is a primary reason to usemap_unchecked. Requirements include: you cannot give&mutaccess to it elsewhere, it cannot be moved from even in theDropimplementation, it cannot be deallocated unless it is dropped, etc.