Skip to content

Slightly improve no return for returning function error #100607

Closed
@Rageking8

Description

@Rageking8

Given the following code: link

fn func() -> i32 {
    123;
}

fn main() {
    
}

The current output is:

Compiling playground v0.0.1 (/playground)
error[[E0308]](https://doc.rust-lang.org/nightly/error-index.html#E0308): mismatched types
 --> src/main.rs:1:14
  |
1 | fn func() -> i32 {
  |    ----      ^^^ expected `i32`, found `()`
  |    |
  |    implicitly returns `()` as its body has no tail or `return` expression
2 |     123;
  |        - help: remove this semicolon

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` due to previous error

Ideally the output should look like have a small note directly behind "- help: remove this semicolon" that says " for implicit return". As I have witness a beginner getting confused as to why certain lines of code in a function require semicolon but not others. (The added note wording might need further amendments).

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-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