Skip to content

Parsing issues with Box'ed unboxed closures #20640

Closed
@bitonic

Description

The following code works:

    pub fn new(delay: uint, callback: Box<FnMut() -> uint + 'a>, remove_on_drop: bool) -> Timer<'a> {
        ...
    }

But this doesn't:

    pub fn new(delay: uint, callback: Box<(FnMut() -> uint) + 'a>, remove_on_drop: bool) -> Timer<'a> {
        ...
    }

rustc complains that

src/sdl2/timer.rs:33:43: 33:60 error: expected a path on the left-hand side of `+`, not `(FnMut() -> uint)` [E0178]
src/sdl2/timer.rs:33     pub fn new(delay: uint, callback: Box<(FnMut() -> uint) + 'a>, remove_on_drop: bool) -> Timer<'a> {
                                                               ^~~~~~~~~~~~~~~~~
src/sdl2/timer.rs:33:43: 33:60 note: perhaps you forgot parentheses? (per RFC 438)
src/sdl2/timer.rs:33     pub fn new(delay: uint, callback: Box<(FnMut() -> uint) + 'a>, remove_on_drop: bool) -> Timer<'a> {
                                                               ^~~~~~~~~~~~~~~~~

If I understand correctly the syntax is trait + lifetime, so I'd expect those parentheses to be fine (and imho they make the code more clear). The note about forgetting parentheses is also puzzling.

Metadata

Assignees

No one assigned

    Labels

    A-parserArea: The parsing of Rust source code to an AST

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions