Skip to content

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

Merged
merged 1 commit into from
Jun 13, 2025

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Jun 4, 2025

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.

Screenshot 2025-06-04 at 10 38 24 AM

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.
@rustbot
Copy link
Collaborator

rustbot commented Jun 4, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 4, 2025
@petrochenkov
Copy link
Contributor

r? compiler

@rustbot rustbot assigned davidtwco and unassigned petrochenkov Jun 5, 2025
Comment on lines +1828 to +1849
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()
Copy link
Contributor Author

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.

@davidtwco
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 12, 2025

📌 Commit 585a409 has been approved by davidtwco

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 12, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 12, 2025
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.
bors added a commit that referenced this pull request Jun 12, 2025
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
bors added a commit that referenced this pull request Jun 12, 2025
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
@bors bors merged commit c77191f into rust-lang:master Jun 13, 2025
10 checks passed
@rustbot rustbot added this to the 1.89.0 milestone Jun 13, 2025
rust-timer added a commit that referenced this pull request Jun 13, 2025
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.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants