Closed
Description
Code
#![allow(unused)]
#![feature(negative_impls)]
trait MyTrait {}
#[derive(Clone)]
struct MyString {
string: String,
}
impl<T: Copy> !MyTrait for T { }
// Works
impl MyTrait for MyString { }
// Throws error but it should work
impl MyTrait for String { }
fn main() {
}
rustc --version --verbose
:
rustc 1.85.0-nightly (5f23ef7d3 2024-12-20)
binary: rustc
commit-hash: 5f23ef7d3f7a8c3e0ca5c4e1978829c0448a3686
commit-date: 2024-12-20
host: aarch64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.6
Error output
error[E0751]: found both positive and negative implementation of trait `MyTrait` for type `String`:
--> src/main.rs:16:1
|
11 | impl<T: Copy> !MyTrait for T { }
| ---------------------------- negative implementation here
...
16 | impl MyTrait for String { }
| ^^^^^^^^^^^^^^^^^^^^^^^ positive implementation here