Skip to content

unused import false positive with macro rules macro #130570

Closed as not planned
Closed as not planned
@ijackson

Description

@ijackson

Steps

git clone https://gitlab.torproject.org/Diziet/arti
cd arti
git checkout origin/report-unused-import-false-positive~0
cargo check -p tor-socksproto --locked

Current output

warning: unused import: `derive_deftly_template_Handshake`
   --> crates/tor-socksproto/src/handshake/framework.rs:440:5
    |
440 | use derive_deftly_template_Handshake; // for rustdoc's benefit
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(unused_imports)]` on by default

warning: `tor-socksproto` (lib) generated 1 warning (run `cargo fix --lib -p tor-socksproto` to apply 1 suggestion)

Desired output

No warning

Rationale and extra context

use on the name of a macro_rules macro is useful to give the macro path scope. In this case, the macro ends up being used by a rustdoc.

Other cases

To show that the warning is incorrect:

git checkout origin/report-unused-import-false-positive~1
cargo doc -p tor-socksproto --locked --all-features --document-private-items --no-deps

which produces

warning: unresolved link to `derive_deftly_template_Handshake`
  --> crates/tor-socksproto/src/handshake/framework.rs:10:29
   |
10 | //!  * Derive [`Handshake`](derive_deftly_template_Handshake).
   |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `derive_deftly_template_Handshake` in scope
   |
   = note: `macro_rules` named `derive_deftly_template_Handshake` exists in this crate, but it is not in scope at this link's location
   = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default

Rust Version

rustc 1.81.0-beta.6 (b5fd9f6f1 2024-08-21)
binary: rustc
commit-hash: b5fd9f6f1061b79c045cc08fe03e00caad536800
commit-date: 2024-08-21
host: x86_64-unknown-linux-gnu
release: 1.81.0-beta.6
LLVM version: 18.1.7

Anything else?

clippy also complains about this; see rust-lang/rust-clippy#13419

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-discussionCategory: Discussion or questions that doesn't represent real issues.L-unused_importsLint: unused_importsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions