Skip to content

regression: conflicting trait impls because Box<dyn Fn*> now implements Fn*. #59750

Closed
@adrian17

Description

@adrian17

Most likely related to #59500 ?

Simplified reproduction:

pub type FuncWrapper = Box<dyn Fn() + 'static>;

pub trait IntoFuncWrapper {
    fn into_func(self) -> FuncWrapper;
}

impl<F> IntoFuncWrapper for F where F: Fn() + 'static {
    fn into_func(self) -> FuncWrapper { Box::new(self) }
}

impl IntoFuncWrapper for FuncWrapper {
    fn into_func(self) -> FuncWrapper { self }
}

fn main() { }

Before: compiles on stable, beta, previous nightly
On latest nightly:

error[E0119]: conflicting implementations of trait `IntoFuncWrapper` for type `std::boxed::Box<(dyn std::ops::Fn() + 'static)>`:
  --> src/main.rs:11:1
   |
7  | impl<F> IntoFuncWrapper for F where F: Fn() + 'static {
   | ----------------------------------------------------- first implementation here
...
11 | impl IntoFuncWrapper for FuncWrapper {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `std::boxed::Box<(dyn std::ops::Fn() + 'static)>`

error: aborting due to previous error

I do not know whether that was expected and should be fixed on my side, or is it an unintended breakage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamT-libs-apiRelevant to the library API 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