Wado

Static Call Resolution — One Walk, One Answer

Context

Type::method(...) is written five ways: bare, ns::Type::method(), Type::<A>::method(), Self::method() and T::method() through a bound. Every one of them has to answer the same questions: is this a static at all, which declaration does it name, what are its parameters, what does it return, what type parameters does it take.

Many lookups answered those questions, each walking its own part of one ladder in its own order. The rungs were the same: the receiver's own declarations, its resource statics and their chain, a trait impl declaring the method, one inheriting the trait's default body, a derived trait, the newtype base. What differed was where each stopped, what it did on a miss, and which receiver it started from.

So two of them could disagree about one call. The spelling resolved and its signature did not, and the call was compiled with no parameter list: an unchecked arity, an unpadded default, a call naming a body without its trait. Fixing the instances one at a time did not converge. Declaration Identity already says one identity, one scope, one answer.

Decision

One resolution answers every spelling, and every site that needs a fact about the call reads it from that answer.

The receiver is one vantage

The receiver is the declaration the call's own reference site resolved. A receiver re-derived from the bare name in the caller's frame answers another question: the importing module may not name Type, and a primitive's impl FromStr for f32 is out of reach from a name.

The same holds one link down. A newtype reaches its base through its own declaration, never by the base's name, which a namespaced lib::Q::twice() never imported. The call names the body of the link the resolution answered with. Under the spelled Q it names a body that does not exist.

It holds for the inference too. ns::Type::method() infers the receiver's type arguments, and reports the ones it cannot fill, exactly as Type::method() does.

A qualified spelling names a trait

Tagged::<Self = V>::tag(5) asks for Tagged's declaration, so only its impls are candidates. The receiver's own declaration of the name is a different method, and a case or flags member V declares builds a value rather than answering the trait. The shadowing rule below applies to a bare V::tag, which is what the spelling rewrites to once the binding has supplied Self.

A trait's turbofish is its argument list: Take::<i64>::take(&f, 42) pins the list and the receiver argument supplies Self. A static has no such argument, so Self = T binds it, closing the list after the trait's own arguments: Take::<i64, Self = V>::take(). Only the impls of the trait at those arguments are candidates. Take::<i64>::take() names no receiver at all, and is reported as that rather than as an unknown function.

The binding is the spelling Rust writes <V as Tagged>::tag(5). An expression opening with < is left free for markup, and the binding reuses the form a bound already writes for an associated type (T: Parts<Items = …>). Self is the trait frame's first parameter, so binding it by name states what the resolution already does.

