Skip to content

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

Open
@Kixunil

Description

@Kixunil

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsE-hardCall for participation: This a hard problem and requires more experience or effort to work onL-styleLint: Belongs in the style lint group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions