-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Improve output of type mismatch due to lack of return value #50009
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
Comments
Alternative output
|
I'm not sure if it has the same root cause, but there's a similar issue with fn foo() -> usize {
loop {
break;
}
}
I assume the error message points at the |
This issue is the biggest annoyance I have when using RLS to write Rust code in VSCode, as it causes the entire function to get highlighted as an error, which is very unhelpful. I've started having to adopt a style where I put a dummy statement at the end of the function before writing anything else just to suppress the error while I write the rest of the function, but it's rather annoying to deal with. |
Modify mismatched type error for functions with no return Fix #50009. ``` error[E0308]: mismatched types --> $DIR/coercion-missing-tail-expected-type.rs:3:24 | LL | fn plus_one(x: i32) -> i32 { //~ ERROR mismatched types | -------- ^^^ expected i32, found () | | | this function's body doesn't return LL | x + 1; | - help: consider removing this semicolon | = note: expected type `i32` found type `()` ``` instead of ``` error[E0308]: mismatched types --> $DIR/coercion-missing-tail-expected-type.rs:3:28 | LL | fn plus_one(x: i32) -> i32 { //~ ERROR mismatched types | ____________________________^ LL | | x + 1; | | - help: consider removing this semicolon LL | | } | |_^ expected i32, found () | = note: expected type `i32` found type `()` ```
When you have
the diagnostic correctly points at the return value
while if the error is due to not having a return value
the output is
It probably should be
The text was updated successfully, but these errors were encountered: