Rust errors / Types and traits
Rust compiler error · checked with rustc 1.99.0
Rust error E0580: `main` function has wrong type
What it meansThe main function was incorrectly declared.
What rustc prints
error[E0580]: `main` function has wrong type --> main.rs:1:1 | 1 | fn main(x: i32) { // error: main function has wrong type | ^^^^^^^^^^^^^^^ incorrect number of function parameters | = note: expected signature `fn()` found signature `fn(i32)`
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
The main function was incorrectly declared.
Erroneous code example:
fn main(x: i32) { // error: main function has wrong type
println!("{}", x);
}
The main function prototype should never take arguments. Example:
fn main() {
// your code
}
If you want to get command-line arguments, use std::env::args. To exit with a specified exit code, use std::process::exit.
From rustc --explain E0580 (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
- E0576cannot find associated type `You` in trait `Hello`
- E0579lower bound for range pattern must be less than upper bound
- E0587type has conflicting packed and align representation hints
- E0588packed type cannot transitively contain a `#[repr(align)]` type
Up next
Often hit nextE0308: mismatched typesA related error from the same family.Read it next →Did this answer your question?