Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardRustZero-cost abstraction in codegenSingle-choice MCQ

A generic function and a trait-object function look interchangeable at the call site, but their codegen differs. For the two calls below, which statement is exactly correct about what the compiler emits and the trade-off involved?

fn via_generic<T: Trait>(x: &T) { x.method(); } fn via_dyn(x: &dyn Trait) { x.method(); }