charon_lib/transform/
remove_unused_methods.rs

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