Skip to content

closure type fails to be inferred properly for vec foldl method #4319

Closed
@thestinger

Description

@thestinger

This snippet works:

fn combine_flags(flags: &[MagicFlag]) -> c_int {
   vec::foldl(0, flags, |a: c_int, b: &MagicFlag| a | (*b as c_int))
}

Changing to the following doesn't compile because it gets inferred as an @ closure:

fn combine_flags(flags: &[MagicFlag]) -> c_int {
    flags.foldl(0, |a: c_int, b: &MagicFlag| a | (*b as c_int))
}

Error:

magic.rs:62:15: 62:61 error: mismatched types: expected `&fn(&core::libc::types::os::arch::c95::c_int, &MagicFlag) -> core::libc::types::os::arch::c95::c_int` but found `&fn(core::libc::types::os::arch::c95::c_int, &MagicFlag) -> core::libc::types::os::arch::c95::c_int` (expected &-ptr but found core::libc::types::os::arch::c95::c_int)
magic.rs:62   flags.foldl(0, |a: c_int, b: &MagicFlag| a | (*b as c_int))
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
zsh: exit 101   rustc magic.rs --test -O

The full code is in this repo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions