E0164 Expected Tuple Struct or Variant Fix
Written December 3, 2026 · Tested with Rust 1.99.1 · 17 min read
- The rule underneath: call form in a pattern names a constructor
- How to read the diagnostic
- The first failure: the index example
- The same error in the other pattern positions
Written December 3, 2026
Tested with Rust 1.99.1
What this guide is
Error E0164 means something that is neither a tuple struct nor a tuple variant was used as a pattern - in the index's words, something which is neither a tuple struct nor a tuple variant was used as a pattern. The error codes index example writes an associated function, A::new(), as a match arm pattern, and its repair matches on a variant of the enum instead, A::B.
In the shapes probed in this guide, the index example verbatim drew exactly one E0164 and no other code - this premise is clean, with no ride-along to separate. The count follows the bad patterns, in the probed shapes: two call patterns in one match drew exactly two E0164 reports, one per pattern, and two matches carrying one bad pattern each also drew two. The code is not specific to match: the same associated-function call written as an if let pattern, as a let pattern, and as a function parameter pattern each drew exactly one E0164 in the probed shapes, and so did an associated function of a struct, S::new(). The near neighbors land elsewhere, in the probed shapes: a free function call as a pattern drew E0532 alone, a unit variant written with parentheses and a unit struct written with parentheses each drew E0532, the same associated function written without parentheses drew E0533, a method call as a pattern drew one unnumbered report that a pattern was expected, and a real tuple variant pattern carrying the wrong number of fields drew E0023. An unresolved name elsewhere in the program did not hide this error in the probed shape: it was reported alongside, one E0164 and one E0425. The call form itself is not banned: tuple variant and tuple struct patterns are ordinary code, a constant is a valid pattern, and the same associated function called in expression position compiles and runs. This guide shows the E0164 shapes, the neighboring shapes, the boundary, 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: call form in a pattern names a constructor
A pattern written in call form - a path followed by parenthesized sub-patterns - is read as a constructor pattern: it says the value was built by that constructor and binds the fields it was built from. Only two items can play that role, which is the index's rule: only a tuple struct and a tuple variant are allowed as a pattern in that form. An associated function is neither, even when its name and job feel like a constructor's - A::new() is a function the compiler would have to run, and patterns never run code. They match against values that already exist.
That is why every repair moves the call out of the pattern. Either the pattern names something that really is a tuple struct or tuple variant, or the function is called first in expression position - where calls belong - and the pattern matches the value the call returned, or the call moves into a match guard, the one place next to a pattern where an expression is allowed to run.
How to read the diagnostic
The E0164 header names what was found: "expected tuple struct or tuple variant, found associated function A::new". The report carries one span, the pattern itself, labeled with the note that `fn` calls are not allowed in patterns, and a help line pointing at the patterns chapter of the book. There is no suggested replacement pattern in the report; the variant repair lives in the index entry.
The count follows the bad patterns, in the probed shapes - one report per call-form pattern that names a function. Two such patterns in one match drew two reports, ending with "aborting due to 2 previous errors":
error[E0164]: expected tuple struct or tuple variant, found associated function `A::new`
--> fail_two_patterns.rs:13:9
|
13 | A::new() => (),
| ^^^^^^^^ `fn` calls are not allowed in patterns
|
= help: for more information, visit https://doc.rust-lang.org/book/ch19-00-patterns.html
error[E0164]: expected tuple struct or tuple variant, found associated function `A::old`
--> fail_two_patterns.rs:14:9
|
14 | A::old() => (),
| ^^^^^^^^ `fn` calls are not allowed in patterns
|
= help: for more information, visit https://doc.rust-lang.org/book/ch19-00-patterns.html
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0164`.
Fix every call-form pattern in the output before recompiling; a second one is already reported, not hidden behind the first.
The first failure: the index example
The index's erroneous example, verbatim - the pattern is an associated function call:
#![allow(unused)]
fn main() {
enum A {
B,
C,
}
impl A {
fn new() {}
}
fn bar(foo: A) {
match foo {
A::new() => (), // error!
_ => {}
}
}
}
error[E0164]: expected tuple struct or tuple variant, found associated function `A::new`
--> fail_index.rs:14:9
|
14 | A::new() => (), // error!
| ^^^^^^^^ `fn` calls are not allowed in patterns
|
= help: for more information, visit https://doc.rust-lang.org/book/ch19-00-patterns.html
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0164`.
Exactly one report, and it is the whole story: no second code rides along in this example. The separation checks confirm the pattern is the only defect. The function itself is not the problem: calling the same associated function in expression position - let a = A::new(); - and matching the result compiled and ran in the probed shape, shown in the boundary section below. And the match is not the problem either: the same match with a variant pattern in place of the call is the index's repair, shown in the repairs section.
The same error in the other pattern positions
The ban follows the pattern, not the match keyword. An associated function of a struct draws the same code as one of an enum, in the probed shape - S::new() as a match pattern drew exactly one E0164, naming associated function `S::new`, in the file fail_struct_assoc_fn.rs. The remaining pattern positions agree, in the probed shapes: if let A::new() = foo drew exactly one E0164 in the file fail_if_let.rs, a let A::new() = foo; binding drew exactly one E0164 in the file fail_let_pattern.rs, and a parameter written fn bar(A::new(): A) drew exactly one E0164 in the file fail_fn_param.rs. Wherever a pattern can be written, a call-form pattern that names a function is this error, under this one code.
One co-report belongs here. A program that carried the index match and an unresolved name in another function reported both - exactly one E0164 and one E0425, in the file ride_unresolved.rs:
error[E0164]: expected tuple struct or tuple variant, found associated function `A::new`
--> ride_unresolved.rs:14:9
|
14 | A::new() => (),
| ^^^^^^^^ `fn` calls are not allowed in patterns
|
= help: for more information, visit https://doc.rust-lang.org/book/ch19-00-patterns.html
error[E0425]: cannot find function `missing_name` in this scope
--> ride_unresolved.rs:20:5
|
20 | missing_name();
| ^^^^^^^^^^^^ not found in this scope
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0164, E0425.
For more information about an error, try `rustc --explain E0164`.
Read the pair as two separate defects, not one defect stated twice: the name error does not mask the pattern error in this shape, and fixing either one leaves the other standing.
The shapes that are not this error
Changing the shape of the bad pattern changes the code. A free function call as a pattern - make() where make is a plain function - drew exactly one E0532 and no E0164 in the probed shape:
error[E0532]: expected a pattern, found a function call
--> fail_free_fn.rs:7:9
|
7 | make() => (),
| ^^^^ not a tuple struct or tuple variant
|
= note: function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch19-00-patterns.html>
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0532`.
The E0532 half of the family covers the wrong-kind pattern more broadly, in the probed shapes: a unit variant written with parentheses, A::B(), drew exactly one E0532 ("expected tuple struct or tuple variant, found unit variant A::B", with a help line to drop the parentheses) in the file fail_unit_variant_call.rs, and a unit struct written with parentheses, U(), drew exactly one E0532 in the file fail_unit_struct_call.rs. Read the header to tell them apart: E0164 names an associated function as what was found; E0532 is drawn by the free function and by items that exist but take no fields.
Dropping the parentheses changes the code again. The associated function written bare, A::new with no call form, drew exactly one E0533 in the probed shape:
error[E0533]: expected unit struct, unit variant or constant, found associated function `A::new`
--> fail_fn_item_pattern.rs:12:9
|
12 | A::new => (),
| ^^^^^^ not a unit struct, unit variant or constant
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0533`.
A method call cannot even be read as a pattern. Writing s.get() as an arm drew one unnumbered report in the probed shape - "expected a pattern, found an expression", with a note that arbitrary expressions are not allowed in patterns and a help line suggesting the expression move to a match arm guard, in the file fail_method_call.rs. And a pattern that names a real tuple variant but carries the wrong number of fields is a different defect again: Some(1, 2) drew exactly one E0023, "this pattern has 2 fields, but the corresponding tuple variant has 1 field", in the file fail_wrong_arity.rs. None of these shapes drew E0164: each fails at a different part of the pattern rules.
The boundary: constructors, constants, and calls in expression position
The line is what the call-form pattern names. On the other side of it, the same forms are ordinary code. A tuple variant pattern - Some(x) - compiled and ran in the probed shape, printing 42:
fn main() {
let o = Some(41);
match o {
Some(x) => println!("{}", x + 1),
None => println!("none"),
}
}
42
A tuple struct pattern compiled and ran in the probed shape, printing 20, in the file boundary_tuple_struct_pattern.rs - a tuple struct constructor is one of the two items the index allows in call form. A constant is a valid pattern without any call form: matching a value against the constant LIMIT compiled and ran, printing at the limit, in the file boundary_const_pattern.rs. And the associated function from the failing example is welcome in expression position: let a = A::new(); followed by a match on a compiled and ran, printing made b, in the file boundary_call_in_expr.rs. The function was never banned - only its use as a pattern was.
Related guides
For a pattern that names the wrong kind of item - a free function, a unit variant or unit struct written with parentheses - the neighboring code is E0532. For an item that is not a unit struct, unit variant, or constant used as a bare pattern, the code is E0533. For a tuple variant pattern with the wrong number of fields, the code is E0023. For an unresolved name reported alongside a pattern error, the code is E0425.
The repairs
Every repair below starts from the same observation: the call may keep its meaning, but it has to leave the pattern. Either the pattern names a real constructor or a constant, or the function runs in expression position or in a guard and the pattern matches what it produced.
Use the index's variant form. This is the index's own repaired example, verbatim: the arm matches the variant A::B instead of calling A::new():
#![allow(unused)]
fn main() {
enum A {
B,
C,
}
impl A {
fn new() {}
}
fn bar(foo: A) {
match foo {
A::B => (), // ok!
_ => {}
}
}
}
The shape compiled in the probed shape. It produces no program output - bar is never called from main - so there is no output to show; the runnable variant, a match returning a string per variant, compiled and ran in the probed shape, printing b and then c, in the file fix_match_variant_runnable.rs.
Call the function first, then match the bound result. Where the associated function really is the constructor in spirit, run it where calls belong and match the value it returns:
enum A {
B,
C,
}
impl A {
fn new(flag: bool) -> A {
if flag {
A::B
} else {
A::C
}
}
}
fn main() {
let a = A::new(true);
match a {
A::B => println!("bound b"),
A::C => println!("bound c"),
}
}
bound b
The pattern side is then an ordinary variant match, and the call keeps its arguments and its timing - it runs once, before the match, instead of pretending to run inside it.
Move the call into a guard. Where the intent was to test the value with a function, a match guard is the place an expression may run next to a pattern:
enum A {
B,
C,
}
fn is_b(a: &A) -> bool {
matches!(a, A::B)
}
fn bar(foo: A) -> &'static str {
match foo {
a if is_b(&a) => "guard b",
_ => "other",
}
}
fn main() {
println!("{}", bar(A::B));
println!("{}", bar(A::C));
}
guard b
other
The wildcard-with-binding pattern matches anything, and the guard decides - this is also the shape the compiler itself suggests when a method call is written as a pattern.
Give the enum a real tuple variant. Where new was standing in for a variant that carries data, adding that variant makes the call form legal as written, because a tuple variant is one of the two allowed items:
enum A {
Made(i32),
C,
}
fn bar(foo: A) -> i32 {
match foo {
A::Made(x) => x + 1,
A::C => 0,
}
}
fn main() {
println!("{}", bar(A::Made(30)));
println!("{}", bar(A::C));
}
31
0
Callers change with the repair choice in one visible way: the variant and tuple-variant repairs change what the pattern can bind - a tuple variant pattern can bind the fields the value was built from - while the bind-first and guard repairs keep the function and its logic exactly as they were, moved to a position where calling is allowed.
Fixes in reach order
First, read the header. "Expected tuple struct or tuple variant, found associated function" is E0164, a function call written as a pattern. A report that a pattern arm did not match the expected kind is E0532, an unnumbered "expected a pattern" report is a general expression written as a pattern, and a field-count report on a real variant is E0023 - each is repaired where it is written.
Second, if a variant or constant expresses the match, use it as the pattern - the index's repair. That clears every E0164 on that pattern at once.
Third, if the function has to run - it computes the value being matched, or it takes arguments - call it in expression position, bind the result, and match the binding; or move the test into a match guard. The function survives both moves unchanged.
Fourth, if the function was standing in for a variant that carries data, add the tuple variant and match it in call form. The pattern then binds the fields directly.
Fifth, if the output carries a second code, separate it before judging the program: an E0425 for an unresolved name is a second, independent defect reported alongside the E0164, and both must be fixed before the program compiles.
Decision summary
E0164 fired in the probed shapes for the index example verbatim (exactly one E0164, no other code), for two call patterns in one match (exactly two, one per pattern), for two matches carrying one bad pattern each (exactly two), for an associated function of a struct (exactly one), and for the same call written as an if let pattern, a let pattern, and a function parameter pattern (exactly one each). It was reported alongside another code in one probed shape: an unresolved name in the same program drew one E0425 next to the one E0164, neither masking the other. It did not fire, in the probed shapes, for a tuple variant pattern (compiled and ran, printing 42), for a tuple struct pattern (printing 20), for a constant pattern (printing at the limit), or for the same associated function called in expression position with its result matched (printing made b). The neighboring shapes drew other reports instead in the probed shapes: a free function call as a pattern, a unit variant written with parentheses, and a unit struct written with parentheses each drew exactly one E0532; the associated function written without parentheses drew exactly one E0533; a method call as a pattern drew one unnumbered expected-a-pattern report; and a tuple variant pattern with the wrong field count drew exactly one E0023. The repairs that compiled and ran in the probed shapes were the index's variant pattern verbatim (compiled; the function is never called, so no output), a runnable variant match (printing b and c), calling the function first and matching the bound result (printing bound b), a match guard calling a predicate (printing guard b and other), and a real tuple variant in place of the function (printing 31 and 0).
Checklist
- The test is what the call-form pattern names, in the probed shapes: E0164 is an associated function used as a pattern - a free function call in the same position is E0532, and the bare function path is E0533.
- The count is per bad pattern, in the probed shapes: two call patterns in one match drew two reports, and two matches with one each drew two.
- The position does not matter, in the probed shapes:
match,if let,let, and parameter patterns each drew the same single E0164. - The function itself is never the problem, in the probed shapes: calling it in expression position and matching the result compiled and ran.
- An unresolved name does not mask this error, in the probed shape: E0164 and E0425 were reported together, as two defects.
- The call leaves the pattern in every repair, in the probed shapes: a variant or tuple variant pattern, a bound result, and a guard call all compiled, and the runnable ones ran.
Sources
- Rust error codes index, E0164 - something which is neither a tuple struct nor a tuple variant was used as a pattern; the erroneous example writes the associated function
A::new()as a match pattern, and the repair matches the variantA::B, only tuple structs and tuple variants being allowed as a pattern in call form. - Rust error codes index, E0532 - a pattern arm did not match the expected kind; the neighboring code drawn in the probed shapes by a free function call used as a pattern, by a unit variant written with parentheses, and by a unit struct written with parentheses.
- Rust error codes index, E0533 - an item which is not a unit struct, a variant, nor a constant was used as a match pattern, whose own advice for matching a value returned by a method is to bind the value first; the neighboring code drawn in the probed shape by the associated function written without parentheses.
- Rust error codes index, E0023 - a pattern attempted to extract an incorrect number of fields from a variant; the neighboring code drawn in the probed shape by a tuple variant pattern carrying two fields for a one-field variant.
- Rust error codes index, E0425 - an unresolved name was used; the neighboring code drawn in the probed shape by an unresolved name in the same program as the index match, reported alongside the E0164 rather than masking it.
Keep Exploring
The full Rust hub \u2014 ownership, structs and enums, async, and measured comparisons.
Every guide on the site in one list, grouped by topic.
Every browser-only checker and verifier on the site.
The C++, Python, Sysadmin, Rust, Go, and TypeScript hubs.