Skip to content

|| true after macro invocation in StmtExpr parses oddly #19658

Closed
@tomjakubowski

Description

@tomjakubowski

For example:

#![feature(macro_rules)]

macro_rules! foo { () => { true } }

fn baz() -> bool {
    foo!() || true
}

fn main() { }

When compiled, produces these errors:

foo.rs:3:28: 3:32 error: mismatched types: expected `()`, found `bool` (expected (), found bool)
foo.rs:3 macro_rules! foo { () => { true } }
                                    ^~~~
foo.rs:3:1: 3:36 note: in expansion of foo!
foo.rs:6:5: 6:14 note: expansion site
foo.rs:6:12: 6:19 error: mismatched types: expected `bool`, found `|| -> bool` (expected bool, found fn)
foo.rs:6     foo!() || true
                    ^~~~~~~
error: aborting due to 2 previous errors

Whereas something like this does parse as intended:

#![feature(macro_rules)]

macro_rules! foo { () => { true } }

fn main() {
    if foo!() || true {

    }
}

The error is remedied by surrounding the whole expression in parentheses, turning it into a return statement, or doing something like let x = foo!() || true; x.

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