Negative trait implementations on stable Rust.
This crate emulates the unstable negative_impls
feature
by generating a trait implementation with a condition that will never be true.
Add this to your Cargo.toml
:
toml
[dependencies]
negative-impl = "0.1"
Compiler support: requires rustc 1.37+
```rust use negativeimpl::negativeimpl;
pub struct Type {}
impl !Send for Type {}
impl !Sync for Type {} ```
Currently this crate only supports auto traits.
The following code cannot compile due to impl<T: Send> Trait for T
and
impl Trait for Type
conflict.
```rust use negativeimpl::negativeimpl;
pub struct Type {}
impl !Send for Type {}
trait Trait {}
impl
text
error[E0119]: conflicting implementations of trait `Trait` for type `Type`:
--> src/lib.rs:60:1
|
14 | impl<T: Send> Trait for T {}
| ------------------------- first implementation here
15 | impl Trait for Type {}
| ^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Type`
The above code can be compiled using the unstable negative_impls
feature.
```rust
pub struct Type {}
impl !Send for Type {}
trait Trait {}
impl
The current behavior of this crate with conditional negative impls is the
same as the unstable negative_impls
feature, but
the unstable negative_impls
feature plans to forbid it.
It's a great plan, but when it's implemented, this crate is unlikely to provide the same behavior due to the macro's limitation.
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.