< 返回版块

leslieDD 发表于 2021-05-19 10:48

fn func5<U: Debug, T: Deref<Target = U>>(t: T) {
    println!("t is {:?}", *t);
}

/*
associated type bounds are unstable
see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more informationrustcE0658
*/

fn func6<T: Deref<Target: Debug>>(t: T) {
}

第二个函数会报错:

associated type bounds are unstable
see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more informationrustcE0658

但是经常在教程里面可以看到类似这样的代码:

impl<P: Deref<Target: Unpin>> Pin<P> {
    pub fn new(pointer: P) -> Pin<P> {
        unsafe { Pin::new_unchecked(pointer) }
    }
}

Target: XXX,这咱写法是不是已经过时了

评论区

写评论
Grobycn 2021-05-19 11:27

不是过时,而是超前了。换 nightly 版本试一试

1 共 1 条评论, 1 页