Skip to content

Discrepancy in closure modes #3643

Closed
Closed
@kyledj

Description

@kyledj

The following code compiles and works as expected:

let a = &"something".all(|c: char| -> bool { c == 'a' });

This code, however:

let char_is_a = fn&(c: char) -> bool { c == 'a' };
let b = &"something".all(char_is_a);

gives the following error:

str_tut.rs:28:26: 28:35 error: mismatched types: expected `fn&(++:char) -> bool` but found `fn&(char) -> bool` (expected argument mode ++, but found +)
str_tut.rs:28   let b = &"something".all(char_is_a);
                                        ^~~~~~~~~
error: aborting due to previous error

If I add the mode to the char_is_a definition, it works. It just seems odd to have this discrepancy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions