rust-lang / rust-lang/rfcs

Implement `Default` for `fn` types and closures.

Open
#3,000 3 comments 12 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

I could avoid some unsafe code if the types of functions and closures-without-captures implemented the Default trait.

Theoretically you could extend this to closures that only capture things implementing Default, but starting with only closures that have no captures seems like a safer bet, and it can always be extended later.

Example:

fn call_by_type<F: Fn() + Copy + Default>() {
    let f = F::default();
    f();
}

fn wrapper<F: Fn() + Copy + Default>(_f: F) {
    call_by_type::<F>();
}

fn foo() {
    println!("Hello, world!");
}

fn main() {
    wrapper(foo);
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the issue's closure and function-pointer example, then review the Rust RFC process in this repository to determine the required proposal and design work. The scope currently covers captureless closures and function types, with captured closures left as a possible later extension; done means a settled design and an accepted or rejected RFC outcome.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.