Description
As part of #45208, one place where typeck_tables_of
is used that cannot easily be removed is this call from check_unused
. What this code is doing is aggregating the set of trait imports that are used by all the function bodies in the crate. Due to glob imports and the like, it is hard to isolate which function body may make use of which trait import. Also, this information is only available from type-checking. So this will require serializing some amount of incremental data in between sessions. But since we don't want to save all of the typeck data, we can at least minimize the amount of data.
The idea is to introduce a new intermediate query used_trait_imports(D)
for some def-id D. It will have the return type Rc<DefIdSet>
and will return the used_trait_imports
field from typeck_tables_of(D)
.
The steps are as follows:
- Change the type of
used_trait_imports
to beRc<DefIdSet>
so it can be cheaply cloned. Make the code compiled. - Introduce the
used_trait_imports
query as defined above; it should returntcx.typeck_tables_of(key).used_trait_imports.clone()
. - Modify these lines to use your new query instead of
typeck_tables_of
.