help text for Send
trait bound mismatch is misleading
#69983
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
D-invalid-suggestion
Diagnostics: A structured suggestion resulting in incorrect code.
P-medium
Medium priority
regression-from-stable-to-beta
Performance or correctness regression from stable to beta.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
This is a small issue but it cost me a fair bit of time and I thought an improvement here could help other new users.
Summary: when a caller tries to invoke a function with a trait bound that includes
Send
, but the caller's value is notSend
, the error message says:The problem here isn't (necessarily) that
T
cannot be sent between threads safely, but more precisely that the function expectedT: Send
and got plainT
.It might not be obvious how this can be so misleading, but as a relatively new user, I thought Rust was telling me that something in my code was trying to send a value between threads and additionally that the value actually couldn't be sent between threads safely. Often times neither of those was the case. You can easily generate this error with single-threaded code and concrete types that all implement
Send
. In my case, often I'd forgotten to putSend
on a trait bounds of the caller, or I'd erroneously putSend
on a trait bound of the callee. Really, this error is just a simple trait bound mismatch. Just from my experience, it looks like this message is special-cased forSend
in order to provide more useful information for someone who might not be familiar withSend
-- which is great. I think that information probably belongs in a "note" though, and the error should be precise about what actually happened instead of inferring too much (incorrectly, in some cases).For trait bound mismatches involving types other than
Send
, the message is more precise:Here's that example in the playground. The error message is:
which is pretty clear and precise about the problem. Here's a similar example where the trait bound is
Send
:Here's that one on the playground.
Now the error message is:
This is the same error code (E0277) and the "help" text is right but the summary message isn't.
The text was updated successfully, but these errors were encountered: