Why this fires¶
The inferred enum shorthand .Variant resolved its enum from the surrounding position's expected type — and that enum has no variant by that name. This is almost always a typo (a "did you mean?" suggestion is attached when a close match exists).
enum Target { Native, Llvm, Wasm }
fn f() {
let t: Target = .Nativ
// ^^^^^^ error[TE137]: `.Nativ` is not a variant of enum
// 'Target'. Did you mean 'Native'?
}TE137 only fires once the enum itself is known. When the position supplies no usable expected type, the compiler cannot even name an enum to check against and reports TE136 instead — so these two codes are mutually exclusive at any one site.
The pattern form of the shorthand reports the same failure under TE133, not TE137:
enum Target { Native, Llvm }
fn n(t: Target) -> int {
match t {
.Nope => 1,
//^^^^ error[TE133]: enum 'Target' has no variant 'Nope'
_ => 0,
}
}That is deliberate: a pattern that names an unknown variant is the same user-facing mistake whether it is written .Nope or Target::Nope, and TE133 already owns it.
Fix it¶
1. Fix the spelling¶
Trust the "did you mean?" suggestion when it appears — it is computed against the enum's real declared variant names.
enum Target { Native, Llvm, Wasm }
let t: Target = .Native // fixed2. Check that the expected type is the enum you meant¶
If the suggestion looks unrelated, the annotation (or the parameter, or the declared return type) may name a different enum than you had in mind. Spelling the qualified form out makes the mismatch visible immediately:
enum Target { Native, Llvm }
enum Mode { Debug, Release }
let m: Mode = Mode::Debug // qualified — the compiler checks the name against `Mode`3. Declare the variant if it is genuinely new¶
enum Target { Native, Llvm, Wasm, Interp } // add it to the declaration
let t: Target = .InterpSee also¶
TE136— the enum could not be inferred for this position at all.TE133— the same unknown-variant check forEnumName::variantand for.Variantpatterns.TE123— the equivalent "did you mean?" check for unknown struct fields.- /docs/data-structures#enums — enum declarations, unit/tuple/struct variants.