On a trait declaring no parameters a lone argument once stood for Self (Tagged::<V>::tag(5)). It read as a trait argument, and a trait that did declare parameters had nowhere left to write Self, so a static of such a trait was unreachable once another declaration shadowed it or tied with it (issue #2650). One form for every trait replaces it.

A namespace qualifies the head, not the argument list. ns::Take::<i64>::take(…) asks the same questions of the same declaration as Take::<i64>::take(…). The head is read where it was written, so a bare spelling and a namespaced one reach the same answer.

What the resolution answers

one declaration with its parameter lists read at the receiver
an overload one trait, several impls; the arguments had nothing to separate
an ambiguity several traits supply the name; no argument can pick
not a static a variant case or a flags member owns the name
out of scope only traits the calling module has not imported supply the name
tied impls of one trait that each leave a slot to the call reach it alike

Each answer means one thing:

One list of candidates, one pass of rules

The rungs produce candidates, and a single pass over them decides. A candidate is one declaration a block on the receiver supplies for the name. It carries what the rules read: the trait it comes through, the block, the declaration, whether it takes a receiver, whether the block wrote the body or inherited it, and the parameter each argument is checked against. It carries no decision, so a rung added later cannot miss a rule.

The receiver's own declarations are candidates too: its inherent impl, the statics a resource declares, and one it inherits along that chain.

The rules run in this order, and the order is the design:

  1. The receiver's own declaration shadows the inherited candidates.
  2. Where several traits supply the name, the spelling names none of them, and that is reported.
  3. The arguments pick among what is left.
  4. The earlier origin outranks: the receiver's own, then a written body, then an inherited one, among what the arguments admit.

Every candidate is receiver-less. A receiver-taking declaration is the method call's: where no receiver-less one answers, Type::method(recv, …) selects what recv.method(…) does (issue #2650). So Type::method(x) is a static's call before it is a receiver's.

What remains is one declaration, or several of one trait that no argument separated: the overload.

Steps 3 and 4 are in that order because a written body the argument rejects is not an answer. impl Conv<i32> for M {} beside impl Conv<String> for M { fn make(…) } answers M::make(5) from the inherited default, though a block wrote a body for the other argument.

An own candidate is exempt from step 3. The arguments choose among impls, and a declaration the receiver makes itself has none to be chosen against. The call site reports an argument mismatch against the one declaration the spelling names.

Rules about what the candidates are

The argument picks a declaration, not a trait

A static call is selected by the parameters the impl declares, each compared against the argument written for it. The comparison is by type identity, so two distinct types that print one name are two candidates.

A parameter still holding slots is compared by shape: the slots are solved from the argument, and what that makes of the parameter is compared. Neither half is a name. A rendered name spells a function type's own parameters, so fn(T) -> i32 never matches fn(i32) -> i32, and it drops a generic's arguments, so Holder<T, T> matches a Holder<i32, String> that no T makes.

From<T> is no special case. Its source type is also its trait argument and from takes one argument, but a trait implemented twice on one receiver (impl Conv<A> for M beside impl Conv<B> for M) poses the same question at any arity, and the declared parameter is what answers it. The parameter is resolved in the impl's own frame, so both sides of the comparison are canonical.

The trait segment of the name a call is compiled under keeps the trait's arguments. Dropping them collapses two declarations of one method name onto one body. What decides this is how many times the receiver implements the trait, never which trait it is. It holds for a body the block inherits as much as one it writes: the segment comes from the block's own trait reference, since a trait declaration has no arguments to give.

A parameter the block fills is a blanket, not a mismatch. Its unsubstituted spelling must not be named, so the candidate declines it and the blanket is instantiated instead.

Three things fill a slot, and only one of them is the argument. The receiver fills a slot it mentions, so impl<T> Make<T> for Wrap<T> is no blanket to Wrap::<i32>::make. The call fills a slot the method declares, so a block's own fn build<T>(v: T) is not one either. What is left is a block slot the receiver never names, as in impl<T: Display> From<T> for ByAny, and only that is a blanket. Two shapes settle the rest: a slot reached only inside a constructor (impl From<Array<T>> for List<T>) leaves a concrete head to name and is kept, and a reference to a slot (From<&T>) is the slot, peeled before the question is asked.

The spelling names both kinds, by what the type answers

Type::method(recv, …) reaches an instance method as well as a static, passing the receiver first. The spelled type answers the name once, with declarations of both kinds, in the order a method call ranks them: the nearest link of its chain, and there the type's own declaration before a trait's. The kind of what answers decides the rest. A receiver-taking declaration makes the spelling a method call on its first argument, which must be of the spelled type or a resource extending it. A receiver-less one is the static this resolution selects.

The call once ran through this resolution alone, which kept a ladder of its own for instance methods: it collected no blanket's instance method, ranked a newtype's trait impl above its base's inherent method by link where dot syntax did not, and reported two traits where dot syntax ranked them (issue #2650). Routing that ladder's calls to the method call by name alone came next: a name some trait declared with a receiver went there, so an unrelated trait decided the call, and a name some trait declared without one kept a blanket's instance method out of reach. Asking the type itself removes both classes.

WEP: Omitted Type Arguments Are Inference Variables replaces the listed instances in this passage and the three after it with inference variables. What they say a sole written impl settles is history: an impl settles no omitted argument, a literal's aside.

A generic type spelled without its arguments (Pair::span(&p)) names no one instance, so the question is what its instances answer the name with. The impls written for the type's head are candidates whatever instance each names. The order is also asked at each instance an impl is written for, so a blanket whose bounds hold there answers too, through any chain of blankets the order follows. The receiver's own type then settles the call, and its selection confirms the candidate or reports that no method answers. Candidates of both kinds at one link leave the kind undecided, and the call is reported as ambiguous.

The kind is decided before the arguments are resolved, so the receiver's type does not take part in it. Resolving the first argument early would resolve that expression twice.

A static answers by the same rule, with the instance found the way any inference finds a type: from the expected type (let d: Duo<i32, bool> = Duo::build()) or an argument (Duo::weigh(d)). Where neither says, the written impls do. If the blanket answers at exactly one instance an impl is written for, that instance is the call's, as a sole written impl (impl Make for Pair<i32, i32>) already settles Pair::made(). More than one leaves the type's arguments uninferred, and the call reports that.

Two traits at one link are ambiguous whichever kind each declares, as they are for a method call. One answering with a static and the other with a method is reported once, and the call recovers on the method.

On a chain of newtypes, the call belongs to the first link, from the spelled head down, that offers anything for the name: a declaration its impls reach, a trait default its impl leaves to answer, a case it declares, or a derivation. A newtype derives nothing itself, so a derivation is offered at the link it is written for. The owner is found without the arguments, and the arguments then select among that link's candidates only.

A blanket offers at the link where its bounds hold, the level the trait resolution order gives it (WEP 2026-09-01, rank 1). A newtype inherits its base's bounds, so counting a blanket wherever it reaches makes the head own every name some blanket supplies, and a blanket only the base admits then outranks the base's own declarations and its derivations. Within its link, a blanket ranks below what is written for the type, a derivation included (rank 2).

The rules then pick among the owner's candidates, a blanket included, and the blanket resolver instantiates the blanket the rules picked. Instantiating whichever applicable blanket comes first instead names a second answer for the call.

An impl on another instance of a link answers nothing for this one. The instance is the one the call spells, or the one the chain declares where the head is spelled bare, never one the arguments would infer.

The arguments cannot decide it, because they are typed against the owner. A site that resolves the parameter list first, to give each argument its expected type, needs the owner before any argument exists, so choosing the link by whether its candidates admit the arguments is circular. Every site that needs the owner, early or late, reads it from this one walk.

The rule rejects no call that compiled. Where a link's candidates reject the arguments, the arguments were already typed against that link and the mismatch reported, so the link below never answered.

The receiver fills the declaring slots, once

A declaration's declaring slots, an impl block's, a resource's or an interface's, are filled by the receiver's type arguments. A block aligns them, since its head may reorder or fix some (impl … for TreeMap<String, V> numbers only V); a resource numbers its own by position.

Never the receiver type itself. Only a trait's frame leads with Self, and that frame is read where an inherited body is. Binding slot zero to the receiver outside it made Stream::<u8>::new() return a StreamWritable<Stream<u8>>, because Stream's slot zero is its T.

The resolution fills them, so the call site does not. It substitutes the method's own slots alone, the ones the resolution leaves open for the call to solve. Filling the declaring slots a second time from the spelled turbofish is two answers for one call.

The arguments are the fact, not the type that holds them. A receiver spelled as a bare name has a list and no type to read it off: Counter::make() infers the list at the call, and Counter<T> resolved from the name would answer with its own parameters. So the resolution takes the arguments as a fact of their own, and derives them from the receiver type only where the call brings none.

A concrete block is named where it is written

A block written for one instantiation hosts its own function, in its own module and under the head it wrote. impl Wrap<i32> for Cell<i32> emits Cell<i32>::wrap beside the block. A generic block has no such head: monomorphization materialises each instance in the receiver's module, under the receiver's own name.

So a call names the block it resolved to, not the receiver it spelled. Cell::wrap(7) picks the concrete block by its argument, and then names Cell<i32> in that block's module. Naming the receiver for both puts the call and the body in different modules, and the call's name carries no arguments where the body's does.

This is what the receiver's type arguments are inferred for. The turbofish is not the only way to write them: the arguments select the block, and the block's head says what the receiver is.

Every parameter a block declares is a slot of that block

A block's slots are numbered by the position each takes in the receiver's arguments. A parameter the receiver never mentions, as in impl<T: Display> From<T> for ByAny, is numbered after the ones it does. Only an argument can fill it, which is what makes the block a blanket, but a slot is what it is either way, so fn from(v: T) has a type. Whether only an argument can fill a parameter is read off its slot.

The block's own parameters bind before the trait's, since From<T>'s is also spelled T. Binding the trait's first claims that name for an argument nothing has resolved yet, and the block's own slot is never made.

Every entry in impl<...> declares a parameter, as in Rust. A concrete instantiation names its type in the trait or receiver instead: impl IndexValue<i32> for Box.

A blanket is a candidate, ranked last

A value blanket (impl<T: Bound> Trait for T) covers a receiver through its bound rather than naming it, so no name at a call site reaches its statics. It is a candidate all the same: what a rung produces is facts, and which of several answers is the rules' to decide.

It ranks after everything written for the receiver itself, so a concrete impl wins by the rule rather than by which path ran first. Ranking happens before the ambiguity report, or a blanket the receiver's own declaration outranks would be named as an alternative to it. Two traits blanketing one receiver supply the name and separate nothing, which is the same ambiguity two concrete impls raise. A blanket tried only where nothing else answered would take the first that applies instead.

Selecting a blanket is the rules'; instantiating one is not. Its template is written against the receiver parameter, so the blanket is instantiated where it is named, and the candidate builds no callee.

An inherited body is read in the trait's own frame

The trait's frame numbers Self as slot 0 and the trait's own parameters after it, so a block reads a default body back by supplying its target and then its trait arguments. Supplying the target alone leaves the rest open: every argument reaches every block, M::tag("x") and M::tag(5) select whichever block came first, and the call then names the other one's body.

So an inherited candidate's parameter is the one the block's trait arguments produce, not the one the trait declared.

One call, one resolution

The literal preselect runs before the callee is resolved, and keys it. Resolving the parameter lists without the argument and naming the body with it gives two answers for one call. One resolver does not prevent that by itself, because two calls to it disagree just as well.

So the resolution hands back everything a site needs from it: the declaration it picked, what the call returns, and the lists to check and pad against. A site that names the body from one answer and asks again for the other is the shape to look for, and the second ask is the one that goes wrong: it is keyed by a bare name in the caller's frame, which an alias or a namespace leaves without that name. The facts that identify a receiver travel as one value for the same reason.

The preselect reads the whole argument list, each argument against the parameter written for it, as the selection does. Reading argument zero alone shapes the first literal from the impl it picked and leaves the rest to their own defaults, so M::make(0, 5) types 5 as i32 and matches no Conv<i64> impl. An argument whose type synthesis cannot produce admits every parameter, so one such argument among others does not stop the rest from deciding.

A spelling several traits answer is reported for the same reason, and before the overload an argument settles. Whether each trait declares a body or leaves its default to answer makes no difference, because neither separates the traits. Every site that names a body consumes that report, or it names a trait-less body nothing declares.

The report names each trait once, in the order the blocks were written. It dedupes by declaration rather than by rendered name, because a trait's two blocks need not be adjacent.

A static's own slots are solved, not spelled

A method's own type parameters are inferred from the arguments, as instance dispatch infers them. Where the block declares no slots of its own, the method's are numbered from zero and the receiver's substitution reaches them anyway. Where it declares some, they are solved at the call and the signature re-instantiated with what came back.

The solve runs after the arguments are elaborated, because it reads them, and a literal is re-coerced afterwards against the parameter the solve produced. A slot the arguments do not pin is reported, with the spelling (Box3::<i32>::build::<i32>(42)) named: an unsolved slot must not reach codegen.

A checked argument is a source change

An inherited default-bodied static checks its arguments against the trait's parameter list. Callers that relied on them going unchecked see a break: Instant::from_str("…") against a declaration taking &String is written &"…".

An argument no list describes is an argument nothing can reject, so the tightening is the point rather than a side effect. It is the one change here a caller outside the compiler sees.

Resolving runs only where its answer is used

Two rungs change compiler state: reading a trait-frame signature at the receiver resolves a type name in an inherited-type-param scope, and the auto-derived Default records a synthesis request. Each runs inside the rung that needs it, never eagerly for a caller's convenience. Resolving the receiver up front changes state on paths that never use it, and stops List<T>::with_capacity, called from inside its own impl, from resolving.

A site that needs the owning link before the arguments walks the chain only on a newtype receiver, and reads the rungs the call's own resolution then reads.

Every name reads one answer

No lookup walks a ladder of its own. It reads the resolution's answer, or asks one rung through the walk the resolution uses. Instantiating a blanket is the exception: it walks the blanket's own rungs, but to instantiate what the rules picked rather than to pick it.

Known gaps