E0277 error is confusing when compile fails using the last implementor for a trait #56368
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
D-confusing
Diagnostics: Confusing error or lint that should be reworked.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Description
This is a followup of forum post [Solved] Need help understanding compilation error with str.contains / String / Pattern.
Here's a function that compiles:
But if I omit passing a reference to
contains
and pass the actualString
:, then compilation fails with error
In this context, as a babbling Rustacean, I had zarroo idea of what rustc was trying to tell me and, assuming the solution (which I found by looking up a
.contains()
example in the Rust book, where a&
reference was used), my incorrect concluding puzzlement was:String
isn't astd::ops::FnMut<(char,)>
, but a reference to aString
is?String
s?As pointed by forum user
krdln
, what's happening is that, as documented by str.contains, I should have passed a Pattern, whose 6 implementors are:, so rustc's logic behind the error message was:
Proposal
When rustc fails to compile using the last (fallback? generic?) implementor for a trait,
The updated, friendlier error message could look something like that:
Note: hope the proposal makes sense, or at least you get the intention! I have no idea what I'm doing! This is my first Rust bug! I haven't even finished the Rust book! One last exclamation mark for the road!
The text was updated successfully, but these errors were encountered: