Skip to content

Lint to catch 'overlapping' wildcard globs #7432

Closed
@arlyon

Description

@arlyon

What it does

By default in rust when using wildcards in use statements, and two modules export things with overlapping names then rather than throw an error, the compiler just uses the first and 'silently' ignores the others.

Example:

lib.rs

mod test1;
mod test2;

pub use test1::*;
pub use test2::*;

test1.rs

enum MyEnum {
    Item1,
    Item2,
}

test2.rs

enum MyEnum {
    Item1,
    Item2,
    Item3,
}

Now we probably can't put this in the compiler as it is a breaking change, however a clippy lint for this would be nice. For context I am working with generated code and have only recently noticed that part of the api is not exported (and therefor broken) due to this issue.

arlyon/async-stripe#66

I suggest a lint that detects overlapping wildcards and exposes a warning to the user on the imports that suffer from this issue about what is going on.

Categories (optional)

  • Kind: clippy::suspicious

What is the advantage of the recommended code over the original code

This will help detect subtle issues that can arise from 'import erasure' (for lack of a better term).

Drawbacks

None.

Example

warning: this wildcard exports test2::MyEnum which clashes with test1::MyEnum causing it to be ignored
  --> src/lib.rs:5:1
   |
 5 | pub use test2::*;
   | ^^^^^^^^^^^^^^^^^ help: consider changing the names to prevent a clash or importing explicitly
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#overlapping_wildcards

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions