E0130 Patterns in Foreign Function Fix
Written December 3, 2026 · Tested with Rust 1.99.1 · 19 min read
- The rule underneath: a foreign declaration names its arguments, it does not destructure them
- How to read the diagnostic
- The first failure: the index example
- The same error for other pattern shapes and other blocks
Written December 3, 2026
Tested with Rust 1.99.1
What this guide is
Error E0130 means a pattern was declared as an argument in a foreign function declaration - in the index's words, patterns aren't allowed in foreign function declarations. The error codes index example declares fn foo((a, b): (u32, u32)); inside an extern "C" block, where the argument is a tuple pattern instead of a name, and its advice is to replace the pattern argument with a regular one: either a struct argument, or a named argument that keeps the tuple type.
In the shapes probed in this guide, the index example verbatim drew exactly one E0130 and no other code - this premise is clean, with no ride-along to separate. The count follows the pattern arguments, in the probed shapes: a declaration with two pattern arguments drew exactly two E0130 reports, one per pattern argument, and a declaration with three drew three. The shape of the pattern changes nothing in kind: a struct pattern, a reference pattern, a nested tuple pattern, a slice pattern, a literal pattern, a mut binding, a ref binding, and an at-pattern each drew exactly one E0130 in the probed shapes, and the block around the declaration changes nothing either - an extern "system" block, an unsafe extern block, and a block with no ABI string all drew the same single report for the same pattern argument in the probed shapes. The rule is specific to foreign declarations: the same pattern argument in an ordinary function definition compiled and ran in the probed shape, and in a trait method declaration it drew a different code, E0642, in the probed shape. At the boundary, a plain identifier argument compiles and runs, and so do the wildcard _ as an argument name, a declaration with no arguments, a foreign static, and a variadic declaration. This guide shows the E0130 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: a foreign declaration names its arguments, it does not destructure them
A foreign function declaration is a promise about a function defined elsewhere: it gives the function's name, the type of each argument, and the return type, and nothing else - there is no body, so there is nothing that could take an incoming value apart. A pattern is a taking-apart: (a, b): (u32, u32) says "receive a pair and bind its two elements to a and b", and that binding step is exactly what a declaration cannot do. The Rust Reference states the allowed forms directly: patterns are not allowed in parameters of functions in external blocks - only an identifier or _ may be used.
That is why the repair is a renaming, not a redesign. The tuple type in the index example is fine as an argument type; what has to go is the pattern in the name position. Give the argument one name - a: (u32, u32) - or change the type to a struct and name that, and move any destructuring you actually need into a Rust function of your own that has a body to destructure in.
One nearby position has its own version of the same ban, under its own code. A trait method declaration also has no body, and a pattern argument there drew E0642 - "patterns aren't allowed in functions without bodies" - in the probed shape, not E0130. Read which code you have before repairing: E0130 points at a foreign declaration, E0642 at a body-less declaration that is not foreign, and the fix - one name for the argument - is the same shape for both.
How to read the diagnostic
The E0130 header is fixed wording: "patterns aren't allowed in foreign function declarations". The span underlines the whole pattern - in the index example, the six characters of (a, b) - and the label reads "pattern not allowed in foreign function". There is no note and no suggested fix in the report itself; the replacement advice lives in the index entry.
The count follows the pattern arguments, in the probed shapes - not the bindings inside them, and not the declarations. One pattern argument drew one report, even when the pattern held more than one binding: the nested pattern (a, (b, c)), binding three names, drew exactly one E0130 in the probed shape, its span covering the whole pattern. Two pattern arguments in one declaration drew two reports, one under each pattern, ending with "aborting due to 2 previous errors":
error[E0130]: patterns aren't allowed in foreign function declarations
--> fail_two_patterns.rs:3:12
|
3 | fn foo((a, b): (u32, u32), (c, d): (u32, u32));
| ^^^^^^ pattern not allowed in foreign function
error[E0130]: patterns aren't allowed in foreign function declarations
--> fail_two_patterns.rs:3:32
|
3 | fn foo((a, b): (u32, u32), (c, d): (u32, u32));
| ^^^^^^ pattern not allowed in foreign function
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0130`.
Fix every pattern argument in the output before recompiling; a second one is already reported, not hidden behind the first. Position changes nothing: a pattern in the second argument, after a plain first argument, drew exactly one E0130 in the probed shape, in the file fail_pattern_second_arg.rs. A return type changes nothing either: the same declaration ending in -> u32 drew exactly one E0130, in the file fail_pattern_with_return.rs - the ban is on the argument's form, wherever the declaration otherwise goes.
The first failure: the index example
The index's erroneous example, verbatim - the argument is a tuple pattern where a name belongs:
#![allow(unused)]
fn main() {
extern "C" {
fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
// function declarations
}
}
error[E0130]: patterns aren't allowed in foreign function declarations
--> fail_index.rs:4:12
|
4 | fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
| ^^^^^^ pattern not allowed in foreign function
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0130`.
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. Replacing the pattern with a single name over the same type - fn foo(pair: (u32, u32)); in the same block - compiled and ran, printing ok, in the file sep_removed_pattern.rs. And the pattern does not need the index's wrapper or its ABI to fire: the identical declaration at the top level of a file drew the same single report in every other failing shape in this guide.
The same error for other pattern shapes and other blocks
Any pattern in the name position draws the same report, however it is built. A struct pattern drew exactly one E0130 in the probed shape, its span covering the whole pattern:
error[E0130]: patterns aren't allowed in foreign function declarations
--> fail_struct_pattern.rs:4:12
|
4 | fn foo(Point { x, y }: Point);
| ^^^^^^^^^^^^^^ pattern not allowed in foreign function
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0130`.
A reference pattern, &(a, b): &(u32, u32), drew exactly one E0130 in the probed shape, in the file fail_ref_pattern.rs, and so did a slice pattern [a, b]: [u32; 2], in the file fail_slice_pattern.rs, and a literal pattern 42: u32, in the file fail_literal_pattern.rs. Bindings that look almost like plain names are patterns too: a mut binding drew exactly one E0130 in the probed shape:
error[E0130]: patterns aren't allowed in foreign function declarations
--> fail_mut_binding.rs:3:12
|
3 | fn foo(mut a: u32);
| ^^^^^ pattern not allowed in foreign function
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0130`.
A ref binding, ref a: u32, drew the same single report in the file fail_ref_binding.rs, and an at-pattern, a @ 42: u32, drew the same single report in the file fail_at_pattern.rs. There is no light form of the pattern that slips through: if the name position does more than name the argument, it is a pattern, and the report is E0130.
The block around the declaration changes nothing, in the probed shapes. The same pattern argument inside extern "system" drew exactly one E0130, in the file fail_extern_system.rs, and inside unsafe extern "C" it drew exactly one E0130, in the file fail_unsafe_extern.rs. A block with no ABI string at all, plain extern { ... }, drew exactly one E0130 for the pattern in the file fail_extern_no_abi.rs - alongside a deprecation warning that the block carries no explicit ABI, a warning about the block rather than the pattern, which the same block would draw with a plain argument in it.
The shapes that are not this error
The same pattern argument in a trait method declaration drew a different code. The trait shape drew exactly one E0642 in the probed shape - not E0130:
error[E0642]: patterns aren't allowed in functions without bodies
--> sep_trait_pattern.rs:3:12
|
3 | fn foo((a, b): (u32, u32));
| ^^^^^^ pattern not allowed in function without body
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0642`.
The split, in the probed shapes, is where the body-less declaration lives. Inside an external block, a pattern argument is E0130. In a trait, the same argument is E0642, the code for patterns in functions without bodies generally. And in an ordinary function definition - a declaration with a body - the same pattern argument is not an error at all: it compiled and ran in the probed shape, shown in the boundary section below.
An argument with no name at all is a different failure again. A foreign declaration written as fn foo(u32); - a bare type where the name belongs - drew an unnumbered parse error in the probed shape, not E0130:
error: expected one of `:`, `@`, or `|`, found `)`
--> neighbor_unnamed_arg.rs:3:15
|
3 | fn foo(u32);
| ^ expected one of `:`, `@`, or `|`
|
help: if this is a parameter name, give it a type
|
3 | fn foo(u32: TypeName);
| ++++++++++
help: if this is a type, explicitly ignore the parameter name
|
3 | fn foo(_: u32);
| ++
error: aborting due to 1 previous error
The report's own second suggestion is the boundary in miniature: a foreign argument must be an identifier or _ - a pattern is E0130, and nothing at all is a parse error.
The shape where a second code rides along
Other errors in the same program are reported alongside E0130. A program whose pattern-carrying declaration shared the file with an unresolved name in the entry point drew E0130 and E0425 together in the probed shape, ending with "aborting due to 2 previous errors":
error[E0130]: patterns aren't allowed in foreign function declarations
--> ride_unresolved.rs:3:12
|
3 | fn foo((a, b): (u32, u32));
| ^^^^^^ pattern not allowed in foreign function
error[E0425]: cannot find value `missing_name` in this scope
--> ride_unresolved.rs:5:28
|
5 | fn main() { println!("{}", missing_name); }
| ^^^^^^^^^^^^ not found in this scope
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0130, E0425.
For more information about an error, try `rustc --explain E0130`.
Fixing the pattern clears the E0130 in that shape and leaves the E0425 standing - the unresolved name is a separate problem that happens to share the output.
One warning rides along with the repairs rather than the error, and it is worth knowing before it surprises you. A tuple type - and a struct type with no representation attribute - is not FFI-safe, so a declaration that names such an argument compiles with an improper_ctypes warning: "extern block uses type (u32, u32), which is not FFI-safe", with the help "consider using a struct instead" for the tuple form and "consider adding a #[repr(C)] or #[repr(transparent)] attribute" for the struct form. The warning appears in the probed shapes for the named-tuple repair, for the struct repair, and for the separation shape with the pattern removed - it belongs to the argument's type, not to the pattern, and it never blocks the build: each of those shapes compiled and ran. The index's own two repairs both draw it in the probed shapes, because both keep a layout the foreign side cannot be assumed to share; treat it as the next thing to fix after E0130, on its own terms.
The boundary: names, the wildcard, and definitions with bodies
The line is the form of the argument's name position. On the other side of it, the same declaration is ordinary code. Plain identifier arguments - fn foo(a: u32, b: u32); in an extern "C" block - compiled and ran in the probed shape, printing plain. The wildcard is a name position of its own: fn foo(_: u32); compiled and ran in the probed shape, printing wildcard, and a wildcard beside a named tuple-typed argument - fn foo(_: u32, b: (u32, u32)); - compiled and ran, printing mixed, in the probed shape (the tuple type drawing the improper_ctypes warning described above). The Reference's rule is exactly this: only an identifier or _ may be used.
The simpler boundary shapes behave as expected. A declaration with no arguments at all, fn foo();, compiled and ran in the probed shape, printing noargs. A foreign static - the other kind of item an external block may declare - compiled and ran in the probed shape, printing static. And a variadic declaration, fn foo(a: u32, ...);, compiled and ran in the probed shape, printing variadic: the trailing ... is part of the declaration's form, not a pattern.
The sharpest boundary is the definition with a body. The index's pattern argument, moved into an ordinary Rust function definition, is ordinary code - the function receives the pair and binds its elements as its first act, which is what a body is for:
fn foo((a, b): (u32, u32)) -> u32 { a + b }
fn main() { println!("{}", foo((2, 3))); }
5
Related guides
For a pattern argument in a trait method declaration, the neighboring code is E0642. For an unresolved name elsewhere in a program that also carries a pattern argument, the neighboring code is E0425.
The repairs
Every repair below starts from the same observation: the declaration may keep the argument's type, but the name position must hold one name. Either give the argument that name, change the type to one that carries its fields under a single name, or keep the declaration plain and do the destructuring in a function that has a body.
Replace the pattern with a struct argument. This is the index's first repair: declare a struct with the fields the pattern was binding, and take one argument of that struct type. The shape compiled and ran in the probed shape, printing 3 - the sum of the two fields supplied to the struct in the entry point:
#![allow(unused)]
struct SomeStruct {
a: u32,
b: u32,
}
extern "C" {
fn foo(s: SomeStruct);
}
fn main() { let s = SomeStruct { a: 1, b: 2 }; println!("{}", s.a + s.b); }
3
The struct form drew the improper_ctypes warning described above in the probed shape - the struct as written has no representation attribute - so add #[repr(C)] when the foreign side really passes this struct by value; the E0130 itself is gone either way, because the argument now has one name.
Replace the pattern with a named tuple argument. This is the index's second repair, and the smaller change: keep the tuple type, and put one name in front of it. The shape compiled and ran in the probed shape, printing named:
#![allow(unused)]
extern "C" {
fn foo(a: (u32, u32));
}
fn main() { println!("named"); }
named
Callers on the foreign side are unaffected by either repair in the probed shapes - a pattern never reached the foreign side, because a declaration with a pattern in it never compiled; what the foreign function receives is the argument's value, under whatever name the Rust declaration gives it. The named-tuple form drew the improper_ctypes warning in the probed shape, for the tuple type rather than the name; the struct form above is the repair to prefer when that warning matters.
Destructure inside a wrapper instead. Where Rust code was going to take the pair apart anyway, keep the foreign declaration in the named form and put the pattern where patterns belong - in a Rust function with a body, which receives the named argument and destructures it there. The shape compiled and ran in the probed shape, printing 9, the sum produced by the wrapper over the pair (4, 5):
#![allow(unused)]
extern "C" {
fn foo(a: (u32, u32));
}
fn sum_pair(p: (u32, u32)) -> u32 { let (a, b) = p; a + b }
fn main() { println!("{}", sum_pair((4, 5))); }
9
Fixes in reach order
First, read the span. If it underlines something in an argument's name position inside an external block, the fix is a name. If the same wording appears as E0642 over a trait method, the fix is the same shape but the code is a different one - check which block the declaration sits in.
Second, replace each pattern argument with a single name over the same type - the index's named-tuple repair, and the smallest change that clears every E0130 in the declaration at once.
Third, if the fields were going to travel together, prefer the index's struct repair: one struct argument, with #[repr(C)] added when the foreign side passes the value for real, which also answers the improper_ctypes warning the plain struct draws.
Fourth, if the pattern existed because Rust code needs the elements separately, move it into a wrapper function with a body and let the wrapper destructure - the declaration itself never gets its pattern back.
Fifth, where an argument is genuinely unused on the Rust side, name it _ rather than leaving the position empty: the wildcard compiles, and a bare type in the name position is a parse error.
Sixth, if the output also carries a second code, separate it before judging the program: an unresolved name elsewhere is an E0425 of its own, and it survives the pattern fix until it is fixed on its own terms.
Decision summary
E0130 fired in the probed shapes for the index example verbatim (exactly one E0130, no other code), for a struct pattern, a reference pattern, a nested tuple pattern, a slice pattern, a literal pattern, a mut binding, a ref binding, and an at-pattern (exactly one each), for a pattern in the second argument after a plain first argument and for a pattern argument in a declaration with a return type (exactly one each), for two pattern arguments in one declaration (exactly two, one per pattern argument) and for three (exactly three), and for the same pattern argument in an extern "system" block, an unsafe extern block, and a block with no ABI string (exactly one each, the last also drawing a deprecation warning about the missing ABI). It rode along, in the probed shapes, with E0425 for an unresolved name elsewhere in the program. It did not fire, in the probed shapes, for the declaration with the pattern replaced by a single name (compiled and ran, printing ok), for plain identifier arguments (printing plain), for the wildcard _ as an argument name (printing wildcard, and mixed beside a named tuple-typed argument), for a declaration with no arguments (printing noargs), for a foreign static (printing static), for a variadic declaration (printing variadic), or for the same pattern argument in an ordinary function definition (compiled and ran, printing 5). The neighboring shapes drew other reports instead in the probed shapes: the same pattern argument in a trait method declaration drew exactly one E0642, and an argument with no name at all drew an unnumbered parse error. The repairs that compiled and ran in the probed shapes were replacing the pattern with a struct argument (printing 3), replacing it with a named tuple argument (printing named), and destructuring inside a wrapper function over the named form (printing 9) - the first two, and the named form generally, drawing an improper_ctypes warning for the argument type's layout in the probed shapes, a warning that belongs to the type and does not block the build.
Checklist
- The test is the name position, in the probed shapes: a foreign argument may be an identifier or
_- anything that destructures, binds withmutorref, or matches a literal is a pattern and draws E0130. - The count is per pattern argument, in the probed shapes: one pattern argument drew one report however many names it bound, and two and three pattern arguments drew two and three reports.
- The pattern's shape changes nothing, in the probed shapes: tuple, struct, reference, slice, literal, and binding patterns all drew the same E0130.
- The block changes nothing either, in the probed shapes:
extern "C",extern "system",unsafe extern, and a block with no ABI string all drew E0130 for the same pattern argument. - A body changes everything, in the probed shapes: the same pattern argument in an ordinary function definition compiled and ran, and in a trait method declaration it drew E0642, not E0130 - check which code you have.
- On the other side of the line there is no error, in the probed shapes: plain names, the wildcard, an empty argument list, a foreign static, and a variadic declaration all compile and run.
Sources
- Rust error codes index, E0130 - a pattern was declared as an argument in a foreign function declaration; the erroneous example is
fn foo((a, b): (u32, u32));inside anextern "C"block, and the fix is to replace the pattern argument with a regular one - a struct argument (fn foo(s: SomeStruct);) or a named tuple argument (fn foo(a: (u32, u32));). - Rust error codes index, E0642 - trait methods currently cannot take patterns as arguments; the neighboring code drawn in the probed shape by the same pattern argument in a trait method declaration, with the same remedy of a single name for the argument.
- Rust error codes index, E0425 - an unresolved name was used; the neighboring code drawn in the probed shape by an unresolved name in a program that also carried a pattern argument.
- The Rust Reference, External blocks - external blocks provide declarations of items not defined in the current crate; functions within external blocks are declared like other Rust functions except that they must not have a body, and patterns are not allowed in parameters - only an identifier or
_may be used; two kinds of item declarations are allowed in external blocks, functions and statics.
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.