Are you talking about this thread
#![feature(specialization)]
#![allow(incomplete_features)]
#![allow(unused_variables)]
trait Is<T> {
fn is(&self);
}
impl<A, B> Is<A> for B {
default fn is(&self) {
println!("no");
}
}
impl<T> Is<T> for T {
fn is(&self) {
println!("yes");
}
}
fn is_static_str<N: Is<&'static str>>(t: N) {
t.is();
}
fn fully_generic_wrapper_function_without_trait_bound<N>(t: N) {
is_static_str::<N>(t);
}
fn main() {
let static_str: &'static str = "hey";
let deallocated_at_end_of_main: String = "hello".to_string();
let not_static_str: &'_ str = deallocated_at_end_of_main.as_str();
is_static_str(static_str); // Ok, prints "yes"
is_static_str(0u32); // Ok, prints "no"
is_static_str(&0u32); // Ok, prints "no"
// is_static_str(not_static_str); // Error, borrowed value does not live long enough
fully_generic_wrapper_function_without_trait_bound(static_str); // yes
fully_generic_wrapper_function_without_trait_bound(0u32); // no
fully_generic_wrapper_function_without_trait_bound(&0u32); // no
fully_generic_wrapper_function_without_trait_bound(not_static_str); // yes (no Error!)
}
In this case,
fn is_static_str<N: Is<&'static str>>(t: N) {
t.is(); // fine, since t:N impl Is<...>
}
fn fully_generic_wrapper_function_without_trait_bound<N>(t: N) {
// how we could ensure N: Is<&'static str>?
is_static_str::<N>(t);
}
IMHO, It is because calling is_static_str::<N>
for a arbitary N
is unsound that cause such problem.
What's more, currently, we could not impl <T:Bar or Baz> Foo for T
(both [T; 0] and [T:Copy; N] could be Copy, but currently rustc just couldn't mark both of them as Copy)
error[E0119]: conflicting implementations of trait `Foo`
--> test.rs:7:1
|
6 | default impl <T:Bar> Foo for T{}
| ------------------------------ first implementation here
7 | default impl <T:Baz> Foo for T{}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
error: aborting due to previous error
For more information about this error, try `rustc --explain E0119`.
code
#![allow(incomplete_features)]
#![feature(specialization)]
trait Foo{}
trait Bar{}
trait Baz{}
default impl <T:Bar> Foo for T{}
default impl <T:Baz> Foo for T{}
impl<T:Bar+Baz> Foo for T{}
impl Bar for i32{}
impl Baz for i32{}
fn main(){}