-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-diagnosticsWorking group: DiagnosticsWorking group: Diagnostics
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!
.)
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-diagnosticsWorking group: DiagnosticsWorking group: Diagnostics