Skip to content

Error message for "expression ascription" does not highlight the entire expression #43703

Closed
@Ixrec

Description

@Ixrec

This came up in #rust today and I couldn't find any similar A-diagnostics issues. A simple example is:

use std::vec::Vec;
fn main() {
    let x: Vec::with_capacity(10);
}

This correctly fails with a compiler error, since it's using : for type ascription where it meant to use = for initialization. But our current error message makes it sound like the problem is near 10, instead of near the :.

error: expected type, found `10`
 --> src/main.rs:4:31
  |
4 |     let x: Vec::with_capacity(10);
  |                               ^^

error: expected one of `!`, `+`, `->`, `::`, `;`, or `=`, found `)`
 --> src/main.rs:4:33
  |
4 |     let x: Vec::with_capacity(10);
  |                                 ^ expected one of `!`, `+`, `->`, `::`, `;`, or `=` here

error: aborting due to previous error(s)

Ideally the message would be "expected type, found Vec::with_capacity(10)".

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions