rust-lang / rust-lang/rust-clippy

Possible enum_glob_use false positive

Open
#8,318 0 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

This code:

#![warn(clippy::pedantic)]

fn main() {
    enum Ops {Add, Sub, Mul, Div};
    use Ops::*;
    
    let op = Add;
    let s = match op {
        Add => "+",
        Sub => "-",
        Mul => "*",
        Div => "/",
    };
    println!("{}", s);
}

Gives:

warning: usage of wildcard import for enum variants
 --> src/main.rs:5:9
  |
5 |     use Ops::*;
  |         ^^^^^^ help: try: `Ops::{Add, Div, Mul, Sub}`
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![warn(clippy::pedantic)]
  |         ^^^^^^^^^^^^^^^^
  = note: `#[warn(clippy::enum_glob_use)]` implied by `#[warn(clippy::pedantic)]`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#enum_glob_use

In this case glob use seems OK to me...

Lint Name

No response

Reproducer

I tried this code:

<code>

I saw this happen:

<output>

I expected to see this happen:

Version

No response

Additional Labels

No response

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

Start by reproducing the supplied Rust example with the enum_glob_use lint enabled, then inspect the lint's implementation and existing tests. Determine whether this enum-wide import should be treated as a false positive and add or update coverage so the intended diagnostic behavior is verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.