Skip to content

Derived type error when assigning function to an Option #9048

Closed
@huonw

Description

@huonw
fn main() {
    let mut rec_f = None;
    let f: &fn(uint) -> bool = |n| { n == 0 || (*rec_f.get_ref())(n - 1) };
    rec_f = Some(f);
}
derived-type.rs:3:47: 3:66 error: the type of this value must be known in this context
derived-type.rs:3     let f: &fn(uint) -> bool = |n| { n == 0 || (*rec_f.get_ref())(n - 1) };
                                                                 ^~~~~~~~~~~~~~~~~~~
derived-type.rs:4:12: 4:20 error: mismatched types: expected `std::option::Option<[type error]>` but found `std::option::Option<&fn<no-bounds>(uint) -> bool>` (expected type error but found fn)
derived-type.rs:4     rec_f = Some(f);
                              ^~~~~~~~
error: aborting due to 2 previous errors

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