Improve the error message of typos on variables that has the same name as struct fields #97133
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
If a method's arguments have a name close to a struct field and we use the field name by mistake when trying to refer to the variable, the message is not very helpful. This should be more common inside
new
methods.Given the following code: playground
The current output is:
Compare the
new
error message to a free-function-stylenew
:Ideally, the output of the
new
should look like this:Is quite not there yet, but is much more helpful as it points to a typo I didn't know I have. In this case, we could either the message pointing to me that I should write
Foo { config: cofig }
, or, ideally, pointing thatcofig
may be a typo toconfig
.The second case (
do_something
), is more complicated as It's not clear whethercofig
is related toconfig
or not.Sorry if this is duplication, I couldn't find a similar issue 😅 .
The text was updated successfully, but these errors were encountered: