Specifically, I expected the following (playground) to be straightforward specialization, but it does not work with min_specialization. Why not?
#![feature(min_specialization)]
trait A {}
trait B: A {}
struct Sa;
impl A for Sa {}
struct Sb;
impl A for Sb {}
impl B for Sb {}
trait X {
fn method(&self);
}
impl<T: A> X for T {
default fn method(&self) {
println!("default");
}
}
// error: cannot specialize on trait `B`
// --> src/main.rs:29:13
// |
// 29 | impl<T: A + B> X for T {
// | ^
impl<T: A + B> X for T {
fn method(&self) {
println!("specialized");
}
}
fn main() {
Sa.method();
Sb.method();
}
Imagine that B is implemented only for the type Foo<'a, 'a>, then whether or not your impl<T: A + B> X for T impl applies to Foo<'a, 'b> depends on if 'a and 'b are the same lifetime or not. However by the time we codegen, all lifetimes are erased, so typeck and codegen would disagree if a specialized impl applies, which is unsound. This is kind of lifetime dependent specialization is exactly what min_specialization is meant to prevent and the reason why the full specialization is unsound and will never be stabilized.
The min_specialization feature prohibits a specialization that would make it possible to define a pair of types that differ only by lifetimes but have different specializations. Your example shows that it is possible to define such a pair of types for any specialization on a trait, so all specializations on a trait are prohibited. Unfortunately, this also prohibits some useful cases.
The specialization feature does not prohibit such specializations, but may misbehave when there are two types that differ only by lifetime but have different specializations.
If that is correct, is it also complete? Or are there other ways that the two features differ?
I don't know if you already read it, but this blog post explains the concept of "always applicable" impls, which is the core idea behind min_specialization. in it, he addresses the soundness problem of specialization and how min_specialization avoids it.