Skip to content

&mut impl Fn() does not implement Fn() #147931

@theemathas

Description

@theemathas

There are the following blanket implementations of the Fn traits on reference types (abbreviated to omit the argument type):

  • impl Fn for &F where F: Fn
  • impl FnMut for &F where F: Fn
  • impl FnOnce for &F where F: Fn
  • impl FnMut for &mut F where F: FnMut
  • impl FnOnce for &mut F where F: FnMut

The following blanket implementation is possible to implement, but is missing from the standard library:

  • impl Fn for &mut F where F: Fn

As far as I can tell, this blanket impl was overlooked in the initial implementation.

This leads to a weird situation where &mut F implements fewer of the Fn traits than &F. This is somewhat strange.

I'm not sure if this needs to be fixed though, since I can't come up with a realistic use case that would run into this.

I am unsure if this is a breaking change or not, as this is a new implementation of a fundamental trait on a fundamental type. I am unable to find code that compiles in stable rust that would break from this change though.

Meta

Affects stable rust version 1.90.0.

Metadata

Metadata

Assignees

Labels

A-closuresArea: Closures (`|…| { … }`)C-bugCategory: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions