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

Avoid ICE: Account for for<'a> types when checking for non-structural type in constant as pattern #134776

Merged
merged 4 commits into from
Jan 11, 2025

Conversation

estebank
Copy link
Contributor

When we encounter a constant in a pattern, we check if it is non-structural. If so, we check if the type implements PartialEq, but for types with escaping bound vars the check would be incorrect as is, so we break early. This is ok because these types would be filtered anyways.

Slight tweak to output to remove unnecessary context as a drive-by.

Fix #134764.

@rustbot
Copy link
Collaborator

rustbot commented Dec 26, 2024

r? @lcnr

rustbot has assigned @lcnr.
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 Dec 26, 2024
@rustbot
Copy link
Collaborator

rustbot commented Dec 26, 2024

Some changes occurred in match checking

cc @Nadrieril

@@ -468,6 +479,10 @@ fn type_has_partial_eq_impl<'tcx>(
let partial_eq_trait_id = tcx.require_lang_item(hir::LangItem::PartialEq, None);
let structural_partial_eq_trait_id = tcx.require_lang_item(hir::LangItem::StructuralPeq, None);

if ty.has_escaping_bound_vars() {
return (false, false, false, None);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

is this necessary given that you bail in the UsedParamsNeedInstantiationVisitor?

I'd expect all other callers to not provide a type with escaping bound vars. MAybe just add debug_assert!(!ty.has_escaping_bound_vars()) to the start of this function

Copy link
Contributor

Choose a reason for hiding this comment

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

while you're at it, can you change the return type to be a struct with named fields? A tuple with 3 bools is very xx

if let ty::Adt(def, _args) = ty.kind() {
if ty.has_escaping_bound_vars() {
self.has_escaping_bound_vars = true;
} else if let ty::Adt(def, _args) = ty.kind() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I also believe that this visitor should not recur into fn-ptrs instead of bailing on bound vars.

Whether an adt implements PartialEq does not matter if it is inside of a trait object which does not implement PartialEq regardless.

Copy link
Contributor

Choose a reason for hiding this comment

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

why do you set has_escaping_bound_vars = true when encountering trait objects?

also, please make it an exhaustive match on ty.kind() and skip fn ptrs (they always impl eq) and bail on trait objects (they never do, except for dyn PartialEq 💀 🤔) and generators. this means has_escaping_bound_vars should be unnecessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was using that as a signal of "don't provide the suggestion". Can rename the field name or add another field.

@estebank estebank force-pushed the vanilla-ice branch 2 times, most recently from 1ab7b2e to 58ae641 Compare January 8, 2025 19:01
without: FxHashSet<Ty<'tcx>>,
/// If any of the subtypes has escaping bounds (`for<'a>`) or involves a trait object, we
/// won't emit a note.
should_note: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, one final nit, instead of setting should_note and then ignoring everything, wouldn't it be easier to return ControlFlow::Break(()) and change the caller to
if v.visit_ty(ty).is_break() { return }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

…constant as pattern

When we encounter a constant in a pattern, we check if it is non-structural. If so, we check if the type implements `PartialEq`, but for types with escaping bound vars the check would be incorrect as is, so we break early. This is ok because these types would be filtered anyways.

Fix rust-lang#134764.
Replace tuple with struct and remove unnecessary early return.
@lcnr
Copy link
Contributor

lcnr commented Jan 11, 2025

thanks 👍

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jan 11, 2025

📌 Commit 857918e has been approved by lcnr

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 Jan 11, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 11, 2025
…iaskrgr

Rollup of 4 pull requests

Successful merges:

 - rust-lang#134030 (add `-Zmin-function-alignment`)
 - rust-lang#134776 (Avoid ICE: Account for `for<'a>` types when checking for non-structural type in constant as pattern)
 - rust-lang#135205 (Rename `BitSet` to `DenseBitSet`)
 - rust-lang#135314 (Eagerly collect mono items for non-generic closures)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 2bcd5cf into rust-lang:master Jan 11, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Jan 11, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 11, 2025
Rollup merge of rust-lang#134776 - estebank:vanilla-ice, r=lcnr

Avoid ICE: Account for `for<'a>` types when checking for non-structural type in constant as pattern

When we encounter a constant in a pattern, we check if it is non-structural. If so, we check if the type implements `PartialEq`, but for types with escaping bound vars the check would be incorrect as is, so we break early. This is ok because these types would be filtered anyways.

Slight tweak to output to remove unnecessary context as a drive-by.

Fix rust-lang#134764.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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.

ICE has escaping bound vars, so it cannot be wrapped in a dummy binder.
4 participants