Skip to content

type inferred for proc expression is not proc? #10718

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

Closed
pnkfelix opened this issue Nov 29, 2013 · 2 comments
Closed

type inferred for proc expression is not proc? #10718

pnkfelix opened this issue Nov 29, 2013 · 2 comments

Comments

@pnkfelix
Copy link
Member

Not sure if this is a bug or by design, but it certainly seemed odd so I wanted to note it.

Consider the following file, t.rs:

fn f1() {
    spawn(proc() println("Variant 1, adapted from tutorial-tasks.md"));
}

#[cfg(lifted_typed)]
fn f2() {
    let p : proc() = proc() println("Variant 2, lift out expression");
    spawn(p);
}

#[cfg(lifted_inferred)]
fn f2() {
    let p = proc() println("Variant 2, lift out expression");
    spawn(p);
}

fn main() { f1(); f2(); }

When I compile the explicitly typed variant (cfg(lifted_typed)), it compiles and runs; but compiling the type inferred variant fails:

% rustc --cfg lifted_typed /tmp/t.rs && /tmp/t
Variant 2, lift out expression
Variant 1, adapted from tutorial-tasks.md
% rustc --cfg lifted_inferred /tmp/t.rs && /tmp/t
/tmp/t.rs:14:10: 14:11 error: mismatched types: expected `proc:Send()` but found `~fn()` (expected bounds `Send` but found no bounds)
/tmp/t.rs:14     spawn(p);
                       ^
error: aborting due to previous error
@huonw
Copy link
Member

huonw commented Nov 29, 2013

In theory ~fn doesn't exist anymore:

fn main() {
    let _: ~fn();
}
twiddle-fn.rs:2:11: 2:12 error: obsolete syntax: managed or owned closure
twiddle-fn.rs:2     let _: ~fn();
                           ^
note: managed closures have been removed and owned closures are now written `proc()`

so (some part of) it is certainly a bug rather than by design. (I guess the bug could just be the error message... shrugs)

@klutzy
Copy link
Contributor

klutzy commented Nov 29, 2013

When rustc reads let f = proc() {};, f is inferred as ~fn() rather than proc() (== ~once fn()). I've seen the behavior when ~fn() was not obsolete yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants