Negative impls of Auto Traits (OIBIT) don't take into account Trait Bounds
The following code fails to compile:
trait Foo {}
auto trait FooAuto {}
impl<T> !FooAuto for T where T: Foo {}
fn test<T>(t: T) where T: FooAuto {}
fn main() {
test(1i32);
}
It produces the following error.
error[E0277]: the trait bound `i32: FooAuto` is not satisfied
--> src/main.rs:11:5
|
10 | test(1i32);
| ^^^^ the trait `FooAuto` is not implemented for `i32`
|
= note: required by `test`
(Playpen)
Even though I restrict the !FooAuto implementation to types implementing Foo (which there is none of), the rust compiler does not seem to take that restriction into account. Instead, it removes the FooAuto auto-implementation from every type.
If I remove the !FooAuto line, the code compiles just fine.
The same problems happens when I use impl<T: Foo> instead of where T: Foo (Playpen).
Also using impl FooAuto for .. {} instead of auto trait FooAuto results in the same problem (Playpen).
A TODO in #13231 would be related:
forbid conditional negative impls as described here
Masaki Hara at 2017-12-20 07:39:11
would be "fixed" by #79098, which would forbid such an impl
Niko Matsakis at 2022-02-17 14:21:18
Current error:
error[[E0658]](https://doc.rust-lang.org/nightly/error_codes/E0658.html): auto traits are experimental and possibly buggy --> src/main.rs:2:1 | 2 | auto trait FooAuto {} | ^^^^^^^^^^^^^^^^^^^^^ | = note: [see issue #13231 <https://github.com/rust-lang/rust/issues/13231>](https://github.com/rust-lang/rust/issues/13231) for more information = help: [add `#![feature(auto_traits)]`](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#) to the crate attributes to enable error[[E0658]](https://doc.rust-lang.org/nightly/error_codes/E0658.html): negative trait bounds are not yet fully implemented; use marker types for now --> src/main.rs:4:9 | 4 | impl<T> !FooAuto for T where T: Foo {} | ^^^^^^^^ | = note: [see issue #68318 <https://github.com/rust-lang/rust/issues/68318>](https://github.com/rust-lang/rust/issues/68318) for more information = help: [add `#![feature(negative_impls)]`](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#) to the crate attributes to enable error[[E0277]](https://doc.rust-lang.org/nightly/error_codes/E0277.html): the trait bound `i32: FooAuto` is not satisfied --> src/main.rs:8:10 | 8 | test(1i32); | ---- ^^^^ the trait `FooAuto` is not implemented for `i32` | | | required by a bound introduced by this call | note: required by a bound in `test` --> src/main.rs:5:27 | 5 | fn test<T>(t: T) where T: FooAuto {} | ^^^^^^^ required by this bound in `test` Some errors have detailed explanations: E0277, E0658. For more information about an error, try `rustc --explain E0277`.Dylan DPC at 2023-06-24 17:39:36