Skip to content

Suggestion: lint usage of non-reexported types from dependencies in public interface of lib crates #2848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Kixunil opened this issue Jun 15, 2018 · 1 comment
Labels
A-lint Area: New lints E-hard Call for participation: This a hard problem and requires more experience or effort to work on L-style Lint: Belongs in the style lint group

Comments

@Kixunil
Copy link

Kixunil commented Jun 15, 2018

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?

@Kixunil
Copy link
Author

Kixunil commented Nov 30, 2020

Some additional thoughts on this:

  • This helps with versioning
  • It might be useful to also reexport features of libraries that appear in the interface. Can clippy look at Cargo.toml?

@flip1995 flip1995 added L-style Lint: Belongs in the style lint group E-hard Call for participation: This a hard problem and requires more experience or effort to work on A-lint Area: New lints labels Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints E-hard Call for participation: This a hard problem and requires more experience or effort to work on L-style Lint: Belongs in the style lint group
Projects
None yet
Development

No branches or pull requests

2 participants