Variant is never constructed in ENUM

I've the below enum:

pub enum AppAction {
    Task,
    Confirmation,
    Notification
}

But I'm getting the below warnings:

warning: variant is never constructed: `Task`
 --> src\models\app_action.rs:2:5
  |
2 |     Task,
  |     ^^^^
  |
  = note: `#[warn(dead_code)]` on by default

What are these?

It simply means that the variant is never used, "constructed", anywhere in your program.

2 Likes

There is no AppAction::Task anywhere in the program. Rust expects that if you say an enum variant exists, you will use it for something somewhere.

3 Likes

during development, when there's various enumerants that you intend to use later—it can be somewhat annoying to see this all the time

by putting this before the enum, or individually before intentionally unused items, you can make the warning disappear:

#[allow(dead_code)]

the warning also goes away when the enum is in a crate and public, because the compiler can't know if it's used anywhere

4 Likes

On the other hand, you are not going to forget them!

2 Likes

You are correct, I may have to live with them tell the app be completed.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.