Skip to content

"main function is not allowed to have generic parameters" when the parameter is a reference #118772

Closed
@wyattscarpenter

Description

@wyattscarpenter

Code

fn main(hmm: &i32) {
  println!("Hello, world!");
}

Current output

error[E0131]: `main` function is not allowed to have generic parameters
  --> src\bin\8.rs:22:8
   |
22 | fn main(hmm: &i32) {
   |        ^ `main` cannot have generic parameters

For more information about this error, try `rustc --explain E0131`.

Desired output

error[E0580]: `main` function has wrong type
  --> src\bin\8.rs:22:1
   |
22 | fn main(hmm: i32) {
   | ^^^^^^^^^^^^^^^^^ incorrect number of function parameters
   |
   = note: expected signature `fn()`
              found signature `fn(i32)`

For more information about this error, try `rustc --explain E0580`.

Rationale and extra context

It is less clear to display the E0131 message for the situation, because it it's about generic parameters. Eg to quote from rustc --explain E0131:

fn main() { // error: main function is not allowed to have generic parameters

Whereas rustc --explain E0580 explains:

The main function prototype should never take arguments.

Other cases

No response

Anything else?

Additionally, neither error is output when the command run is cargo test; which is probably erroneous behavior, as check, clippy, build, and run.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions