Description
Motivation
This field has a lot of code going into creating it, while its use sites barely care at all about all the nice data it contains. They could just as well compute the data they need themselves. Computing the data is cheap, so there's no point in computing this ahead of time.
Instructions
1. Eliminate uses
The field is used in two places:
- HIR -> MIR conversion
rust/src/librustc_mir/hair/cx/expr.rs
Line 590 in 50702b2
- rvalue promotion
rust/src/librustc_passes/rvalue_promotion.rs
Line 371 in 50702b2
The 1. use can be fixed by just checking whether the type of source
is the same type as expr_ty
. This means all foo as Bar
casts get ignored if foo
is already of type Bar
. Which is exactly what that code is trying to do.
The 2. use actually wants to know the cast kind, but there's no need to get that from the cast_kinds
field. Instead one would again obtain the type of the expression being cast and the type being cast to, and then do exactly what MIR based borrowck does when going through the same code (Use CastTy
to figure out the details):
rust/src/librustc_mir/transform/qualify_consts.rs
Lines 719 to 725 in 38168a7
2. Eliminate the field and all the code feeding into it
This part is easy now. Remove the field, and the compiler will guide you to all the places it's used. All you have to do is remove code until the compiler is happy.