Enum rustc::traits::select::SelectionCandidate [−][src]
enum SelectionCandidate<'tcx> { BuiltinCandidate { has_nested: bool, }, ParamCandidate(PolyTraitRef<'tcx>), ImplCandidate(DefId), AutoImplCandidate(DefId), ProjectionCandidate, ClosureCandidate, GeneratorCandidate, FnPointerCandidate, ObjectCandidate, BuiltinObjectCandidate, BuiltinUnsizeCandidate, }
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
The selection process begins by considering all impls, where
clauses, and so forth that might resolve an obligation. Sometimes
we'll be able to say definitively that (e.g.) an impl does not
apply to the obligation: perhaps it is defined for usize
but the
obligation is for int
. In that case, we drop the impl out of the
list. But the other cases are considered candidates.
For selection to succeed, there must be exactly one matching candidate. If the obligation is fully known, this is guaranteed by coherence. However, if the obligation contains type parameters or variables, there may be multiple such impls.
It is not a real problem if multiple matching impls exist because of type variables - it just means the obligation isn't sufficiently elaborated. In that case we report an ambiguity, and the caller can try again after more type information has been gathered or report a "type annotations required" error.
However, with type parameters, this can be a real problem - type parameters don't unify with regular types, but they can unify with variables from blanket impls, and (unless we know its bounds will always be satisfied) picking the blanket impl will be wrong for at least some substitutions. To make this concrete, if we have
trait AsDebug { type Out : fmt::Debug; fn debug(self) -> Self::Out; }
impl<T: fmt::Debug> AsDebug for T {
type Out = T;
fn debug(self) -> fmt::Debug { self }
}
fn foo<T: AsDebug>(t: T) { println!("{:?}",
we can't just use the impl to resolve the
- a type from another crate (that doesn't implement fmt::Debug) could implement AsDebug.
Because where-clauses match the type exactly, multiple clauses can only match if there are unresolved variables, and we can mostly just report this ambiguity in that case. This is still a problem - we can't do anything with ambiguities that involve only regions. This is issue #21974.
If a single where-clause matches and there are no inference variables left, then it definitely matches and we can just select it.
In fact, we even select the where-clause when the obligation contains inference variables. The can lead to inference making "leaps of logic", for example in this situation:
pub trait Foo
pub fn foo
Here the obligation <T as Foo<$0>> can be matched by both the blanket impl and the where-clause. We select the where-clause and unify $0=bool, so the program prints "false". However, if the where-clause is omitted, the blanket impl is selected, we unify $0=(), and the program prints "()".
Exactly the same issues apply to projection and object candidates, except that we can have both a projection candidate and a where-clause candidate for the same obligation. In that case either would do (except that different "leaps of logic" would occur if inference variables are present), and we just pick the where-clause. This is, for example, required for associated types to work in default impls, as the bounds are visible both as projection bounds and as where-clauses from the parameter environment.
Variants
BuiltinCandidate
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
Fields of BuiltinCandidate
has_nested: bool | 🔬 This is a nightly-only experimental API. ( |
ParamCandidate(PolyTraitRef<'tcx>)
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
ImplCandidate(DefId)
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
AutoImplCandidate(DefId)
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
ProjectionCandidate
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
This is a trait matching with a projected type as Self
, and
we found an applicable bound in the trait definition.
ClosureCandidate
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
Implementation of a Fn
-family trait by one of the anonymous types
generated for a ||
expression.
GeneratorCandidate
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
Implementation of a Generator
trait by one of the anonymous types
generated for a generator.
FnPointerCandidate
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
Implementation of a Fn
-family trait by one of the anonymous
types generated for a fn pointer type (e.g., fn(int)->int
)
ObjectCandidate
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
BuiltinObjectCandidate
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
BuiltinUnsizeCandidate
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
Trait Implementations
impl<'tcx> PartialEq for SelectionCandidate<'tcx>
[src]
impl<'tcx> PartialEq for SelectionCandidate<'tcx>
fn eq(&self, other: &SelectionCandidate<'tcx>) -> bool
[src]
fn eq(&self, other: &SelectionCandidate<'tcx>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &SelectionCandidate<'tcx>) -> bool
[src]
fn ne(&self, other: &SelectionCandidate<'tcx>) -> bool
This method tests for !=
.
impl<'tcx> Eq for SelectionCandidate<'tcx>
[src]
impl<'tcx> Eq for SelectionCandidate<'tcx>
fn assert_receiver_is_total_eq(&self)
[src]
fn assert_receiver_is_total_eq(&self)
impl<'tcx> Debug for SelectionCandidate<'tcx>
[src]
impl<'tcx> Debug for SelectionCandidate<'tcx>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<'tcx> Clone for SelectionCandidate<'tcx>
[src]
impl<'tcx> Clone for SelectionCandidate<'tcx>
fn clone(&self) -> SelectionCandidate<'tcx>
[src]
fn clone(&self) -> SelectionCandidate<'tcx>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<'a, 'tcx> Lift<'tcx> for SelectionCandidate<'a>
[src]
impl<'a, 'tcx> Lift<'tcx> for SelectionCandidate<'a>
type Lifted = SelectionCandidate<'tcx>
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
fn lift_to_tcx<'b, 'gcx>(
&self,
tcx: TyCtxt<'b, 'gcx, 'tcx>
) -> Option<Self::Lifted>
[src]
fn lift_to_tcx<'b, 'gcx>(
&self,
tcx: TyCtxt<'b, 'gcx, 'tcx>
) -> Option<Self::Lifted>
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
Auto Trait Implementations
impl<'tcx> !Send for SelectionCandidate<'tcx>
impl<'tcx> !Send for SelectionCandidate<'tcx>
impl<'tcx> !Sync for SelectionCandidate<'tcx>
impl<'tcx> !Sync for SelectionCandidate<'tcx>