Skip to content

Trait coherency regression in 1.78 #124664

@w4

Description

@w4

Code

I tried this code:

trait Vendor { type Processor<'a>: VendorProcessor; } trait VendorProcessor { type EventGroup: Group; } trait Group {} trait EventProcessor<T> {} struct MyEventProcessor<T: Vendor> { t: T, } struct MyEvent {} impl Group for MyEvent {} impl<T: Vendor> EventProcessor<MyEvent> for MyEventProcessor<T> {} impl<T, Group> EventProcessor<Group> for MyEventProcessor<T> where T: Vendor, for<'a> T::Processor<'a>: VendorProcessor<EventGroup = Group>, {}

I expected a working build.

Instead, this happened:

error[E0119]: conflicting implementations of trait `EventProcessor<MyEvent>` for type `MyEventProcessor<_>` --> minimal-repro/src/lib.rs:23:1 | 21 | impl<T: Vendor> EventProcessor<MyEvent> for MyEventProcessor<T> {} | --------------------------------------------------------------- first implementation here 22 | 23 | / impl<T, Group> EventProcessor<Group> for MyEventProcessor<T> 24 | | where 25 | | T: Vendor, 26 | | for<'a> T::Processor<'a>: VendorProcessor<EventGroup = Group>, | |__________________________________________________________________^ conflicting implementation for `MyEventProcessor<_>` 

If this was a bugfix for trait coherency, it doesn't seem to have been documented in the changelog. The two implementations could technically be irrefutably non-conflicting though if there is no impl VendorProcessor<EventGroup = MyEvent> on private types.

Version it worked on

It most recently worked on: 1.77.2

Version with regression

rustc --version --verbose:

rustc 1.78.0 (9b00956e5 2024-04-29) binary: rustc commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6 commit-date: 2024-04-29 host: aarch64-apple-darwin release: 1.78.0 LLVM version: 18.1.2 

@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-coherenceArea: CoherenceC-bugCategory: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions