Rust errors / Types and traits
Rust compiler error · checked with rustc 1.99.0
Rust error E0044: foreign items may not have type parameters
What it meansYou cannot use type or const parameters on foreign items.
What rustc prints
error[E0044]: foreign items may not have type parameters --> main.rs:1:14 | 1 | extern "C" { fn some_func<T>(x: T); } | ^^^^^^^^^^^^^^^^^^^^^^ can't have type parameters | = help: replace the type parameters with concrete types like `u32`
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
You cannot use type or const parameters on foreign items.
Example of erroneous code:
extern "C" { fn some_func<T>(x: T); }
To fix this, replace the generic parameter with the specializations that you need:
extern "C" { fn some_func_i32(x: i32); }
extern "C" { fn some_func_i64(x: i64); }From rustc --explain E0044 (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
- E0033A trait type has been dereferenced
- E0038For any given trait `Trait` there may be a related _type_ called the _trait object type_ which is typically written as `dyn Trait`. In earlier editions of Rust, trait object types were written as plain `Trait` (just the name of the trait, written in type positions) but this was a bit too confusing, so we now write `dyn Trait`
- E0046not all trait items implemented, missing: `foo`
- E0049associated function `foo` has 0 type parameters but its trait declaration has 1 type parameter
Up next
Often hit nextE0308: mismatched typesA related error from the same family.Read it next →Did this answer your question?