在这里,返回 *self,应该是错误的,假设 Self 是 &T,而 &self 就是 &Self,也就是&&T。此时返回self才对,也就是 返回 &T。而返回 *self 就是返回T了。
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl<T: ?Sized> const Deref for &T {
type Target = T;
#[rustc_diagnostic_item = "noop_method_deref"]
fn deref(&self) -> &T {
self
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> !DerefMut for &T {}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl<T: ?Sized> const Deref for &mut T {
type Target = T;
fn deref(&self) -> &T {
self
}
}
在《Deref 解引用》章节出现错误:
在这里,返回 *self,应该是错误的,假设 Self 是 &T,而 &self 就是 &Self,也就是&&T。此时返回self才对,也就是 返回 &T。而返回 *self 就是返回T了。
而在标准库中就是