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

&fn is non-copyable #3904

Closed
nikomatsakis opened this issue Nov 2, 2012 · 3 comments
Closed

&fn is non-copyable #3904

nikomatsakis opened this issue Nov 2, 2012 · 3 comments
Assignees
Labels
A-lifetimes Area: Lifetimes / regions A-typesystem Area: The type system
Milestone

Comments

@nikomatsakis
Copy link
Contributor

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,
    };
    val.boom();
}

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
Copy link
Contributor Author

Careful about &once fn etc.

@catamorphism
Copy link
Contributor

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

@nikomatsakis
Copy link
Contributor Author

This is fixed.

RalfJung pushed a commit to RalfJung/rust that referenced this issue Oct 5, 2024
Refactor ``return_read_bytes_and_count`` and ``return_written_byte_count_or_error``

Fixes rust-lang#3904

This PR
- separate the error logic from ``return_read_bytes_and_count`` and ``return_written_byte_count_or_error`` into a helper function ``set_last_error_and_return``.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions A-typesystem Area: The type system
Projects
None yet
Development

No branches or pull requests

2 participants