Avoid 'not found' terminology when there is only one potentially applicable method. #76267
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-confusing
Diagnostics: Confusing error or lint that should be reworked.
The following code:
gives the following error:
If we change the call to
my_fn()
to call some completely nonexistent method (e.g.missing_method()
), we get the following error.These two error messages are quite similar - however, they really mean two completely different things. The first error is due to a trait bound error - there's only one in-scope method that the user could possibly be trying to call, but the receiver is not valid. The second error is caused by there being no methods that could even possibly apply - other than suggesting similarly-named methods or additional trait imports, there's really nothing else for the error message to say.
I think using the 'no method found' terminology is the first case is very misleading. It requires the user to read further into the error message to determine if the receiver is invalid, or if they made a typo/tried to call a method that was removed in a newer release of a crate.
I propose that we move the "method
foo
exists but ..." note to become the main error message. In the case of multiple possibilities, we could say something like "cannot call methodfoo
on base typebar
due to ...".The text was updated successfully, but these errors were encountered: