Open
Description
It's possible that this is working as designed or that I'm taking the wrong approach here, so apologies up front if that's the case.
I seem to be able to use the combination of auto_traits
and negative_impls
to implement traits in a way that is generic but polymorphic for generic types on concrete types, but not for associated types on traits.
#![feature(auto_traits, negative_impls)]
use std::future::Future;
trait MyTrait {}
struct MyStruct {}
struct GenericStruct<T> {
value: T,
}
auto trait NotString {}
impl !NotString for String {}
// Generics on a concrete type work as expected
// I can specify T: NotString and there is no conflict
impl MyTrait for GenericStruct<String> {}
impl<T: NotString> MyTrait for GenericStruct<T> {}
// Associated Types don't work as I'd expect
impl<S> MyTrait for S where S: Future<Output = String> {}
// Even though T is NotString there's a conflict between Future<Output = String> and Future<Output = T>
impl<S, T: NotString> MyTrait for S where S: Future<Output = T> {}
I would've expected that the compiler could tell that Future<Output = String>
and Future<Output = T>
were mutually exclusive, given that T: NotString
.
Meta
rustc --version --verbose
:
rustc 1.50.0-nightly (7efc097c4 2020-12-12)
binary: rustc
commit-hash: 7efc097c4fe6e97f54a44cee91c56189e9ddb41c
commit-date: 2020-12-12
host: x86_64-apple-darwin
release: 1.50.0-nightly