Rust

Duplicate Discriminant Value E0081 Fix

You give two enum variants the same number - or one variant quietly already holds the number you assign to another - and the compiler stops with E0081: a discriminant value can belong to only one variant. This guide shows each failing shape, which code it actually draws, the enums that compile and run, and the two repairs: give the clashing variant its own value, or drop the explicit value and let the implicit numbering take over.

Written December 2, 2026 · Tested with Rust 1.99.0 · 15 min read

By the end of this guide
  • The rule underneath: one value, one variant
  • How to read the diagnostic
  • The first failure: the index example
  • The clash you did not write: implicit values

Written December 2, 2026

Tested with Rust 1.99.0

What this guide is

Error E0081 means a discriminant value is present more than once in an enum. The error codes index puts it in one sentence: "A discriminant value is present more than once."

In the shapes probed in this guide, E0081 is drawn whenever two variants end up with the same discriminant value - whether both values are written out, one of them arrives implicitly, or one of them arrives through a constant. A reused variant name with different values is a different error, E0428, and an explicit discriminant on a payload variant without an integer representation adds E0732 alongside E0081 in the probed shape. This guide shows the E0081 shapes, the neighboring shapes, the enums that compile and run, and the repairs.

Build every program in this guide with rustc --edition 2021. In the compiler transcripts, the file names are the bare names shown on the command line.

The rule underneath: one value, one variant

Discriminants are used to differentiate enum variants stored in memory. The index states the consequence directly: the same value used for two or more variants makes it impossible to distinguish them. A value therefore belongs to at most one variant in an enum.

Variants without a manually specified discriminant are numbered from top to bottom starting from 0. That implicit numbering is the part that surprises: a variant with no value written next to it still holds a value, and a later explicit value can collide with it. An explicit value also resets the run - in the probed shapes, the variants after an explicit value continue from that value plus one.

How to read the diagnostic

The header names the value: "discriminant value 3 assigned more than once". Under the enum, each assignment of that value is marked with "3 assigned here", so the diagnostic points at both sides of the clash, not just the second one. When the clash is with an implicit value, the diagnostic still marks the implicit variant, and in one probed shape it adds a note explaining that the implicit variant's discriminant was incremented from an earlier startpoint.

Read the value in the header first. That is the number to resolve: one of the variants marked with that value has to move, or lose its explicit value.

The first failure: the index example

The index's erroneous example, verbatim:

Rust
#![allow(unused)]
fn main() {
enum Enum {
    P = 3,
    X = 3, // error!
    Y = 5,
}
}
Output
error[E0081]: discriminant value `3` assigned more than once
 --> fail_index.rs:3:1
  |
