-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Assert negative trait bounds #8
Comments
This has been mentioned previously at #2 (comment). I agree that this would be a useful feature; I just haven't thought of a way it can be implemented. |
So, I wasn't aware that the negative trait bound syntax was only available on nightly (it appears in the docs for struct Success;
#[derive(Clone)]
struct Negative;
trait NotClone {}
impl<T> NotClone for T where T: Clone {}
impl NotClone for Success {} // No problem!
// impl NotClone for Failure {} // Causes a compiler error This (ab)uses a blanket impl to cause types which implement a trait to fail to compile. Unfortunately, it only works for types which are defined in the crate in which the assertion is called. This seems like the normal use case for |
Yeah, it seems that approach isn't viable as of yet. The compiler still has some bugs that it needs to iron out. Here are some other failed attempts. |
Ah, it seems I'm not the first person to wander down this path. Do you consider the restriction that either the type or the trait must be defined in the same crate to be a deal breaker? It seems like that condition would be satisfied for most uses of |
I'd like to see some issues—such as the compiler suggesting that |
Oof, yeah, I agree. The error messages are pretty tough as well. Thanks for your time! |
I've had a new idea for this: #17. Ambiguity in name resolution can also trigger a compilation error, thus we introduce two competing traits with the same method. One of the traits is always implemented while the other is only implemented when the trait bounds are met. When the type implements all the supplied trait the compiler can no longer resolve the method name to a single trait and compilation fails. When the trait bound is not met, the compilation succeeds. To ensure that no other trait may interfere with name resolution we include a single parameter that is of a local type, effectively sealing the method signature. |
This is resolved by #17, which was just merged. |
To my knowledge,
assert_impl!
cannot assert that a given typeT
satisfies, for example,T: !Send
.The text was updated successfully, but these errors were encountered: