Skip to content

Calling a closure stored in a struct, a bug or just a bad error message #18343

Closed
@dutt

Description

@dutt

I tried to do this:

struct S {
    x : uint,
    func : fn(uint)
}

impl S {
    fn no_func(val : uint) { println!("{}", val); }
    fn new() -> S {
        S { x : 0, func : S::no_func }
    }
}

fn main() {
    let s : S = S::new();
    s.func(7);
}

And I got the error:
error: typeSdoes not implement any method in scope named "func"

It seems to try to look for a member function and ignore the member variable. One person(alexchandel) in the rust irc channel said this was a bug and should work, another(p1start) said the error message should be improved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions