rust-lang / rust-lang/rust-clippy
single-component-path-imports, and macro_rules macros
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the warning with cargo clippy --locked -p tor-socksproto using the reported arti checkout, then compare it with the cargo doc reproduction. Start from the single-component-path-imports lint and the import in crates/tor-socksproto/src/handshake/framework.rs; done means the useful macro import is not reported as redundant and the rustdoc links resolve.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100