Skip to content

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

Open
@oberien

Description

@oberien

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-specializationArea: Trait impl specializationC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions