Given the following code (playground):
macro_rules! foo {
() => {};
}
fn bar() {
// do stuff
}
The current output is:
warning: unused macro definition
--> src/lib.rs:1:1
|
1 | / macro_rules! foo {
2 | | () => {};
3 | | }
| |_^
|
= note: `#[warn(unused_macros)]` on by default
warning: function is never used: `bar`
--> src/lib.rs:5:4
|
5 | fn bar() {
| ^^^
|
= note: `#[warn(dead_code)]` on by default
Note how the span for the unused_macros lint covers the entire macro definition. This is fine for terminal diagnostic output, but when using an IDE or a Rust language server, this causes the entire macro definition to be underlined with yellow:

In my experience, this tends to make writing macros obnoxious without allowing unused_macros (either globally or locally).
Ideally, the span for this lint should be reduced to the macro's identifier, similar to how the dead_code lint's span only highlights bar's identifier:
warning: unused macro definition
--> src/lib.rs:1:1
|
1 | macro_rules! foo {
| ^^^
|
= note: `#[warn(unused_macros)]` on by default
warning: function is never used: `bar`
--> src/lib.rs:5:4
|
5 | fn bar() {
| ^^^
|
= note: `#[warn(dead_code)]` on by default
@rustbot modify labels: +A-macros +C-enhancement
Given the following code (playground):
The current output is:
Note how the span for the
unused_macroslint covers the entire macro definition. This is fine for terminal diagnostic output, but when using an IDE or a Rust language server, this causes the entire macro definition to be underlined with yellow:In my experience, this tends to make writing macros obnoxious without allowing
unused_macros(either globally or locally).Ideally, the span for this lint should be reduced to the macro's identifier, similar to how the
dead_codelint's span only highlightsbar's identifier:@rustbot modify labels: +A-macros +C-enhancement