charon_lib/transform/
remove_unused_methods.rs

1//! Remove the trait/impl methods that were not translated.
2use crate::ast::*;
3
4use super::{TransformCtx, ctx::TransformPass};
5
6pub struct Transform;
7impl TransformPass for Transform {
8    fn transform_ctx(&self, ctx: &mut TransformCtx) {
9        let method_is_translated = |id: FunDeclId| ctx.translated.fun_decls.get(id).is_some();
10        // Keep only the methods for which we translated the corresponding `FunDecl`. We ensured
11        // that this would be translated if the method is used or transparently implemented.
12        for tdecl in ctx.translated.trait_decls.iter_mut() {
13            tdecl
14                .methods
15                .retain(|m| method_is_translated(m.skip_binder.item.id));
16        }
17        for timpl in ctx.translated.trait_impls.iter_mut() {
18            timpl
19                .methods
20                .retain(|(_, m)| method_is_translated(m.skip_binder.id));
21        }
22    }
23}