Description
I've answered a question like this every day for the past 3 days... https://users.rust-lang.org/t/how-to-create-a-new-option-serde-json-value-value/15466
The problem is with code like this:
struct foo;
let foo = 1;
Typically the let binding and the struct definition are much more separated, and the struct definition comes from a glob import. The error received is:
error[E0308]: mismatched types
--> src/main.rs:4:9
|
4 | let foo = 1;
| ^^^ expected integral variable, found struct `main::foo`
|
= note: expected type `{integer}`
found type `main::foo`
This error isn't wrong, and I'm not even proposing that we remove it. However, in the specific case where the match is on a unit struct, I do think it would be incredibly helpful to add a help
diagnostic pointing at the span where foo
was brought into scope, stating that a struct with zero fields named foo
was imported. E.g.
--> src/main.rs:2:4
|
2 | struct foo;
| ^^^^^^^^^^ note: A struct named `foo` with zero fields was brought into scope here.
|
I have purposely biased this error message towards use
vs definition, because I think the overwhelmingly common case is going to be from use
not definition (though the error is still reasonable when pointing at the definition).
I'd be happy to implement this if it'd be accepted, though I think I'll probably need a bit of help.