Skip to main content

qualify_duplicate_type_names

Function qualify_duplicate_type_names 

Source
pub fn qualify_duplicate_type_names(
    structs: &mut [Struct],
    enums: &mut [EnumType],
    fns: &mut [Function],
    struct_files: &[(u16, u16)],
    enum_files: &[(u16, u16)],
    namespaces: &FileNamespaces,
    sources: &[Source],
)
Expand description

Puts the declaring module in front of every plain struct or enum name that more than one module declares, so a package’s types never collide with a consumer’s types of the same name.

Plain types share one program-wide table keyed by name, and a method lowers to a free function named after its type (Plain#get), so two modules each declaring Plain leave one Plain#get answering calls on both. The name a duplicate is registered under becomes right::Plain, which is what a diagnostic prints and what a method on it is mangled under; a generic type two modules declare is qualified the same way, see render_instantiation. A name only one module declares is left as it was written.

Every impl method is re-mangled against the name its receiver ended up with, resolved in the scope the impl block was written in, and so are the calls a method makes on its own receiver, which the recursion check reads.