Skip to content

Not dealing with return type #19858

Open
Open
@daniel-pfeiffer

Description

@daniel-pfeiffer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsdiagnostics / error reportingA-parserparser issuesC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions