Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Non copyable values captured by fn~ closures can be copied #2828

Closed
msullivan opened this Issue · 4 comments

3 participants

@msullivan

The following program compiles and runs and will run the destructor twice:

class non_copyable {
    let n: int;
    new() { self.n = 0; }
    drop { log(error, "running destructor"); }
}

fn main() {
    let x = non_copyable();

    let f = fn~() { assert x.n == 0; };
    let g = copy f;

    f(); g();
}
@nikomatsakis
Owner

The problem is that send used to be a subset of copy. This was changed but it sounds like fn~ was changed inconsistently. If we moved over to the fn types with explicit bounds (fn:send vs fn:send copy) this would be solved.

@catamorphism catamorphism was assigned
@catamorphism

This appears to have fixed itself, hallelujah! In 8255aa1 I checked in the test case.

@nikomatsakis
Owner

I don't think it's really fixed. If you modify the test case to include a "move" capture clause, it still reproduces:

struct NoCopy {
    n: int
}
fn NoCopy() -> NoCopy {
    NoCopy { n: 0 }
}

impl NoCopy: Drop {
    fn finalize(&self) {
        log(error, "running destructor");
    }
}

fn main() {
    let x = NoCopy();

    let f = fn~(move x) { assert x.n == 0; }; 
    let g = copy f; // <-- Error expected here

    f(); g();
}

The proper fix is the work on closure bounds I did not get to for 0.5!

@nikomatsakis nikomatsakis reopened this
@catamorphism

Oops! Bumping to 0.6, then.

@nikomatsakis nikomatsakis referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@nikomatsakis nikomatsakis referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@nikomatsakis nikomatsakis referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@nikomatsakis nikomatsakis closed this issue from a commit
@nikomatsakis nikomatsakis 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.
a32498d
@jayanderson jayanderson referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@jayanderson jayanderson referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@jayanderson jayanderson referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@catamorphism catamorphism was unassigned by msullivan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.