Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing issues with Box'ed unboxed closures #20640

Closed
bitonic opened this issue Jan 6, 2015 · 3 comments
Closed

Parsing issues with Box'ed unboxed closures #20640

bitonic opened this issue Jan 6, 2015 · 3 comments
Labels
A-parser Area: The parsing of Rust source code to an AST.

Comments

@bitonic
Copy link

bitonic commented Jan 6, 2015

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.

@kmcallister kmcallister added A-parser Area: The parsing of Rust source code to an AST. I-papercut labels Jan 6, 2015
@steveklabnik
Copy link
Member

Full example:

struct Timer<'a> {
    x: &'a i32,
}

impl<'b> Timer<'b> {
    pub fn new<'a>(delay: usize, callback: Box<(FnMut() -> usize) + 'a>, remove_on_drop: bool) -> Timer<'a> {
        unimplemented!()
    }
}

fn main() {}

Same error still happens today.

@pmarcelll
Copy link
Contributor

@petrochenkov if I understand it correctly, this is accepted today, but #40043 fixes the parser, so rejecting the parentheses is the correct behavior, and this is not a bug after all (and can be closed).

@petrochenkov
Copy link
Contributor

petrochenkov commented Mar 5, 2017

@pmarcelll
Indeed.
I wasn't aware of this issue.
Confusing diagnostics perhaps you forgot parentheses? are fixed in #40043 as well.
Closing as a duplicate of #39318.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST.
Projects
None yet
Development

No branches or pull requests

5 participants