#no-alloc #macro

nightly macro no-std negative-impl

Negative trait implementations on stable Rust

8 releases

new 0.1.7 Feb 27, 2026
0.1.6 Aug 23, 2024
0.1.5 Apr 13, 2024
0.1.4 Jun 29, 2023
0.0.0 Nov 17, 2020

#2522 in Rust patterns

Download history 58/week @ 2025-11-06 313/week @ 2025-11-13 374/week @ 2025-11-20 274/week @ 2025-11-27 256/week @ 2025-12-04 325/week @ 2025-12-11 352/week @ 2025-12-18 190/week @ 2025-12-25 350/week @ 2026-01-01 265/week @ 2026-01-08 471/week @ 2026-01-15 427/week @ 2026-01-22 356/week @ 2026-01-29 466/week @ 2026-02-05 361/week @ 2026-02-12 168/week @ 2026-02-19

1,433 downloads per month
Used in 10 crates (5 directly)

Apache-2.0 OR MIT

20KB
129 lines

negative-impl

crates.io docs.rs license msrv github actions

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.

Usage

Add this to your Cargo.toml:

[dependencies]
negative-impl = "0.1"

Examples

use negative_impl::negative_impl;

struct Type {}

#[negative_impl]
impl !Send for Type {}
#[negative_impl]
impl !Sync for Type {}

Supported traits

Currently this crate only supports auto traits.

Limitations

Conflicting implementations

The following code cannot compile due to impl<T: Send> Trait for T and impl Trait for Type conflict.

use negative_impl::negative_impl;

struct Type {}

#[negative_impl]
impl !Send for Type {}

trait Trait {}

impl<T: Send> Trait for T {}
impl Trait for Type {}
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.

#![feature(negative_impls)]

struct Type {}

impl !Send for Type {}

trait Trait {}

impl<T: Send> Trait for T {}
impl Trait for Type {}

License

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.

Dependencies

~130–520KB
~12K SLoC