#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
impl<T: ?Sized, A: Allocator> const Deref for Box<T, A> {
type Target = T;
fn deref(&self) -> &T {
&**self
}
}
Run Code Online (Sandbox Code Playgroud)
以我的理解:
self-> &Box,*self-> Box。**self-> *Box,将调用:*(Box.deref())? 这不会导致递归吗?我创建一个测试代码:
impl<T> Deref for MyBox<T> {
type Target = T;
fn deref(&self) -> &T {
&**self
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,Rust 返回给我:fatal runtime error: stack overflow
那么&**self …
rust ×1