Skip to content

Implementation of Trait for different type of Fn doesn't work #60074

@richerarc

Description

@richerarc

Implementing a Trait for a type T (where T is a function with a given a signature) and then trying to implement the same trait for another type T (where T is a function with a different signature) doesn't compile.

I tried this code:

trait MyTrait {}

impl<F> MyTrait for F where F: Fn(u32) -> u32 {}

impl<F> MyTrait for F where F: Fn(u32, u32) -> u32 {}

When compiling this code I get :

error[E0119]: conflicting implementations of trait `MyTrait`:
 --> src/main.rs:5:1
  |
3 | impl<F> MyTrait for F where F: Fn(u32) -> u32 {}
  | ------------------------------------------------------ first implementation here
4 | 
5 | impl<F> MyTrait for F where F: Fn(u32, u32) -> u32 {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation

What I would expect is that T here represent in the first implementation either a fn(u32) -> u32 or a closure the implement Fn(u32) -> u32, then in the second implementation, T would be either a fn(u32, u32) -> u32 or a closure the implement Fn(u32, u32) -> u32.

Meta

rustc 1.34.0 (91856ed 2019-04-10)
binary: rustc
commit-hash: 91856ed
commit-date: 2019-04-10
host: x86_64-apple-darwin
release: 1.34.0
LLVM version: 8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)A-trait-systemArea: Trait systemT-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions