Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Implement Clone on |A|: 'static -> R &'static fn()` #8025

Closed
bluss opened this issue Jul 24, 2013 · 9 comments
Closed

RFC: Implement Clone on |A|: 'static -> R &'static fn()` #8025

bluss opened this issue Jul 24, 2013 · 9 comments
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. P-low Low priority

Comments

@bluss
Copy link
Member

bluss commented Jul 24, 2013

Some closures are shallow-clonable and should implement .clone().

One example is a &'static fn(A) -> R autoborrowed from an extern fn. If it's clonable then that could make an iterator adaptor like MapIterator clonable in some cases.

@catamorphism
Copy link
Contributor

I think this is a change requiring an RFC.

Nominating so we can discuss it in triage.

@nikomatsakis
Copy link
Contributor

Seems like a fine thing to do. We'll need a couple of impls for differing numbers of arguments.

@brson
Copy link
Contributor

brson commented Nov 7, 2013

Good newbie bug.

@pnkfelix
Copy link
Member

pnkfelix commented Nov 7, 2013

assigned to P-low to reflect that its not a big deal for 1.0 though.

@pnkfelix
Copy link
Member

I just encountered a case where I think I want this.

The details, for those interested: I'm trying to set up a condition-like system, but where the exception responses are carried in objects rather than derived from the dynamic scope. I also want to be able to have child object initially set up its exception handler as a copy of the exception handler of the parent. I'm pretty sure the "obvious thing" is to use objects instead of closures here, since the objects could obviously implement clone, but it would be nice to inter-operate with functions, even if only ones that can be &'static borrowed.

@pnkfelix
Copy link
Member

Ah wait, we also support clone on other kinds of fn, as added by PR #8109.

(But also issue #10501 might be a problem.)

@nikomatsakis
Copy link
Contributor

So, there is some confusion between the spellings of various types -- what was &'static fn is now better written ||:'static (modulo issue #10553). By which I mean: a closure with a static bound is basically the same as a bare function. Anyway, I think the approach I laid out in #10501 subsumes this particular bug and is necessary for these kinds of clones to really work.

@erickt erickt changed the title RFC: Implement Clone on &'static fn() RFC: Implement Clone on |A|: 'static -> R &'static fn()` May 5, 2014
@erickt
Copy link
Contributor

erickt commented May 5, 2014

Edited the title to match the current syntax for closures. I believe this is an example test case if this were implemented.

fn foo() { println!("hi"); }

fn bar(x: ||: 'static) {
    (x)();
    let y = x.clone();
    (y)();
}

fn main() {
    bar(foo);
}

@nikomatsakis
Copy link
Contributor

I think we ought to just close this issue. It'd require an RFC and would interact with plans for "unboxed closures" (#8622).

flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 23, 2021
Rustup

Re-sync, because I didn't get to syncing things back to rustc.

r? `@ghost`

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. P-low Low priority
Projects
None yet
Development

No branches or pull requests

6 participants