rust-lang / rust-lang/rust-clippy
Lint against non-idiomatic use paths
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Warn users about importing item other than modules, types, traits and derive macros.
Categories (optional)
- Kind:
clippy::style.
What is the advantage of the recommended code over the original code
Specifying the parent module when calling the function makes it clear that the function isn’t locally defined while still minimizing repetition of the full path.
when bringing in structs, enums, and other items with use, it’s idiomatic to specify the full path.
The book does not say about how to import macros. Personally, I suggest that warn about importing:
- functions,
- function-like and attribute-like macros,
- consts,
- statics,
while allowing importing:
- derive macros,
- modules,
- traits,
- types.
Drawbacks
This style might not be suitable for everyone, and should not be enforced by default.
Example
mod front_of_house {
pub mod hosting {
pub fn add_to_waitlist() {}
}
}
use self::front_of_house::hosting::add_to_waitlist;
pub fn eat_at_restaurant() {
add_to_waitlist();
add_to_waitlist();
add_to_waitlist();
}
Could be written as:
mod front_of_house {
pub mod hosting {
pub fn add_to_waitlist() {}
}
}
use self::front_of_house::hosting;
pub fn eat_at_restaurant() {
hosting::add_to_waitlist();
hosting::add_to_waitlist();
hosting::add_to_waitlist();
}
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
Start from the issue's examples and the linked Rust Book section on creating idiomatic use paths. Define the lint behavior for functions, function-like and attribute-like macros, consts, and statics, while allowing derive macros, modules, traits, and types. Done means the proposed non-default style lint consistently distinguishes these item categories.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100