Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

unused import false positive with macro rules macro #130570

Open
ijackson opened this issue Sep 19, 2024 · 1 comment
Open

unused import false positive with macro rules macro #130570

ijackson opened this issue Sep 19, 2024 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-discussion Category: Discussion or questions that doesn't represent real issues. L-unused_imports Lint: unused_imports T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@ijackson
Copy link
Contributor

ijackson commented Sep 19, 2024

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

@ijackson ijackson 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 Sep 19, 2024
@clubby789
Copy link
Contributor

Seems like the same as #79542. I would argue this isn't really a false positive. You can import for rustdoc only by adding a #[cfg(doc)] to the import which resolves the warning.

@jieyouxu jieyouxu added C-discussion Category: Discussion or questions that doesn't represent real issues. L-unused_imports Lint: unused_imports T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-discussion Category: Discussion or questions that doesn't represent real issues. L-unused_imports Lint: unused_imports T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants