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

Already on GitHub? Sign in to your account

&fn is non-copyable #3904

nikomatsakis opened this Issue Nov 2, 2012 · 3 comments


None yet
2 participants

nikomatsakis commented Nov 2, 2012

This test suggests that &fn is noncopyable. I do not believe this should be the case.

type ErrPrinter = &fn(&str, &str);

fn example_err(prog: &str, arg: &str) {
    io::println(fmt!("%s: %s", prog, arg))

fn exit(+print: ErrPrinter, prog: &str, arg: &str) {
    print(prog, arg);

struct X {
    mut err: ErrPrinter

impl X {
    fn boom() {
        exit(self.err, "prog", "arg");

fn main(){
    let val = &X{
        err: example_err,

The test yields:

Running /Users/nmatsakis/versioned/rust-gold/build/x86_64-apple-darwin/stage2/bin/rustc:
/Users/nmatsakis/tmp/foo.rs:17:13: 17:21 error: copying a noncopyable value
/Users/nmatsakis/tmp/foo.rs:17         exit(self.err, "prog", "arg");
/Users/nmatsakis/tmp/foo.rs:17:13: 17:21 note: function arguments must be copyable
/Users/nmatsakis/tmp/foo.rs:17         exit(self.err, "prog", "arg");

@ghost ghost assigned nikomatsakis Dec 4, 2012


nikomatsakis commented Dec 4, 2012

Careful about &once fn etc.


catamorphism commented Jan 10, 2013

Reproduced with 737e115 (though the error is now "moving out of mutable field", it reflects the same issue).

nikomatsakis added a commit to nikomatsakis/rust that referenced this issue Feb 7, 2013

Make ~fn non-copyable, make &fn copyable, split barefn/closure types,
correct handling of moves for struct-record update.

Part of #3678.  Fixes #2828, #3904, #4719.

bors added a commit that referenced this issue Feb 7, 2013


nikomatsakis commented Mar 20, 2013

This is fixed.

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