rust-lang / rust-lang/rust-clippy

New lint: reexport_crate_in_api

Open
#8,490 0 comments 0 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

If a library crate contains a type or trait in public API that was defined in a dependency, including alloc and std, then clippy should suggest to reexport the dependency using pub extern crate foo or pub use foo as bar.

Lint Name

reexport_crate_in_api

Category

style

Advantage
  • The downstream crates don't need to bother with adding it to Cargo.toml
  • Less version conflicts
  • No need to look up which version is compatible
  • No need for ugly tricks or high MSRV when the downstream dependency wants to depend optionally
  • Including std and alloc helps crates that want to be no_std-aware with optional std/alloc features
Drawbacks

A few more trivial items in crates. Changing rustdoc to put these at the bottom of docs would mitigate the noise.

Example
#[derive(Serialize, Deserialize)]
pub struct Foo(u32);

pub fn bar() -> String {
    "hello".to_owned()
}

Could be written as:

pub extern crate serde;
pub extern crate alloc;

#[derive(Serialize, Deserialize)]
pub struct Foo(u32);

pub fn bar() -> String {
    "hello".to_owned()
}

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 no implementation files, tests, or entry points. Start by surveying existing Clippy lint implementations and their UI tests, then define detection and suggestion coverage for dependency, alloc, and std reexports before validating the proposed examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.