Closed
Description
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
Labels
No labels