Skip to content

Error messages wrt. patterns named the same as a type could be better #49145

Closed
@Centril

Description

@Centril

Given:

struct f; fn main() { let f = 1; }

a rust compiler (playground, stable) will error with:

error[E0308]: mismatched types
 --> src/main.rs:1:27
  |
1 | struct f; fn main() { let f = 1; }
  |                           ^ expected integral variable, found struct `f`
  |
  = note: expected type `{integer}`
             found type `f`

this is morally right; but the error message could highlight the fact that the user most likely confused the pattern f (as in the equivalent unit struct pattern f {}) with a variable binding f.

Tho, the names coinciding is somewhat pathological, so it might not warrant special care; but perhaps it does?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-feature-requestCategory: A feature request, i.e: not implemented / a PR.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions