Skip to content
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

Fix rust-lang/rust#107877, etc. #10403

Merged
merged 1 commit into from
Mar 5, 2023
Merged

Fix rust-lang/rust#107877, etc. #10403

merged 1 commit into from
Mar 5, 2023

Conversation

smoelius
Copy link
Contributor

@smoelius smoelius commented Feb 25, 2023

Fix #10009
Fix #10387
Fix rust-lang/rust#107877

The fix is to verify that the associated item's trait is implemented before trying to project the item's type.

r? @Jarcho


changelog: ICE: [needless_borrow]: No longer panics on ambiguous projections
#10403

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Feb 25, 2023
@smoelius
Copy link
Contributor Author

smoelius commented Mar 3, 2023

With the just pushed commit, I revised the approach. 😬

I'm sorry for the moving target, but I think you'll agree the new approach is better.

// avoid hitting this `span_bug`:
// /~https://github.com/rust-lang/rust/blob/695072daa6cc04045f2aa79d751d884ad5263080/compiler/rustc_trait_selection/src/traits/query/normalize.rs#L272-L275
// See: /~https://github.com/rust-lang/rust/issues/107877
if implements_trait(cx, new_ty, assoc_item.container_id(cx.tcx), List::empty())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this pass the substitutions needed for the trait, rather than just an empty list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but do we have a way of knowing what those could could/should be?

I was under the impression we were making a best effort guess of "no parameters needed."

Maybe I'm misunderstanding, but I thought that's what was happening with [] here:

let projection = cx.tcx
.mk_projection(assoc_item.def_id, cx.tcx.mk_substs_trait(new_ty, []));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameters are stored in the projection predicate. You'd need to replace the self type but otherwise they should be correct. This is probably the reason for the ambiguity error in the first place. If both Foo<X> and Foo<Y> are implemented then Foo<_>::Assoc could refer to either.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think implements_trait returns false in this case which hides the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like your analysis was spot on.

@Jarcho
Copy link
Contributor

Jarcho commented Mar 5, 2023

Thank you. @bors r+

@bors
Copy link
Contributor

bors commented Mar 5, 2023

📌 Commit f95d9de has been approved by Jarcho

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Mar 5, 2023

⌛ Testing commit f95d9de with merge 70e85d1...

@bors
Copy link
Contributor

bors commented Mar 5, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Jarcho
Pushing 70e85d1 to master...

@bors bors merged commit 70e85d1 into rust-lang:master Mar 5, 2023
@smoelius smoelius deleted the fix-107877 branch March 5, 2023 01:45
@Jarcho Jarcho added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Mar 5, 2023
@flip1995
Copy link
Member

rust-lang/rust#110273

@flip1995 flip1995 added beta-accepted Accepted for backporting to the compiler in the beta channel. and removed beta-nominated Nominated for backporting to the compiler in the beta channel. labels Apr 13, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 13, 2023
[beta] Clippy: backport optimization and ICE fixes

The first commit optimizes a lint, that runs noticeably slow and is a perf issue. See rust-lang/rust-clippy#10533

The second commit fixes an ICE that occurred when running Clippy on `gitoxide` besides others. Since this is a rather popular crate, we want to fix this rather sooner than later. See rust-lang/rust-clippy#10403

---

Both commits are already on `master` and deployed on `nightly`.
@xFrednet xFrednet removed the beta-accepted Accepted for backporting to the compiler in the beta channel. label Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
6 participants