Skip to content

negative_impls: negative impl fails to prevent overlap error #112588

Open
@lcnr

Description

@lcnr

The following example should pass coherence but currently errors.

#![feature(negative_impls, with_negative_coherence)]
trait Trait {}
impl<T: ?Sized> !Trait for &T {}
trait OtherTrait<T> {}

impl<T: Trait> OtherTrait<T> for T {}
impl<T, U> OtherTrait<&U> for &T {} // error, but shouldn't
error[[E0119]](https://doc.rust-lang.org/nightly/error_codes/E0119.html): conflicting implementations of trait `OtherTrait<&_>` for type `&_`
 --> src/lib.rs:7:1
  |
6 | impl<T: Trait> OtherTrait<T> for T {}
  | ---------------------------------- first implementation here
7 | impl<T, U> OtherTrait<&U> for &T {} // error, but shouldn't
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `&_`

previous test which was only missing the with_negative_coherence feature flag:

#![feature(negative_impls)]
trait Trait {}
impl<T: ?Sized> !Trait for &T {}
trait OtherTrait {}

impl<T: Trait> OtherTrait for T {}
impl<T> OtherTrait for &T {} // error, but shouldn't
// impl OtherTrait for &u32 // ok
error[[E0119]](https://doc.rust-lang.org/nightly/error_codes/E0119.html): conflicting implementations of trait `OtherTrait` for type `&_`
  --> src/lib.rs:10:1
   |
9  | impl<T: Trait> OtherTrait for T {}
   | ------------------------------- first implementation here
10 | impl<T> OtherTrait for &T {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `&_`

~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions