Skip to content

single-component-path-imports, and macro_rules macros #13419

@ijackson

Description

@ijackson

Summary

With macro_rules macros, use name_of_the_macro can be useful to give the macro a path scope. Macros otherwise only have lexical scope.

This can be useful to refer to the macro before its definition, or for rustdoc.

Lint Name

single-component-path-imports

Reproducer

Steps

git clone https://gitlab.torproject.org/Diziet/arti
cd arti
git checkout origin/report-clippy-single-path-imports-false-positive~0
cargo clippy --locked -p tor-socksproto

Expected output

No complaints

Actual output

warning: this import is redundant
   --> crates/tor-socksproto/src/handshake/framework.rs:440:1
    |
440 | use derive_deftly_template_Handshake; // for rustdoc's benefit
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it entirely
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports
note: the lint level is defined here
   --> crates/tor-socksproto/src/lib.rs:9:9
    |
9   | #![warn(clippy::all)]
    |         ^^^^^^^^^^^
    = note: `#[warn(clippy::single_component_path_imports)]` implied by `#[warn(clippy::all)]`

Repro that suggested code is broken

git checkout origin/report-clippy-single-path-imports-false-positive~1
cargo doc -p tor-socksproto --locked --all-features --document-private-items --no-deps

This 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

(multiple copies).

For my reference, the current branch tip for report-clippy-single-path-imports-false-positive is 8063b71ff92dd30d7fdf2d8200cda7e06f2a0db8

Version

rustc 1.81.0-beta.6 (b5fd9f6f1 2024-08-21)
binary: rust
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

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions