Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slightly improve no return for returning function error #100607

Closed
Rageking8 opened this issue Aug 16, 2022 · 1 comment · Fixed by #102650
Closed

Slightly improve no return for returning function error #100607

Rageking8 opened this issue Aug 16, 2022 · 1 comment · Fixed by #102650
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Rageking8
Copy link
Contributor

Rageking8 commented Aug 16, 2022

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).

@Rageking8 Rageking8 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 16, 2022
@reez12g
Copy link
Contributor

reez12g commented Aug 16, 2022

@rustbot claim

notriddle added a commit to notriddle/rust that referenced this issue Oct 5, 2022
…rn-for-returning-function-error, r=compiler-errors

Slightly improve no return for returning function error

Fixes rust-lang#100607

The rationale is that absolute beginners will be slightly confused as to why certain lines of code in a function does not require a semicolon. (I have actually witness a beginner having this confusion). Hence, a slight rationale is added "to return this value", which signals to the user that after removing said semicolon the value is returned resolving that error.

However, if this is not desirable, I welcome any other suggestions. Thanks.
@bors bors closed this as completed in 55ebb61 Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
2 participants