Hi folks, I'm working on improving the error message for E0308. In this post, I'm hoping I can get some feedback on the wording I'm working on. I'm a new contributor to Rust, and I'm nervous about changing the error message so many will see when editing their code.
It's the error message when two different types seem to be assigned to the same variable. (Which doesn't work in a static language as I understand it. I'm a bit of a perpetual beginner to programming...)
I thought the old message was a bit wordy and intimidating, but that it could be communicated in a clearer way without losing any accuracy.
I just did this PR that got merged: Improve E0308 error message wording by DeeDeeG · Pull Request #70242 · rust-lang/rust · GitHub
But I'm still a bit unsatisfied with how it turned out.
(I don't want to change the code snippet in the error message, because I think it's good. I'm focused only on the wording of the message.)
Here's my latest draft:
This error occurs when the compiler was unable to infer the concrete type of a variable. It can occur for several cases; The most common case is a mismatch between two types: the type explicitly assigned to a variable by the [code's] author, and the type the compiler infers for an expression assigned to that variable.
I'm not sure about the phrase "the code's author" being maybe too verbose... and I'm not sure if I want to add this at the end of the last sentence:
assigned to that variable [later on].
Or:
for an expression [to be assigned] to that variable.
I also want to add a "hint" sentence on to the end, explaining that this error exists due to Rust being a statically-typed language. This error seemed like a pretty foreign concept to me when I first saw it, because I'm used to dynamic typing. I have taken a few approaches to wording this, and I'm not sure which I prefer.
No variable may have more than one type during the same program, as Rust is statically typed.
A single variable may not have more than one type during the same program, as Rust is statically typed.
A single variable may not have more than one type, as Rust is a statically typed language.
A variable may not take on a second type after it has been initialized with a first type. (Rust is a statically typed language.)
Can anyone give me their thoughts on this? Suggested improved wording? Can you confirm my wording choices are accurate? Is it okay I took out the concept of "initialization," from the main error text, or would most programmers get better information with that included?
Thanks for any feedback.
Also: I'm interested in starting up an effort to improve the existing error messages and docs, and sort of set an example of clear yet approachable language around the Rust language. If anyone has ideas on how to do this or wants to join in, feel free to get in touch.