E0277: suggest dereferencing function arguments in more cases #133292
+206
−113
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This unifies and generalizes some of the logic in
TypeErrCtxt::suggest_dereferences
so that it will suggest dereferencing arguments to function/method calls in order to satisfy trait bounds in more cases.Previously it would only fire on reference types, and it had two separate cases (one specifically to get through custom
Deref
impls when passing by-reference, and one specifically to catch #87437). I've based the new checks loosely on what's done forE0308
inFnCtxt::suggest_deref_or_ref
: it will suggest dereferences to satisfy trait bounds whenever the referent isCopy
, is boxed (& so can be moved out of the boxes), or is being passed by reference.This doesn't make the suggestion fire in contexts other than function arguments or binary operators (which are in a separate case that this doesn't touch), and doesn't make it suggest a combination of
&
-removal and dereferences. Those would require a bit more restructuring, so I figured just doing this would be a decent first step.Closes #90997