Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto_traits + negative_impls not working as expected with associated types #87732

Open
gbj opened this issue Aug 3, 2021 · 0 comments
Open
Labels
C-bug Category: This is a bug. F-auto_traits `#![feature(auto_traits)]` F-negative_impls #![feature(negative_impls)]

Comments

@gbj
Copy link

gbj commented Aug 3, 2021

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

@gbj gbj added the C-bug Category: This is a bug. label Aug 3, 2021
@jonas-schievink jonas-schievink added F-auto_traits `#![feature(auto_traits)]` F-negative_impls #![feature(negative_impls)] labels Aug 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-auto_traits `#![feature(auto_traits)]` F-negative_impls #![feature(negative_impls)]
Projects
None yet
Development

No branches or pull requests

2 participants