寻找具有全面实现的另一个特征的实现时,有没有办法抑制“ rustc_on_unimplemented”消息?

时间:2018-07-13 13:44:38

标签: types compiler-errors rust traits

我有以下代码:

#![feature(on_unimplemented)]

use std::marker::PhantomData;

struct S<T>(PhantomData<T>);

#[rustc_on_unimplemented(message = "T1 missing")]
trait T1 {}

trait T2 {}

#[rustc_on_unimplemented(message = "T2 missing")]
impl<T: T1> T2 for S<T> {}

fn main() {
    wants_t2(S::<u8>(PhantomData));
}

fn wants_t2<T: T2>(_: T) {}

playground

编译时,出现此错误:

error[E0277]: T1 missing
  --> src/main.rs:16:5
   |
16 |     wants_t2(S::<u8>(PhantomData));
   |     ^^^^^^^^ the trait `T1` is not implemented for `u8`
   |
   = note: required because of the requirements on the impl of `T2` for `S<u8>`
note: required by `wants_t2`
  --> src/main.rs:19:1
   |
19 | fn wants_t2<T: T2>(_: T) {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^

寻找rustc_on_unimplemented的实现时,是否有办法抑制T1的{​​{1}}?某种程度上像Try的方法过滤器?

0 个答案:

没有答案