Closed
Description
Here's a toy program demonstrating the problem:
macro_rules! my_macro {
() => {
fn my_func() {
// An intentional type error here. The compiler doesn't do a good
// job of saying what line is causing it.
assert_eq!(0u8, 0u16);
}
}
}
my_macro!();
fn main() {
my_func();
}
Compiling it (current stable rustc, 1.21) gives the following error:
error[E0308]: mismatched types
--> src/main.rs:11:1
|
11 | my_macro!();
| ^^^^^^^^^^^^
| |
| expected u8, found u16
| in this macro invocation
|
= note: this error originates in a macro outside of the current crate
All the compiler is telling me is that "something inside the macro generates this type error". In particular, it's not able to tell me that the problem is on line 6. I wouldn't be surprised if this was a known problem somewhere, but I wanted to make sure to report it, since it's probably super confusing for new developers. (For example, I expect you could run into this easily by combining assert!
with another common macro like lazy_static!
.)