Closed
Description
Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6ad29d6923c9ffe687e2a08669a03101
fn main() {
let x: i8 = loop { 10 };
}
The current output is:
Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
--> src/main.rs:2:24
|
2 | let x: i8 = loop { 10 };
| ^^ expected `()`, found integer
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground`
To learn more, run the command again with --verbose.
Ideally the output should look like:
Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
--> src/main.rs:2:24
|
2 | let x: i8 = loop { 10 };
| ^^^
| | |
| | expected `()`, found integer
| help: consider adding `break` here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground`
To learn more, run the command again with --verbose.
It may not be immediately clear to a user why implicit-return/break style works for if
expressions, but not for loop
. Adding a hint to explicitly break with break value;
would be helpful.