3 | enum Enum {
  | ^^^^^^^^^
4 |     P = 3,
  |         - `3` assigned here
5 |     X = 3, // error!
  |         - `3` assigned here

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0081`.

The example draws exactly one E0081 - no second code hides in it. Two variants, P and X, both hold 3, and the third variant's value, 5, is not part of the clash. The repair below keeps P at 3 and moves X to its own value.

The same shape without the index's framing fails identically:

Rust
enum E { A = 1, B = 1 }
fn main() { println!("x"); }
Output
error[E0081]: discriminant value `1` assigned more than once
 --> fail_simple_dup.rs:1:1
  |
1 | enum E { A = 1, B = 1 }
  | ^^^^^^       -      - `1` assigned here
  |              |
  |              `1` assigned here

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0081`.

Negative values clash the same way: an enum with two variants at -1 drew E0081 in the probed shape, with the header naming -1. Three variants sharing one value also drew exactly one E0081 in the probed shape, with all three assignments marked - the error is reported once per duplicated value in that shape, not once per extra variant.

The clash you did not write: implicit values

The index's second erroneous example gives the first variant no value at all:

Rust
#![allow(unused)]
fn main() {
enum Bad {
    X,
    Y = 0, // error!
}
}
Output
error[E0081]: discriminant value `0` assigned more than once
 --> fail_index_bad.rs:3:1
  |
3 | enum Bad {
  | ^^^^^^^^
4 |     X,
  |     - `0` assigned here
5 |     Y = 0, // error!
  |         - `0` assigned here

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0081`.

Here X already holds 0 - the first implicit value - by the time Y is assigned 0 explicitly, so the conflict occurs even though only one value is written in the source. The index states this warning in plain terms: clashes can occur with seemingly unrelated variants.

The clash can sit further down the list. In the probed shape with two implicit variants before the explicit one, the diagnostic explains the implicit value it computed:

Rust
enum E { A, B, C = 1 }
fn main() { println!("x"); }
Output
error[E0081]: discriminant value `1` assigned more than once
 --> fail_implicit_clash_later.rs:1:1
  |
1 | enum E { A, B, C = 1 }
  | ^^^^^^   -  -      - `1` assigned here
  |          |  |
  |          |  `1` assigned here
  |          discriminant for `B` incremented from this startpoint (`A` + 1 variant later => `B` = 1)

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0081`.

In this probed shape, A holds 0 and B holds 1 implicitly, so assigning 1 to C duplicates B, not A. When you read an E0081 with only one explicit assignment in sight, count the implicit variants above it before choosing which value to change.

A constant does not hide the duplicate

Writing one side of the clash as a constant, or as a constant expression, does not change the code. The compiler evaluates the discriminant values before comparing them, so a constant holding 4 clashes with a literal 4:

Rust
const V: isize = 4;
enum E { A = V, B = 4 }
fn main() { println!("x"); }
Output
error[E0081]: discriminant value `4` assigned more than once
 --> fail_const_dup.rs:2:1
  |
2 | enum E { A = V, B = 4 }
  | ^^^^^^       -      - `4` assigned here
  |              |
  |              `4` assigned here

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0081`.

A constant expression clashed the same way in the probed shape: a variant assigned 1 + 1 and a variant assigned 2 drew E0081, with the header naming 2. Renaming, factoring, or computing a value does not give a variant a distinct discriminant - only a distinct evaluated value does.

An integer representation does not change the code either: a duplicate under a u8 representation, in an enum written with a #[repr(u8)] attribute, drew exactly one E0081 in the probed shape, with the same header and the same two assignment marks.

The shapes that are not this error alone

An explicit discriminant on a variant that carries data adds a second error in the probed shape without a representation. The duplicate still draws E0081, and the payload variant also draws E0732:

Rust
enum E { A(i32) = 1, B = 1 }
fn main() { println!("x"); }
Output
error[E0732]: `#[repr(inttype)]` must be specified for enums with explicit discriminants and non-unit variants
 --> fail_payload_dup.rs:1:1
  |
1 | enum E { A(i32) = 1, B = 1 }
  | ^^^^^^            - explicit discriminant on non-unit variant specified here

error[E0081]: discriminant value `1` assigned more than once
 --> fail_payload_dup.rs:1:1
  |
1 | enum E { A(i32) = 1, B = 1 }
  | ^^^^^^            -      - `1` assigned here
  |                   |
  |                   `1` assigned here

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0081, E0732.
For more information about an error, try `rustc --explain E0081`.

The E0732 page states the rule behind the added error: an enum with a discriminant must specify a #[repr(inttype)] when it has a non-unit variant with a discriminant. Adding that representation in the probed shape removed E0732 and left exactly one E0081 - the duplicate itself still has to be fixed:

Rust
#[repr(i32)]
enum E { A(i32) = 1, B = 1 }
fn main() { println!("x"); }
Output
error[E0081]: discriminant value `1` assigned more than once
 --> fail_payload_repr_dup.rs:2:1
  |
2 | enum E { A(i32) = 1, B = 1 }
  | ^^^^^^            -      - `1` assigned here
  |                   |
  |                   `1` assigned here

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0081`.

A struct-style variant with an explicit discriminant behaved the same way in the probed shape: E0732 plus E0081, in an enum with a struct-style variant assigned 1 and a unit variant assigned 1.

Reusing a variant name is not E0081 at all. Two variants with the same name but different values drew E0428:

Rust
enum E { A = 1, A = 2 }
fn main() { println!("x"); }
Output
error[E0428]: the name `A` is defined multiple times
 --> neighbour_dup_variant_name.rs:1:17
  |
1 | enum E { A = 1, A = 2 }
  |          -----  ^^^^^ `A` redefined here
  |          |
  |          previous definition of the type `A` here
  |
  = note: `A` must be defined only once in the type namespace of this enum

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0428`.

A value that does not fit the representation is also not E0081. In the probed shape, a single variant assigned 256 under a u8 representation drew a literal-out-of-range error with no error code in brackets, stating that the literal does not fit into u8, whose range is 0..=255. There was no duplicate in that shape - the problem was the size of the one value, not a clash between two.

What does work: distinct values, written or implicit

Distinct explicit values compile and run. The probed enum printed its three discriminants in order:

Rust
enum E { A = 1, B = 2, C = 5 }
fn main() { println!("{} {} {}", E::A as i32, E::B as i32, E::C as i32); }
Output
1 2 5

The index's own non-erroneous example compiles in the probed shape as well: a first variant with no value, then explicit values of 3 and 5, printed ok when a print statement was added inside main. Distinct negative values compile too: the probed enum at -1, 0, and 1 printed -1 0 1. Distinct values under a u8 representation compiled and printed 1 2 in the probed shape.

Implicit numbering after an explicit value continues from that value, and it compiles when the result stays distinct:

Rust
enum E { A = 3, B, C }
fn main() { println!("{} {} {}", E::A as i32, E::B as i32, E::C as i32); }
Output
3 4 5

In this probed shape B holds 4 and C holds 5, neither written in the source. That continuation is exactly the mechanism behind the implicit clashes above - it helps when the continued values are free, and it clashes when a later explicit value lands on one of them.

Duplicate definitions cluster together. For a name defined more than once, see Duplicate Definition E0428 Fix. For patterns that leave a variant uncovered, see Non-Exhaustive Patterns E0004 Fix.

The repairs

Give the second variant its own distinct value. This repair keeps the first variant's value from the index example, moves the clashing variant to the next free value, and leaves the third variant alone:

Rust
enum Enum { P = 3, X = 4, Y = 5 }
fn main() { println!("{} {} {}", Enum::P as i32, Enum::X as i32, Enum::Y as i32); }
Output
3 4 5

Or remove the clashing explicit value and let the implicit numbering assign a distinct one. This repair fixes the index's Bad shape by replacing the explicit 0 - which duplicated the first variant's implicit 0 - with an explicit 1:

Rust
enum Bad { X, Y = 1 }
fn main() { println!("{} {}", Bad::X as i32, Bad::Y as i32); }
Output
0 1

Dropping every explicit value works the same way when no specific numbers are required: the probed enum with three variants and no values printed 0 1 2. Choose distinct explicit values when the numbers themselves carry meaning - a wire format, a stored code, a protocol value - and implicit numbering when they do not, so there is no written value left to clash.

Fixes in reach order

First, read the value in the header. The header names the duplicated discriminant value, and the marks under the enum show every assignment of it. In the probed shapes that value arrived as two explicit values (the index example, a simple duplicate, a negative duplicate, a three-way duplicate, and a duplicate under a u8 representation), as an explicit value clashing with an implicit one (the index's Bad example and the two-implicit-variants shape), or as a constant or constant expression evaluating to the other variant's value.

Second, count the implicit variants. A variant with no value holds the previous variant's value plus one, starting from 0 - so an explicit value can clash with a variant that has no number written next to it, as in the probed Bad and A, B, C = 1 shapes.

Third, check for a second error before fixing only the duplicate. In the probed shapes, an explicit discriminant on a payload or struct-style variant without an integer representation also drew E0732; adding a #[repr(inttype)] attribute removed E0732 and left the E0081 to fix. A reused variant name with different values is E0428, not E0081, and a value out of range for the representation is a literal-out-of-range error with no error code, not E0081.

Fourth, apply one repair: give one of the clashing variants a distinct value, as in the probed repair printing 3 4 5, or remove the clashing explicit value so the implicit numbering assigns a distinct one, as in the probed repairs printing 0 1 and 0 1 2.

Last, leave the distinct enums alone: distinct explicit values, distinct negative values, distinct values under a u8 representation, and implicit values continuing after an explicit one all compile in the probed shapes. Do not renumber them while fixing the duplicate next to them.

Decision summary

E0081 fired for every duplicated discriminant value probed - the index example (P = 3 and X = 3, exactly one E0081), a simple duplicate, a negative duplicate, a three-way duplicate (exactly one E0081 in the probed shape), a duplicate under a u8 representation, a duplicate through a constant and through a constant expression, and the implicit clashes: the index's Bad example (an explicit 0 against an implicit 0, exactly one E0081) and a shape where an explicit 1 clashed with the second variant's implicit 1. It did not fire alone for a payload variant with an explicit discriminant and no integer representation, which drew E0732 plus E0081 in the probed shape, or for a struct-style variant in the same position, which also drew E0732 plus E0081 in the probed shape; adding an integer representation to the payload shape left exactly one E0081. It did not fire for a reused variant name with different values, which drew E0428, or for a single value out of range for a u8 representation, which drew a literal-out-of-range error with no error code. The shapes that compiled and ran were distinct explicit values (printing 1 2 5), the index's non-erroneous example (printing ok in the probed shape), distinct negative values (printing -1 0 1), distinct values under a u8 representation (printing 1 2), implicit values continuing after an explicit one (printing 3 4 5), and the repairs: a distinct value for the clashing variant (printing 3 4 5), an explicit value replacing the clashing one in the Bad shape (printing 0 1), and no explicit values at all (printing 0 1 2).

Checklist

  • One discriminant value belongs to at most one variant: two variants ending up with the same value draw E0081 in the probed shapes, whether the values are explicit, implicit, or through a constant.
  • A variant with no value still holds one: implicit numbering starts at 0 and continues from the previous value, so an explicit value can clash with an implicit one, as in the probed Bad shape.
  • A constant does not hide a duplicate: a constant holding 4 clashing with a literal 4, and a constant expression 1 + 1 clashing with a literal 2, draw E0081 in the probed shapes.
  • An integer representation does not change E0081: a duplicate under a u8 representation draws E0081 in the probed shape.
  • Payload variants keep their own added code: an explicit discriminant on a payload or struct-style variant without an integer representation draws E0732 alongside E0081 in the probed shapes.
  • Names and ranges keep their own errors: a reused variant name with different values is E0428, and a value out of range for the representation is a literal-out-of-range error with no error code, in the probed shapes.
  • The two repairs in the probed shapes: give a clashing variant a distinct value, or remove the clashing explicit value so the implicit numbering assigns a distinct one - both compile and run.

Sources

  • Rust error codes index, E0081 - a discriminant value is present more than once; discriminants differentiate variants stored in memory, the same value for two or more variants makes them impossible to distinguish, and variants without a manually specified discriminant are numbered from top to bottom starting from 0, so clashes can occur with seemingly unrelated variants.
  • Rust error codes index, E0732 - an enum with a discriminant must specify a #[repr(inttype)]; the code added alongside E0081 by an explicit discriminant on a non-unit variant without an integer representation in the probed shapes.
  • Rust error codes index, E0428 - a type or module has been defined more than once; the code drawn by a reused variant name in the probed shape.

Keep Exploring