rust-lang / rust-lang/rust-clippy

Force absolute path for some items

Open
#14,520 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

Lint absolute_paths (#10568) warns about items that use an absolute path instead of a use.
Clippy misses the opposite lint: warn about unqualified paths that are imported where they should not.

Advantage

An example is the log crate, which is often used as log::info! or log::error!. Unfortunately, newcomers may be tempted to import the macros from the log crate.

For consistency, it would be good to have an option to enforce the use of the full path with clippy.

Drawbacks

No response

Example
use log::error;

fn f() {
    error!("fatal error in f");
}

Could be written as:

fn f() {
    log::error!("fatal error in f");
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names the existing absolute_paths lint (#10568) and shows the desired log::error! form. Start by reviewing that lint and the surrounding Clippy lint conventions; determine the supported scope for unqualified imports and how the option should behave. Done means the requested lint is implemented with coverage for the shown examples and documented behavior.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.