Rust errors / Types and traits
Rust compiler error · checked with rustc 1.99.0
Rust error E0642: patterns aren't allowed in functions without bodies
What it meansTrait methods currently cannot take patterns as arguments.
What rustc prints
error[E0642]: patterns aren't allowed in functions without bodies
--> main.rs:2:12
|
2 | fn foo((x, y): (i32, i32)); // error: patterns aren't allowed
| ^^^^^^ pattern not allowed in function without bodyReal output of rustc 1.99.0 compiling the official example below (2021 edition). Your names and line numbers will differ; the first line is the part to match.
The compiler team's explanation
Trait methods currently cannot take patterns as arguments.
Erroneous code example:
trait Foo {
fn foo((x, y): (i32, i32)); // error: patterns aren't allowed
// in trait methods
}
You can instead use a single name for the argument:
trait Foo {
fn foo(x_and_y: (i32, i32)); // ok!
}From rustc --explain E0642 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.
Related errors
- E0308mismatched types
- E0277the trait bound is not satisfied
- E0599no method named X found in the current scope
- E0433failed to resolve
- E0631type mismatch in closure arguments
- E0634type has conflicting packed representation hints
- E0643method `foo` has incompatible signature for trait
- E0644closure/coroutine type that references itself
Up next
Often hit nextE0308: mismatched typesA related error from the same family.Read it next →Did this answer your question?