Skip to main content

trait_namespace_target

Function trait_namespace_target 

Source
pub(super) fn trait_namespace_target(
    class_system: ClassSystem,
    type_ident: &Ident,
    trait_name: &Ident,
    member: &str,
) -> String
Expand description

R-visible assignment target for a trait member (method or const) placed in the per-class trait namespace — the single owner of the namespace-shape policy the 5 generators previously hand-rolled independently (audit 2026-07-03-dogfooding-macros-codegen.md finding #1; #1141). member is the R-facing method/const name.

Policy:

  • Env / S3 / R6 / Vctrs: Type$Trait$member — class-scoped, so it is collision-free by construction. This is what fixes #1115: two R6 impls of one trait on different types now emit TypeA$Trait$m / TypeB$Trait$m rather than a shared, unqualified r6_trait_Trait_m that aborted wrapper-gen via the duplicate-definition guard.
  • S4: flat Type_Trait_member standalone name. S4 objects intercept $<-, so Type$Trait$member cannot be assigned onto them; the class component in the flat name keeps it collision-free.
  • S7: env_var$member, where env_var = trait_namespace_env_var (.Type__Trait) is a local env attached to Type via attr() at the end of the generator. S7 objects also intercept $<-; routing through an attribute-attached env lets Type$Trait$member still resolve at the call site (R’s $ on an S7 object falls through to attributes).