-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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.
Description
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
hellow554 and cherryblossom000
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.