I have tried this code :
#![feature(specialization)]
#![feature(non_lifetime_binders)]
#![feature(auto_traits)]
#![feature(negative_impls)]
auto trait Default {}
pub trait Bar<T:?Sized>{}
pub trait Foo:for<T> Bar<T>{}
pub struct Impl;
// usize is a non default implementation, do some special work for Bar
impl ! Default for usize {}
impl Bar<usize> for Impl {}
// for default implementation ,do some general work for Bar
impl<T:?Sized> Bar<T> for Impl where T: Default {}
// we have done implemented for any Type T Bar<T> for for `Impl`, try to implement `Foo` for `Impl`. but error occurred.
impl Foo for Impl{}
fn main(){}
what i expect is:compile pass.
but it shows error:
error[E0277]: the trait bound `T: Default` is not satisfied
--> src/main.rs:72:14
|
72 | impl Foo for Impl{}
| ^^^^ the trait `Default` is not implemented for `T`
|
= help: the following other types implement trait `Bar<T>`:
<Impl as Bar<T>>
<Impl as Bar<usize>>
note: required for `Impl` to implement `Bar<T>`
--> src/main.rs:69:16
|
69 | impl<T:?Sized> Bar<T> for Impl where T: Default {}
| ^^^^^^ ^^^^ ------- unsatisfied trait bound introduced here
note: required by a bound in `Foo`
--> src/main.rs:59:15
|
59 | pub trait Foo:for<T> Bar<T>{}
| ^^^^^^^^^^^^^ required by this bound in `Foo`
It's seemed that rust compiler deduce whether the Impl
satisfy for<T> Bar<T>
by just searching for impl<T:?Sized> Bar<T> for Impl
instead of really judging for any type T
whether Bar<T>
is implemented for Impl
.
So, my question is :
- Is it expected or a bug ?
- If it is expected, any reason for not to compile ?