2

type certainty: clear `DefId` when an expression's type changes to non-adt by y2...

 4 weeks ago
source link: https://github.com/rust-lang/rust-clippy/pull/12591
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Member

@y21 y21

commented

Mar 29, 2024

edited

Fixes #12585

The root cause of the ICE in the linked issue was in the expression one.x, in the array literal.

The type of one is the One struct: an adt with a DefId, so its certainty is Certain(def_id_of_one). However, the field access .x can then change the type (to i32 here) and that should update that DefId accordingly. It does do that correctly when one.x would be another adt with a DefId:

but when it isn't an adt and there is no def id (which is the case in the linked issue: one.x is an i32), it keeps the DefId of One, even though that's the wrong type (which would then lead to a contradiction later when joining Certaintys):

In particular, in the linked issue, from_array([one.x, two.x]) would try to join the Certainty of the two array elements, which should have been [Certain(None), Certain(None)], because i32s have no DefId, but instead it was [Certain(One), Certain(Two)], because the DefId wasn't cleared from when it was visiting one and two. This is the "contradiction" that could be seen in the ICE message

... so this changes it to clear the DefId when it isn't an adt.

cc @smoelius you implemented this initially in #11135, does this change make sense to you?

changelog: none


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK