Rust
Type Parameters on Foreign Items E0044 Fix
An extern block declares code that already exists somewhere else: a symbol in a library, with one fixed signature. There is no foreign body for the compiler to specialize, so a foreign function cannot take a type parameter or a const parameter - the declaration itself draws E0044. Lifetimes are the exception: they describe borrows rather than generating code, and a foreign function may name them. The fix is to declare what the foreign side actually exports: one declaration per concrete type, a generic wrapper written in Rust over a concrete declaration, or a concrete pointer-based signature. This guide shows each generic shape failing, the neighboring mistakes that draw different errors, the shapes that compile and run, and the repairs running.
Written December 2, 2026 · Tested with Rust 1.99.0 · 19 min read
- The rule underneath: a declaration cannot be specialized
- How to read the diagnostic
- The first failure: the index example
- Every generic foreign function shape draws the same code
Written December 2, 2026
Tested with Rust 1.99.0
What this guide is
Error E0044 means a foreign item was given type parameters. The error codes index puts it in one line: "You cannot use type or const parameters on foreign items."
A foreign item is any item declared inside an extern block: a function, a static, or a type that lives in another library and is only declared in Rust, never defined. The boundary around the code is the interesting part. Type parameters and const parameters on a foreign function draw E0044, in every block flavor. The same idea aimed at a foreign static or a foreign type fails earlier and without this code, and lifetime parameters - which look like the same syntax - are allowed on foreign functions. This guide shows each case with its actual code.
Build every program in this guide with rustc --edition 2021. The programs that call foreign functions link against a small library that exports the named symbols, so the declarations below resolve to real code when the programs run. In the compiler transcripts, the file names are the bare names shown on the command line.
The rule underneath: a declaration cannot be specialized
A generic Rust function is a template: the compiler generates one concrete version for each type it is called with, a process called monomorphization. That works because the compiler has the body. A foreign function has no body in Rust - the extern block is a promise that a symbol with exactly that name and signature already exists in the linked library. There is nothing to generate versions of, and a C library does not contain one symbol per Rust type. So the declaration has to name concrete types from the start.
The same reasoning covers const parameters: a foreign function cannot vary by a compile-time constant either, because the foreign symbol is still a single fixed entry point. Lifetimes escape the ban for a different reason: a lifetime parameter generates no code and changes no calling convention - it only records, for the borrow checker, how the references in the signature relate. The sections below show a lifetime-parameter foreign function compiling and running next to the type-parameter shapes failing.
How to read the diagnostic
The header is "foreign items may not have type parameters", and the span covers the whole foreign function, labeled "can't have type parameters". The help line states the repair directly: "replace the type parameters with concrete types like u32". For a const parameter the wording shifts - "may not have const parameters", "can't have const parameters", and "replace the const parameters with concrete consts" - but the code is the same E0044. With a type parameter and a const parameter on the same function, the wording combines - "may not have type or const parameters", "can't have type or const parameters", and "replace the type or const parameters with concrete types or consts" - still the same E0044.
One reading trap matters: when a generic shape draws an uncoded error instead, as foreign statics and foreign types do below, the absence of E0044 does not mean the shape is closer to legal. It means a different check fired first.
The first failure: the index example
The index's erroneous example, verbatim:
#![allow(unused)]
fn main() {
extern "C" { fn some_func<T>(x: T); }
}
error[E0044]: foreign items may not have type parameters
--> fail_index.rs:5:14
|
5 | extern "C" { fn some_func<T>(x: T); }
| ^^^^^^^^^^^^^^^^^^^^^^ can't have type parameters
|
= help: replace the type parameters with concrete types like `u32`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0044`.
The example is a single generic foreign function, and it draws exactly one E0044 - no second code hides in it. The index's corrected form declares one function per concrete type, some_func_i32 and some_func_i64, and that repair is shown running in the repairs below.
Every generic foreign function shape draws the same code
More parameters change nothing. Two type parameters, one for the argument and one for the return value, fail as one error:
extern "C" {
fn convert<T, U>(x: T) -> U;
}
fn main() {}
error[E0044]: foreign items may not have type parameters
--> fail_generic_fn_multi.rs:2:5
|
2 | fn convert<T, U>(x: T) -> U;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't have type parameters
|
= help: replace the type parameters with concrete types like `u32`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0044`.
A trait bound does not rescue the parameter. The foreign side cannot check a Rust trait, and the declaration fails before the bound matters:
extern "C" {
fn show<T: Clone>(x: T);
}
fn main() {}
error[E0044]: foreign items may not have type parameters
--> fail_generic_fn_bound.rs:2:5
|
2 | fn show<T: Clone>(x: T);
| ^^^^^^^^^^^^^^^^^^^^^^^^ can't have type parameters
|
= help: replace the type parameters with concrete types like `u32`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0044`.
A where clause is the same parameter written in the other position, and it draws the same code with the span stretched over the whole declaration:
extern "C" {
fn show<T>(x: T)
where
T: Clone;
}
fn main() {}
error[E0044]: foreign items may not have type parameters
--> fail_where_clause.rs:2:5
|
2 | / fn show<T>(x: T)
3 | | where
4 | | T: Clone;
| |_________________^ can't have type parameters
|
= help: replace the type parameters with concrete types like `u32`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0044`.
A const parameter draws E0044 with its own wording. The header and the help both say "const parameters" and "concrete consts":
extern "C" {
fn fill<const N: usize>(buf: [u8; N]);
}
fn main() {}
error[E0044]: foreign items may not have const parameters
--> fail_generic_fn_const.rs:2:5
|
2 | fn fill<const N: usize>(buf: [u8; N]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't have const parameters
|
= help: replace the const parameters with concrete consts
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0044`.
The block flavor changes nothing. An unsafe extern block - the form newer Rust prefers - rejects the generic declaration identically:
unsafe extern "C" {
fn some_func<T>(x: T);
}
fn main() {}
error[E0044]: foreign items may not have type parameters
--> fail_unsafe_extern_generic.rs:2:5
|
2 | fn some_func<T>(x: T);
| ^^^^^^^^^^^^^^^^^^^^^^ can't have type parameters
|
= help: replace the type parameters with concrete types like `u32`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0044`.
And an extern block with no ABI draws E0044 on top of its own deprecation warning about the missing ABI. The warning is about the block; the error is about the parameter:
extern {
fn some_func<T>(x: T);
}
fn main() {}
warning: `extern` declarations without an explicit ABI are deprecated
--> fail_extern_no_abi_generic.rs:1:1
|
1 | extern {
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"`
|
= note: `#[warn(missing_abi)]` on by default
error[E0044]: foreign items may not have type parameters
--> fail_extern_no_abi_generic.rs:2:5
|
2 | fn some_func<T>(x: T);
| ^^^^^^^^^^^^^^^^^^^^^^ can't have type parameters
|
= help: replace the type parameters with concrete types like `u32`
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0044`.
Plain, bounded, multi-parameter, const-parameter, where-clause, unsafe extern, no ABI: a type or const parameter on a foreign function is the whole defect, and E0044 is always the code.
The shape that is not this error: a generic foreign static
A static with a type parameter never reaches the E0044 check. It fails with an uncoded error - "static items may not have generic parameters" - and then a second error because the parameter it could not declare is not in scope for the static's type:
extern "C" {
static COUNTER<T>: T;
}
fn main() {}
error: static items may not have generic parameters
--> fail_generic_static.rs:2:19
|
2 | static COUNTER<T>: T;
| ^^^
error[E0425]: cannot find type `T` in this scope
--> fail_generic_static.rs:2:24
|
2 | static COUNTER<T>: T;
| ^ not found in this scope
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0425`.
The fix is the same in spirit - a foreign static names one concrete type - but the code to search for is not E0044, and the second error, E0425, is a consequence of the first rather than a separate mistake.
The shapes that are not this error: generic foreign types
A foreign type with a type parameter draws an uncoded error that names the repair - "help: remove the generic parameters" - plus E0658, because foreign types themselves are still experimental on stable Rust:
extern "C" {
type Handle<T>;
}
fn main() {}
error: `type`s inside `extern` blocks cannot have generic parameters
--> fail_generic_type.rs:2:16
|
1 | extern "C" {
| ---------- `extern` block begins here
2 | type Handle<T>;
| ^^^ help: remove the generic parameters
|
= note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
error[E0658]: extern types are experimental
--> fail_generic_type.rs:2:5
|
2 | type Handle<T>;
| ^^^^^^^^^^^^^^^
|
= note: see issue #43467 <https://github.com/rust-lang/rust/issues/43467> for more information
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0658`.
A lifetime parameter on a foreign type lands in the same place. Unlike on a function, a lifetime here is treated as a generic parameter of the type, and both errors repeat:
extern "C" {
type Shared<'a>;
}
fn main() {}
error: `type`s inside `extern` blocks cannot have generic parameters
--> fail_lifetime_type.rs:2:16
|
1 | extern "C" {
| ---------- `extern` block begins here
2 | type Shared<'a>;
| ^^^^ help: remove the generic parameters
|
= note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
error[E0658]: extern types are experimental
--> fail_lifetime_type.rs:2:5
|
2 | type Shared<'a>;
| ^^^^^^^^^^^^^^^^
|
= note: see issue #43467 <https://github.com/rust-lang/rust/issues/43467> for more information
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0658`.
Two separate facts are stacked in these transcripts: foreign types may not have generic parameters of any kind, and on stable Rust a foreign type may not be declared at all. The second fact gets its own section below, because it also applies to the non-generic declaration.
What does work: lifetime parameters on a foreign function
A lifetime parameter on a foreign function compiles. The declaration below is never called, so the compiler warns that it is unused - a warning, not an error - and emits no E0044:
extern "C" {
fn first<'a>(x: &'a i32, y: &'a i32) -> &'a i32;
}
fn main() {}
warning: function `first` is never used
--> fail_lifetime_fn.rs:2:8
|
2 | fn first<'a>(x: &'a i32, y: &'a i32) -> &'a i32;
| ^^^^^
|
= note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default
warning: 1 warning emitted
Called, it runs. This declaration names a lifetime parameter and relates the return reference to the argument references, and the program prints the first argument's value:
extern "C" {
fn ffi_first_ref<'a>(x: &'a i32, y: &'a i32) -> &'a i32;
}
fn main() {
let a = 4;
let b = 9;
let picked = unsafe { ffi_first_ref(&a, &b) };
println!("{}", picked);
}
4
The asymmetry is the rule: type and const parameters would have to generate code or change the symbol, so they are banned; a lifetime only constrains borrows at the call site, so it is allowed on the item where borrows can appear - a function signature. Lifetimes written inside argument types without an explicit parameter, the ordinary elided form, are of course fine as well.
What does work: a plain foreign function and static
With concrete types, the plain declarations compile, link, and run. The function returns its argument and the static holds its value:
extern "C" {
fn ffi_identity_i32(x: i32) -> i32;
static FFI_COUNTER: i32;
}
fn main() {
let value = unsafe { ffi_identity_i32(7) };
let counter = unsafe { FFI_COUNTER };
println!("{} {}", value, counter);
}
7 42
An unsafe extern block with concrete types is equally legal - the unsafe on the block changes who vouches for the declarations, not what may be declared:
unsafe extern "C" {
fn ffi_add_i32(a: i32, b: i32) -> i32;
}
fn main() {
let total = unsafe { ffi_add_i32(2, 3) };
println!("{}", total);
}
5
A variadic foreign function - one ending in ... - is also a concrete declaration and compiles the same way; the C side, not the Rust declaration, decides how many arguments a call passes. This declaration is never called, so it draws only the unused warning:
extern "C" {
fn ffi_sum_bytes(ptr: *const u8, len: usize, ...) -> i32;
}
fn main() {}
warning: function `ffi_sum_bytes` is never used
--> ok_variadic_decl.rs:2:8
|
2 | fn ffi_sum_bytes(ptr: *const u8, len: usize, ...) -> i32;
| ^^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default
warning: 1 warning emitted
Nothing in the concrete forms needs a parameter to be useful.
Neighboring codes: E0658, the function with a body, and E0049
Three mistakes sit next to E0044 around extern blocks and generic counts, and each keeps its own error.
A foreign type at all, on stable Rust - E0658. Removing the generic parameters from the foreign type above does not make it compile; the declaration itself is experimental:
extern "C" {
type FfiHandle;
}
fn main() {}
error[E0658]: extern types are experimental
--> ok_foreign_type_plain.rs:2:5
|
2 | type FfiHandle;
| ^^^^^^^^^^^^^^^
|
= note: see issue #43467 <https://github.com/rust-lang/rust/issues/43467> for more information
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0658`.
So on stable Rust the opaque-type job is done with raw pointers instead: declare the handle functions as taking and returning *mut c_void, and let the Rust side treat the pointer as an uninterpreted handle. That form is one of the repairs below.
A function with a body inside an extern block - an uncoded error. An extern block holds declarations only; writing the body the generic version would have needed fails as "incorrect function inside extern block":
extern "C" {
fn some_func(x: i32) -> i32 {
x
}
}
fn main() {}
error: incorrect function inside `extern` block
--> neighbour_fn_with_body.rs:2:8
|
1 | extern "C" {
| ---------- `extern` blocks define existing foreign functions and functions inside of them cannot have a body
2 | fn some_func(x: i32) -> i32 {
| ________^^^^^^^^^________________-
| | |
| | cannot have a body
3 | | x
4 | | }
| |_____- help: remove the invalid body: `;`
|
= help: you might have meant to write a function accessible through FFI, which can be done by writing `extern fn` outside of the `extern` block
= note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
error: aborting due to 1 previous error
The help points at the real distinction: a function you define for foreign callers is written outside the block as an extern fn; a function inside the block is one you are declaring, and declarations have no bodies and no parameters to specialize.
The wrong number of type parameters in a trait implementation - E0049. This is the generic-count mistake that does carry a code near E0044's number, in trait land rather than FFI land. The trait declares a generic method and the implementation omits the parameter:
trait Converter {
fn convert<T>(&self, x: T) -> T;
}
struct Identity;
impl Converter for Identity {
fn convert(&self, x: i32) -> i32 {
x
}
}
fn main() {
let id = Identity;
println!("{}", id.convert(3));
}
error[E0049]: method `convert` has 0 type parameters but its trait declaration has 1 type parameter
--> neighbour_trait_param_mismatch.rs:8:15
|
2 | fn convert<T>(&self, x: T) -> T;
| - expected 1 type parameter
...
8 | fn convert(&self, x: i32) -> i32 {
| ^ found 0 type parameters
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0049`.
E0049 is a mismatch between two Rust declarations the compiler can compare; E0044 is a parameter on a declaration that has no Rust counterpart at all. If the item sits in an extern block, the code is E0044 or one of the uncoded errors above - never E0049.
The repairs
Declare one function per concrete type. This is the index's own repair, and the compiler's help points at it: replace the parameter with the concrete types the foreign library actually exports, one declaration each. Here the two specialized declarations are called with an i32 and an i64:
extern "C" {
fn ffi_identity_i32(x: i32) -> i32;
fn ffi_identity_i64(x: i64) -> i64;
}
fn main() {
unsafe {
println!("{} {}", ffi_identity_i32(3), ffi_identity_i64(4));
}
}
3 4
Each name is a separate foreign symbol, which is exactly what a specialized C library exports. The cost is one declaration per type, paid once at the declaration site instead of at every call.
Move the generics to a Rust-side wrapper. When callers want one generic name, give them a Rust function - which may be generic, because the compiler has its body - over a concrete foreign declaration. The wrapper below accepts anything that converts into i64 and forwards it through the single concrete declaration:
extern "C" {
fn ffi_identity_i64(x: i64) -> i64;
}
fn identity_via_ffi<T: Into<i64>>(x: T) -> i64 {
unsafe { ffi_identity_i64(x.into()) }
}
fn main() {
println!("{} {}", identity_via_ffi(5_i32), identity_via_ffi(6_i64));
}
5 6
The generic surface now lives where monomorphization is possible, and every instantiation funnels into the one foreign symbol. This is the repair to reach for when the set of types is open-ended but they all convert to a type the foreign side speaks.
Erase the type in a concrete signature. A foreign function that takes a pointer and a length speaks for any slice of bytes, whatever the caller's element type was. The Rust side keeps the typed view and passes the erased one across the boundary:
extern "C" {
fn ffi_sum_bytes(ptr: *const u8, len: usize) -> i32;
}
fn sum_via_ffi(data: &[u8]) -> i32 {
unsafe { ffi_sum_bytes(data.as_ptr(), data.len()) }
}
fn main() {
println!("{}", sum_via_ffi(&[1, 2, 3]));
}
6
The declaration is fully concrete - a pointer and a usize - so nothing about it needs a parameter. The caller-side function restores the typed interface, and the sum it prints is computed by the foreign code from the erased arguments.
Carry an opaque handle as a raw void pointer. This is the stable-Rust substitute for the foreign type that drew E0658 above: the foreign side creates and destroys the handle, and Rust only ever holds the pointer:
use std::ffi::c_void;
extern "C" {
fn ffi_new_handle(value: i32) -> *mut c_void;
fn ffi_handle_value(handle: *const c_void) -> i32;
fn ffi_free_handle(handle: *mut c_void);
}
fn main() {
unsafe {
let handle = ffi_new_handle(11);
println!("{}", ffi_handle_value(handle));
ffi_free_handle(handle);
}
}
11
The value printed is read back through the foreign function, so the round trip proves the pointer carried the handle correctly - no foreign type declaration was needed anywhere in it.
Fixes in reach order
First, check the code and the item kind before touching anything. E0044 means a foreign function carries a type or const parameter. A generic foreign static and a generic foreign type draw uncoded errors instead, a plain foreign type on stable Rust draws E0658, a body inside an extern block is an uncoded error, and a generic-count mismatch in a trait implementation is E0049.
Second, read the help line: it already names the repair - replace the type parameters with concrete types, or the const parameters with concrete consts.
Third, if the foreign library exports one symbol per type, declare each of them, with the concrete signatures, exactly as the index's corrected example does.
Fourth, if callers want a generic interface, write it as a Rust-side wrapper over the concrete declarations, or erase the varying type into a pointer, a length, or a raw void pointer in the foreign signature.
Last, leave legal parameter shapes alone: lifetime parameters on a foreign function, and lifetimes inside its argument types, compile and run. Do not strip them while removing the type parameters next to them.
Decision summary
E0044 fired for every type or const parameter on a foreign function: the index example, two type parameters, a trait bound, a where clause, a const parameter (with const wording), an unsafe extern block, and an extern block with no ABI (on top of its missing-ABI warning). It did not fire for a generic foreign static or a generic foreign type, which drew uncoded errors - the static adding E0425 for the undeclared parameter, the type adding E0658 - nor for a lifetime parameter on a foreign type, which drew the same pair, nor for a function with a body inside an extern block, which was an uncoded error, nor for a trait implementation with the wrong number of type parameters, which drew E0049. A foreign type with no parameters at all still drew E0658 on stable Rust. The shapes that compiled and ran were a foreign function with lifetime parameters, a plain foreign function and static, and a non-generic unsafe extern block. The repairs that ran were one specialized declaration per concrete type, a generic Rust-side wrapper over a concrete declaration, type erasure through a pointer-and-length signature, and an opaque handle carried as a raw void pointer.
Checklist
- A foreign function names concrete types only - no type parameters, no const parameters, no bounds, no where clauses.
- The block flavor does not matter:
extern "C",unsafe extern, and a block with no ABI all reject generic foreign functions the same way. - Lifetime parameters on a foreign function are legal; keep them when removing type parameters from the same declaration.
- A generic foreign static or foreign type fails without E0044 - search the uncoded wording. A generic foreign type also draws E0658 behind it; a generic foreign static draws a second error only when the undeclared parameter is actually used (E0425 in the type-use case shown above, E0261 for an undeclared lifetime use, and no second error when the parameter is never used).
- On stable Rust, declare no foreign types at all; carry opaque handles as raw pointers such as
*mut c_void. - Put the generic interface in a Rust wrapper, and keep the foreign declarations it forwards to fully concrete.
Related guides on this site
- Inherent Impl on Foreign Type E0116 Fix
- Main Function Type Parameters E0131 Fix
- E0087 Too Many Type Parameters Fix
- E0091 Unused Type Parameter Fix
Sources
- Rust error codes index, E0044 - you cannot use type or const parameters on foreign items; the erroneous example declares
fn some_func<T>(x: T);in anextern "C"block, and the corrected example replaces it withsome_func_i32andsome_func_i64declarations. - Rust error codes index, E0049 - a method has a different number of type parameters than its trait declaration, the neighboring generic-count code shown in this guide.
- Rust error codes index, E0658 - an unstable feature was used; foreign type declarations draw it on stable Rust, with or without generic parameters.
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.