-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
E0277: suggest dereferencing function arguments in more cases #133292
Conversation
r? @fee1-dead rustbot has assigned @fee1-dead. Use |
// reference, `ty` is `Copy`, or we're moving out of a (potentially nested) `Box`. | ||
let can_deref = is_under_ref.is_some() | ||
|| self.type_is_copy_modulo_regions(obligation.param_env, ty) | ||
|| ty.is_numeric() // for inference vars (presumably but not provably `Copy`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ty.is_numeric()
case is admittedly a hack for tests/ui/traits/suggest-dereferences/suggest-dereferencing-receiver-argument.rs
, since it wants a deref suggestion for an &{integer}
. I think a slightly more principled (still hacky) way to do this could be to walk through base_ty
and add Copy
bounds to the ParamEnv
for any numeric inference vars. It should maybe also downgrade the suggestion to MaybeIncorrect
if any type inference vars are present. {integer}: Sized
does appear to be provable already, at least.
r? compiler |
r? @estebank |
@bors r+ |
…bank E0277: suggest dereferencing function arguments in more cases 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 rust-lang#87437). I've based the new checks loosely on what's done for `E0308` in `FnCtxt::suggest_deref_or_ref`: it will suggest dereferences to satisfy trait bounds whenever the referent is `Copy`, 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 rust-lang#90997
Rollup of 7 pull requests Successful merges: - rust-lang#131439 (Remove allowing static_mut_refs lint) - rust-lang#133292 (E0277: suggest dereferencing function arguments in more cases) - rust-lang#134080 (Avoid use of LFS64 symbols on Emscripten) - rust-lang#134877 (add suggestion for wrongly ordered format parameters) - rust-lang#134926 (Update books) - rust-lang#134945 (Some small nits to the borrowck suggestions for mutating a map through index) - rust-lang#134979 (Provide structured suggestion for `impl Default` of type where all fields have defaults) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 6 pull requests Successful merges: - rust-lang#131439 (Remove allowing static_mut_refs lint) - rust-lang#133292 (E0277: suggest dereferencing function arguments in more cases) - rust-lang#134877 (add suggestion for wrongly ordered format parameters) - rust-lang#134945 (Some small nits to the borrowck suggestions for mutating a map through index) - rust-lang#134950 (bootstrap: Overhaul and simplify the `tool_check_step!` macro) - rust-lang#134979 (Provide structured suggestion for `impl Default` of type where all fields have defaults) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#133292 - dianne:e0277-suggest-deref, r=estebank E0277: suggest dereferencing function arguments in more cases 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 rust-lang#87437). I've based the new checks loosely on what's done for `E0308` in `FnCtxt::suggest_deref_or_ref`: it will suggest dereferences to satisfy trait bounds whenever the referent is `Copy`, 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 rust-lang#90997
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