Skip to content

Span for unused_macros lint is too large, which makes writing macros in IDEs annoying #90745

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
PatchMixolydic opened this issue Nov 10, 2021 · 1 comment · Fixed by #90761
Closed
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@PatchMixolydic
Copy link
Contributor

PatchMixolydic commented Nov 10, 2021

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:

A screenshot of VSCode with rust-analyzer demonstrating the problem.

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

@PatchMixolydic PatchMixolydic added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 10, 2021
@rustbot rustbot added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Nov 10, 2021
@hellow554
Copy link
Contributor

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 11, 2021
Shorten Span of unused macro lints

The span has been reduced to the actual ident of the macro, instead of linting the
*whole* macro.

Closes rust-lang#90745

r? `@estebank`
hellow554 added a commit to hellow554/rust that referenced this issue Nov 12, 2021
Shorten Span of unused macro lints

The span has been reduced to the actual ident of the macro, instead of linting the
*whole* macro.

Closes rust-lang#90745

r? `@estebank`
@bors bors closed this as completed in 640f365 Nov 12, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants