Skip to content

Functions and closures with incorrect return types should have better diagnostics #41897

@Mark-Simulacrum

Description

@Mark-Simulacrum
Member

We should do better on the diagnostic in this case, since presumably the author of the code meant to return the 10, so we should suggest that the function needs a return type, somewhat as we currently give the "remove ;" suggestion.

fn foo() {
   10
}
error[E0308]: mismatched types
 --> test.rs:2:5
  |
2 |     10
  |     ^^ expected (), found integral variable
  |
  = note: expected type `()`
             found type `{integer}`

error: aborting due to previous error

Filing this to close out #35478, #21838, #22216, #18595 as duplicates of this.

Activity

estebank

estebank commented on May 17, 2017

@estebank
Contributor

Previous stab at this: #39231.

estebank

estebank commented on Jul 26, 2017

@estebank
Contributor

We do this now.

added a commit that references this issue on Jul 26, 2017
d96f9d4
added a commit that references this issue on Aug 9, 2017
f142499
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @estebank@Mark-Simulacrum

      Issue actions

        Functions and closures with incorrect return types should have better diagnostics · Issue #41897 · rust-lang/rust