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

Type inference failure around closure argument types #3609

Closed
nikomatsakis opened this issue Sep 27, 2012 · 2 comments
Closed

Type inference failure around closure argument types #3609

nikomatsakis opened this issue Sep 27, 2012 · 2 comments
Labels
A-typesystem Area: The type system
Milestone

Comments

@nikomatsakis
Copy link
Contributor

This gist from jesse99 suggests a type inference failure:

https://gist.github.com/3795931

you have to add an explicit annot on the argument type to get it to work. this should not be necessary since the local variable was annotated. not sure what's going on here!

@nikomatsakis
Copy link
Contributor Author

import comm::Chan;

type RingBuffer = ~[float];
type SamplesFn = fn~ (samples: &RingBuffer);

enum Msg
{
    GetSamples(~str, SamplesFn), // sample set name, callback which receives samples
}

fn foo(name: ~str, samples_chan: Chan<Msg>) {
    do task::spawn
    |copy name|
    {
        let callback: SamplesFn =
            |buffer|
            {
                for buffer.len().timesi |i| {error!("%?: %f", i, buffer[i])}
            };
        samples_chan.send(GetSamples(copy name, callback));
    };
}

fn main() {}

yields

/Users/nmatsakis/tmp/foo.rs:15:32: 19:13 error: mismatched types: expected `SamplesFn` but found `fn~(&RingBuffer)` (lifetime mismatch)
/Users/nmatsakis/tmp/foo.rs:15         let callback: SamplesFn =
/Users/nmatsakis/tmp/foo.rs:16             |buffer|
/Users/nmatsakis/tmp/foo.rs:17             {
/Users/nmatsakis/tmp/foo.rs:18                 for buffer.len().timesi |i| {error!("%?: %f", i, buffer[i])}
/Users/nmatsakis/tmp/foo.rs:19             };
note: the static lifetime...
note: ...does not necessarily outlive lifetime re_bound(br_anon(0))
error: aborting due to previous error

@catamorphism
Copy link
Contributor

This seems to have been fixed. I'll check in a test case.

catamorphism added a commit that referenced this issue Jan 3, 2013
RalfJung pushed a commit to RalfJung/rust that referenced this issue Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system
Projects
None yet
Development

No branches or pull requests

2 participants