Rust errors / Types and traits
Rust compiler error · checked with rustc 1.99.0
Rust error E0561: patterns aren't allowed in function pointer types
What it meansA non-ident or non-wildcard pattern has been used as a parameter of a function pointer type.
What rustc prints
error[E0561]: patterns aren't allowed in function pointer types
--> main.rs:1:14
|
1 | type A1 = fn(mut param: u8); // error!
| ^^^^^^^^^Real 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
A non-ident or non-wildcard pattern has been used as a parameter of a function pointer type.
Erroneous code example:
type A1 = fn(mut param: u8); // error!
type A2 = fn(¶m: u32); // error!
When using an alias over a function type, you cannot e.g. denote a parameter as being mutable.
To fix the issue, remove patterns (_ is allowed though). Example:
type A1 = fn(param: u8); // ok!
type A2 = fn(_: u32); // ok!
You can also omit the parameter name:
type A3 = fn(i16); // ok!From rustc --explain E0561 (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
- E0529expected an array or slice, found `f32`
- E0531cannot find tuple struct or tuple variant `Type` in this scope
- E0562`impl Trait` is not allowed in the type of variable bindings
- E0567auto traits cannot have generic parameters
Up next
Often hit nextE0308: mismatched typesA related error from the same family.Read it next →Did this answer your question?