Skip to content

Better account for invalid async fn main() {} #78905

Closed

Description

@estebank

The following

async fn main() {
}

produces a lot of output that is not quite good:

error[E0277]: `main` has invalid return type `impl Future`
 --> src/main.rs:1:17
  |
1 | async fn main() {
  |                 ^ `main` can only return types that implement `Termination`
  |
  = help: consider using `()`, or a `Result`

error[E0752]: `main` function is not allowed to be `async`
 --> src/main.rs:1:1
  |
1 | async fn main() {
  | ^^^^^^^^^^^^^^^ `main` function is not allowed to be `async`

The two errors (E0277 and E0752) should be only a single error.

(Taken from a subset of https://users.rust-lang.org/t/how-can-we-return-a-anonymous-type-in-result-trait/51258)

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.
    on Nov 9, 2020
  2. veera-sivarajan commented on Jul 26, 2024

    @veera-sivarajan
    Contributor

    Output on rustc 1.80.0:

    error[E0752]: `main` function is not allowed to be `async`
     --> projects/rust/test.rs:5:1
      |
    5 | async fn main() {
      | ^^^^^^^^^^^^^^^ `main` function is not allowed to be `async`
    
    error: aborting due to 1 previous error
    
    For more information about this error, try `rustc --explain E0752`.
    
  3. Enselic commented on Mar 26, 2026

    @Enselic
    Member

    The two errors (E0277 and E0752) should be only a single error.

    Output on rustc 1.80.0:

    Triage: Since the expected behavior is now in place, we can close this issue now, right?

  4. added
    S-candidate-for-closingStatus: This issue will be closed after a week or so unless objections are raised.
    on Mar 26, 2026
  5. Enselic commented on Jul 16, 2026

    @Enselic
    Member

    Triage: Looks like we don't have a test for this, so we just need to add a test.

  6. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    and removed
    S-candidate-for-closingStatus: This issue will be closed after a week or so unless objections are raised.
    on Jul 16, 2026
  7. konard commented on Jul 21, 2026

    @konard

    @rustbot claim

  8. added a commit that references this issue on Sep 11, 2026
    2eaa601
  9. added a commit that references this issue on Sep 11, 2026
    093ca2c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-verboseDiagnostics: Too much output caused by a single piece of incorrect code.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.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