Skip to main content

collect_trait_decls

Function collect_trait_decls 

Source
pub fn collect_trait_decls(modules: &[(&AIRModule, &Path)]) -> TraitDeclRegistry
Expand description

Pre-scan every reached module and build the TraitDeclRegistry.

Walks each module’s top-level TraitDecls and records the trait’s generic params and the full method list. Backends use this at each impl Trait for Type site to recover the trait’s default methods (those carrying a body) so they can be synthesized onto the implementing type — the trait interface alone carries only signatures, so a type that relies on an inherited default would otherwise have no such method at runtime (js/ts/go). A pre-scan (rather than recording traits as their decls are emitted) is required because an impl may precede its trait’s declaration in source order, and because a used trait’s decl can live in a different module than its impl (cross-module use). Mirrors collect_generic_decls.