Skip to content

with_negative_coherence fails to prevent coherence_leak_check overlap error #117986

Closed
@Jules-Bertholet

Description

@Jules-Bertholet

I tried this code:

#![forbid(coherence_leak_check)]
#![feature(negative_impls, with_negative_coherence)]

pub trait Marker {}

impl<'a, T: ?Sized> !Marker for &'a T {}

trait FnMarker {}

impl<T: ?Sized + Marker> FnMarker for fn(T) {}
impl<T: ?Sized> FnMarker for fn(&T) {}

I expected to see this happen: Compiles successfully

Instead, this happened:

error: conflicting implementations of trait `FnMarker` for type `fn(&_)`
  --> src/lib.rs:11:1
   |
10 | impl<T: ?Sized + Marker> FnMarker for fn(T) {}
   | ------------------------------------------- first implementation here
11 | impl<T: ?Sized> FnMarker for fn(&T) {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `fn(&_)`
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #56105 <https://github.com/rust-lang/rust/issues/56105>
   = note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
note: the lint level is defined here
  --> src/lib.rs:1:11
   |
1  | #![forbid(coherence_leak_check)]
   |           ^^^^^^^^^^^^^^^^^^^^

Meta

rustc --version:

1.76.0-nightly (2023-11-15 6b771f6b5a6c8b03b632)

@rustbot label A-coherence F-negative_impls requires-nightly T-compiler

Metadata

Metadata

Labels

A-coherenceArea: CoherenceC-bugCategory: This is a bug.F-negative_impls#![feature(negative_impls)]T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions