Skip to content

FnMut not implemented for mutable FnMut implementors #23015

Closed
@alexcrichton

Description

For example this program does not compile

fn foo<F: FnMut()>(_: F) {}

fn main() {
    let mut cb = || {};
    foo(&mut cb);
}
foo.rs:5:5: 5:8 error: the trait `core::ops::Fn<()>` is not implemented for the type `&mut [closure foo.rs:4:18: 4:23]` [E0277]
foo.rs:5     foo(&mut cb);
             ^~~
error: aborting due to previous error

The unfortunate error message is covered by another issue, but this seems like an unfortunate limitation. I tried to implement this but got coherence violations. I also implemented this "halfway" and got compile errors due to legitimate coherence violations which sprang up. I believe we have some hardwired impls of these traits in the compiler, but I'd like to make sure we have our story straight on these.

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)P-mediumMedium priority

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions