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

Struct + Fn fulfills Send, but sugary version |&: ...| does not #16560

Closed
japaric opened this issue Aug 17, 2014 · 1 comment · Fixed by #18324
Closed

Struct + Fn fulfills Send, but sugary version |&: ...| does not #16560

japaric opened this issue Aug 17, 2014 · 1 comment · Fixed by #18324
Labels
A-closures Area: Closures (`|…| { … }`) E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@japaric
Copy link
Member

japaric commented Aug 17, 2014

STR

#![feature(unboxed_closures)]

use std::mem;
use std::ops::Fn;

// Unsugared closure
struct Closure(u8);

impl Fn<(u8,), u8> for Closure {
    extern "rust-call" fn call(&self, (y,): (u8,)) -> u8 {
        let &Closure(x) = self;

        x + y
    }
}

fn main() {
    let y = 0u8;
    let closure = |&: x| y + x;
    let unsugared_closure = Closure(y);

    // Check that both closures are capturing by value
    println!("{}", mem::size_of_val(&closure));  // prints 1
    println!("{}", mem::size_of_val(&unsugared_closure));  // prints 1

    spawn(proc() {
        let ok = unsugared_closure;
        let err = closure;
    })
}

Output

closure.rs:28:19: 28:26 error: cannot capture variable of type `closure`, which does not fulfill `'static+Send`, in a bounded closure [E0146]
closure.rs:28         let err = closure;
                                ^~~~~~~
closure.rs:28:19: 28:26 note: this closure's environment must satisfy `'static+Send`
closure.rs:28         let err = closure;
                                ^~~~~~~
error: aborting due to previous error

Version

rustc 0.12.0-pre (eff87bc9d 2014-08-17 13:11:06 +0000)
@bkoropoff
Copy link
Contributor

The example code with appropriate changes now builds:

#![feature(unboxed_closures)]

use std::mem;

fn main() {
    let y = 0u8;
    let closure = move |&: x| y + x;

    // Check that both closures are capturing by value
    println!("{}", mem::size_of_val(&closure));  // prints 1

    spawn(proc() {
        let ok = closure;
    })
}

This issue just needs a test now.

@sfackler sfackler added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 17, 2014
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 18, 2024
internal: Set channel override when querying the sysroot metadata

This is pretty hard to discover, and makes the setting useless, we should probably enable it for now.

CC rust-lang#16486
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: Closures (`|…| { … }`) E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
4 participants