pub struct TraitMethod {
pub name: String,
pub params: Vec<Ty>,
pub ret: Ty,
pub has_self: bool,
pub mut_self: bool,
pub generics: u32,
pub bounds: Vec<Vec<DefId>>,
pub default_def: Option<DefId>,
}Expand description
One method of a trait. In params/ret, Ty::Param(0) denotes Self and
Ty::Param(1..=generics) the method’s own generic parameters (a generic
method like fn map<U>(self, …)). params never itself contains a
self entry: when the method declares a self receiver it is implicit
rather than stored here, but a trait method need not declare one at all
(e.g. fn zero() -> Int), in which case params is just its declared
parameters.
Fields§
§name: String§params: Vec<Ty>§ret: Ty§has_self: boolWhether the method declares a self receiver. A method without one is
an associated function, called as Type::name(…) with no receiver —
never as value.name(…). params looks the same either way (self is
never stored in it), so this flag is the only record of the difference,
and dispatch that ignores it lowers a receiver argument into a callee
that has no slot for it.
mut_self: boolWhether the self receiver is declared mut, i.e. whether the method is
a mutator whose callers must supply a mutable receiver place (E0060,
ADR 0005 §1). Meaningless when has_self is false, and the conformance
check that compares this against the impl’s own mut runs only after the
two agree about has_self at all.
It has to live here rather than being read off the impl: trait dispatch
resolves to (trait_id, method_index), and for a generic receiver
(fn f<T: Tr>(mut x: T) { x.m() }) there is no single impl whose
receiver declaration could be consulted. params cannot carry it either
— method_sig_parts strips a self parameter whether or not it is
mut, so the flag is the only record, exactly as has_self is the only
record of the receiver’s presence.
generics: u32Number of the method’s own generic parameters (not counting Self).
bounds: Vec<Vec<DefId>>Trait bounds per method generic parameter (indexed 0..generics).
default_def: Option<DefId>The compiled default-body function, if the trait provides a default.