-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Detect method not being present that is present in other tuple types #142034
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
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
.
@bors r+ |
Detect method not being present that is present in other tuple types 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. <img width="1166" alt="Screenshot 2025-06-04 at 10 38 24 AM" src="https://github.com/user-attachments/assets/d257c9ea-c2d7-42e7-8473-8b93aa54b8e0" /> Address rust-lang#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.
Rollup of 10 pull requests Successful merges: - #134536 (Lint on fn pointers comparisons in external macros) - #138164 (Infrastructure for lints during attribute parsing, specifically duplicate usages of attributes) - #141069 (Suggest mut when possbile for temporary value dropped while borrowed) - #141934 (resolve: Tweak `private_macro_use` lint to be compatible with upcoming macro prelude changes) - #142034 (Detect method not being present that is present in other tuple types) - #142402 (chore(doctest): Remove redundant blank lines) - #142406 (Note when enum variants shadow an associated function) - #142407 (Remove bootstrap adhoc group) - #142408 (Add myself (WaffleLapkin) to review rotation) - #142418 (Remove lower_arg_ty as all callers were passing `None`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 9 pull requests Successful merges: - #134536 (Lint on fn pointers comparisons in external macros) - #141069 (Suggest mut when possbile for temporary value dropped while borrowed) - #141934 (resolve: Tweak `private_macro_use` lint to be compatible with upcoming macro prelude changes) - #142034 (Detect method not being present that is present in other tuple types) - #142402 (chore(doctest): Remove redundant blank lines) - #142406 (Note when enum variants shadow an associated function) - #142407 (Remove bootstrap adhoc group) - #142408 (Add myself (WaffleLapkin) to review rotation) - #142418 (Remove lower_arg_ty as all callers were passing `None`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #142034 - estebank:issue-141258, r=davidtwco Detect method not being present that is present in other tuple types 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. <img width="1166" alt="Screenshot 2025-06-04 at 10 38 24 AM" src="https://github.com/user-attachments/assets/d257c9ea-c2d7-42e7-8473-8b93aa54b8e0" /> 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.
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.