Skip to content

Not dealing with return type #19858

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

Open
daniel-pfeiffer opened this issue May 24, 2025 · 4 comments
Open

Not dealing with return type #19858

daniel-pfeiffer opened this issue May 24, 2025 · 4 comments
Labels
A-diagnostics diagnostics / error reporting A-parser parser issues C-bug Category: bug

Comments

@daniel-pfeiffer
Copy link

daniel-pfeiffer commented May 24, 2025

rust-analyzer version: 0.4.2470-standalone

rustc version: 1.87.0 (17067e9ac 2025-05-09)

editor or extension: VSCode 1.100.2

I guess this problem is partly between RA and compiler and partly between RA and VSCode. I had reported it on irlo compiler, but they point me to you.

Rustlings functions4.rs made me notice several things.

This (both for return spec - or ->) gives an unrusty, very terse error message with no suggestion:

fn sale_price(price: i64) -> {
    if is_even(price) {
        price - 10
    } else {
        price - 3
    }
}
Syntax Error: expected type rust-analyzer(syntax-error)

Removing the arrow dramatically improves the message:

error[E0308]: mismatched types
  --> exercises/02_functions/functions4.rs:13:9
   |
11 | fn sale_price(price: i64) {
   |                          - help: try adding a return type: `-> i64`
12 |     if is_even(price) {
13 |         price - 10
   |         ^^^^^^^^^^ expected `()`, found `i64`

I see that one is syntax and the other logic, but from user’s perspective it’s pretty much the same error. In both cases VScode doesn’t suggest the obvious quick fix.

@daniel-pfeiffer daniel-pfeiffer added the C-bug Category: bug label May 24, 2025
@ChayimFriedman2
Copy link
Contributor

The first error is from rust-analyzer and the second from rustc. r-a's error messages are not great in general, especially compared to rustc's.

@daniel-pfeiffer
Copy link
Author

Thanks for the clarification! I hope the RA messages can be gradually be brought up to par!

And even though the 2nd is very clear and helpful, VScode doesn’t see that. I’ve no clue if they parse most messages, except this one. Or does RA need to give meta-data and hasn’t gotten round to providing it in this case? Rhetorical question, just hoping this will be fixed – especially as it’s from Rustlings, i.e. beginners face this!

@ChayimFriedman2
Copy link
Contributor

And even though the 2nd is very clear and helpful, VScode doesn’t see that. I’ve no clue if they parse most messages, except this one. Or does RA need to give meta-data and hasn’t gotten round to providing it in this case? Rhetorical question, just hoping this will be fixed – especially as it’s from Rustlings, i.e. beginners face this!

It's probably spread across places in the code, i.e. parts of the error are shown in different places.

@Veykril
Copy link
Member

Veykril commented May 26, 2025

The main issue is with rendering the nice error diagnostics from rustc in VSCode, which is quite difficult as VSCode's user facing error machinery is pretty weak.

As for r-a's error here, we should report expected type, found {`` like rustc does instead of just expected type. But as Chayim said, our parse error infra is pretty weak overall.

@Veykril Veykril added A-parser parser issues A-diagnostics diagnostics / error reporting labels May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics diagnostics / error reporting A-parser parser issues C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants