Skip to content

functions implement Copy but not Clone #28229

Description

@fuchsnj

This compiles

fn func(){}

fn main(){
    run(func);
    run(func);
}

fn run<T>(f: T)
where T: Fn() + Copy{
    f();
}

but this does not (playground)

fn func(){}

fn main(){
    run(func);
    run(func);
}

fn run<T>(f: T)
where T: Fn() + Clone{
    f();
}

The only difference is the bounds on T. The Copy trait requires that the Clone trait is also implemented, so I believe both of these should compile.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemC-bugCategory: This is a bug.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-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