Skip to content
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

Negative impls of Auto Traits (OIBIT) don't take into account Trait Bounds #46813

Open
oberien opened this issue Dec 18, 2017 · 3 comments
Open
Labels
A-specialization Area: Trait impl specialization C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@oberien
Copy link
Contributor

oberien commented Dec 18, 2017

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).

@shepmaster shepmaster changed the title Nagitve impl of Auto Traits (OIBIT) don't take into account Trait Bounds Negative impls of Auto Traits (OIBIT) don't take into account Trait Bounds Dec 18, 2017
@qnighy
Copy link
Contributor

qnighy commented Dec 20, 2017

A TODO in #13231 would be related:

forbid conditional negative impls as described here

@pietroalbini pietroalbini added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-specialization Area: Trait impl specialization labels Jan 30, 2018
@nikomatsakis
Copy link
Contributor

would be "fixed" by #79098, which would forbid such an impl

@Dylan-DPC
Copy link
Member

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`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-specialization Area: Trait impl specialization C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

5 participants