-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Detect method not being present that is present in other tuple types #142034
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
base: master
Are you sure you want to change the base?
Conversation
When a method is not present because of a trait bound not being met, and that trait bound is on a tuple, we check if making the tuple have no borrowed types makes the method to be found and highlight it if it does. This is a common problem for Bevy in particular and ORMs in general.
rustbot has assigned @petrochenkov. Use |
r? compiler |
if let Some(impl_span) = self | ||
.tcx | ||
.all_impls(def_id) | ||
.filter(|&impl_def_id| { | ||
let header = self.tcx.impl_trait_header(impl_def_id).unwrap(); | ||
let trait_ref = header.trait_ref.instantiate( | ||
self.tcx, | ||
self.infcx.fresh_args_for_item(DUMMY_SP, impl_def_id), | ||
); | ||
|
||
let value = ty::fold_regions(self.tcx, ty, |_, _| { | ||
self.tcx.lifetimes.re_erased | ||
}); | ||
// FIXME: Don't bother dealing with non-lifetime binders here... | ||
if value.has_escaping_bound_vars() { | ||
return false; | ||
} | ||
self.infcx.can_eq(ty::ParamEnv::empty(), trait_ref.self_ty(), value) | ||
&& header.polarity == ty::ImplPolarity::Positive | ||
}) | ||
.map(|impl_def_id| self.tcx.def_span(impl_def_id)) | ||
.next() |
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.
This is a smell blatantly taken from another diagnostic. This seems to be a recurring useful need: assert if a certain (trait) predicate would be fulfilled with a different type, and if so, get the span for that specific impl
. We should probably add a mechanism of doing that to TyCtxt
.
When a method is not present because of a trait bound not being met, and that trait bound is on a tuple, we check if making the tuple have no borrowed types makes the method to be found and highlight it if it does. This is a common problem for Bevy in particular and ORMs in general.
Address #141258. I believe that more combination of cases in the tuple types should be handled (like adding borrows and checking when a specific type needs to not be a borrow while the rest stay the same), but for now this handles the most common case.