rust-lang / rust-lang/rust-clippy
Suggestion: lint usage of non-reexported types from dependencies in public interface of lib crates
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
I think this suggestion can be best explained with an example. Suppose we have a library crate with this lib.rs
extern crate byteorder;
pub struct MyStruct { /* details are irrelevant */ }
impl MyStruct {
pub fn deserialize::<BO: byteorder::ByteOrder>(data: &[u8]) -> Self {
// implementation irrelevant
}
The problem with this crate is that in order to use it, a user must explicitly add byteorder crate to dependencies, which is annoying. However, if the crate had pub extern crate byteorder; or re-exported byteorder::{ByteOrder, LE, BE}, no additional definitions would be necessary.
So I suggest to detect instances of usage of types from dependencies in interfaces and warn if they aren't public/re-exported.
Of course, there is a difficulty with traits used like in this example (re-exporting byteorder::ByteOrder isn't enough but there is nothing in the interface of the deserialize method to suggest that). One way to address it would be suggesting to either make the whole dependency public or re-export all public types implementing that trait.
What do you think?
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 with the lib.rs example and define how a lint should identify dependency types exposed through a public interface without a public dependency or re-export. Resolve the trait case and decide what warning or re-export guidance means; done requires a concrete, testable lint specification, though no test or implementation file is named.
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
- Needs clarification
- Newbie friendliness
- 25/100