1//! Candidate selection. See the [rustc dev guide] for more information on how this works.
2//!
3//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/resolution.html#selection
45use rustc_errors::ErrorGuaranteed;
6use rustc_hir::def_id::DefId;
7use rustc_macros::{HashStable, TypeVisitable};
8use rustc_query_system::cache::Cache;
9use rustc_type_ir::solve::AliasBoundKind;
1011use self::EvaluationResult::*;
12use super::{SelectionError, SelectionResult};
13use crate::ty;
1415pub type SelectionCache<'tcx, ENV> =
16Cache<(ENV, ty::TraitPredicate<'tcx>), SelectionResult<'tcx, SelectionCandidate<'tcx>>>;
1718pub type EvaluationCache<'tcx, ENV> = Cache<(ENV, ty::PolyTraitPredicate<'tcx>), EvaluationResult>;
1920/// The selection process begins by considering all impls, where
21/// clauses, and so forth that might resolve an obligation. Sometimes
22/// we'll be able to say definitively that (e.g.) an impl does not
23/// apply to the obligation: perhaps it is defined for `usize` but the
24/// obligation is for `i32`. In that case, we drop the impl out of the
25/// list. But the other cases are considered *candidates*.
26///
27/// For selection to succeed, there must be exactly one matching
28/// candidate. If the obligation is fully known, this is guaranteed
29/// by coherence. However, if the obligation contains type parameters
30/// or variables, there may be multiple such impls.
31///
32/// It is not a real problem if multiple matching impls exist because
33/// of type variables - it just means the obligation isn't sufficiently
34/// elaborated. In that case we report an ambiguity, and the caller can
35/// try again after more type information has been gathered or report a
36/// "type annotations needed" error.
37///
38/// However, with type parameters, this can be a real problem - type
39/// parameters don't unify with regular types, but they *can* unify
40/// with variables from blanket impls, and (unless we know its bounds
41/// will always be satisfied) picking the blanket impl will be wrong
42/// for at least *some* generic parameters. To make this concrete, if
43/// we have
44///
45/// ```rust, ignore
46/// trait AsDebug { type Out: fmt::Debug; fn debug(self) -> Self::Out; }
47/// impl<T: fmt::Debug> AsDebug for T {
48/// type Out = T;
49/// fn debug(self) -> fmt::Debug { self }
50/// }
51/// fn foo<T: AsDebug>(t: T) { println!("{:?}", <T as AsDebug>::debug(t)); }
52/// ```
53///
54/// we can't just use the impl to resolve the `<T as AsDebug>` obligation
55/// -- a type from another crate (that doesn't implement `fmt::Debug`) could
56/// implement `AsDebug`.
57///
58/// Because where-clauses match the type exactly, multiple clauses can
59/// only match if there are unresolved variables, and we can mostly just
60/// report this ambiguity in that case. This is still a problem - we can't
61/// *do anything* with ambiguities that involve only regions. This is issue
62/// #21974.
63///
64/// If a single where-clause matches and there are no inference
65/// variables left, then it definitely matches and we can just select
66/// it.
67///
68/// In fact, we even select the where-clause when the obligation contains
69/// inference variables. The can lead to inference making "leaps of logic",
70/// for example in this situation:
71///
72/// ```rust, ignore
73/// pub trait Foo<T> { fn foo(&self) -> T; }
74/// impl<T> Foo<()> for T { fn foo(&self) { } }
75/// impl Foo<bool> for bool { fn foo(&self) -> bool { *self } }
76///
77/// pub fn foo<T>(t: T) where T: Foo<bool> {
78/// println!("{:?}", <T as Foo<_>>::foo(&t));
79/// }
80/// fn main() { foo(false); }
81/// ```
82///
83/// Here the obligation `<T as Foo<$0>>` can be matched by both the blanket
84/// impl and the where-clause. We select the where-clause and unify `$0=bool`,
85/// so the program prints "false". However, if the where-clause is omitted,
86/// the blanket impl is selected, we unify `$0=()`, and the program prints
87/// "()".
88///
89/// Exactly the same issues apply to projection and object candidates, except
90/// that we can have both a projection candidate and a where-clause candidate
91/// for the same obligation. In that case either would do (except that
92/// different "leaps of logic" would occur if inference variables are
93/// present), and we just pick the where-clause. This is, for example,
94/// required for associated types to work in default impls, as the bounds
95/// are visible both as projection bounds and as where-clauses from the
96/// parameter environment.
97#[derive(#[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for SelectionCandidate<'tcx> {
#[inline]
fn eq(&self, other: &SelectionCandidate<'tcx>) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(SelectionCandidate::ParamCandidate(__self_0),
SelectionCandidate::ParamCandidate(__arg1_0)) =>
__self_0 == __arg1_0,
(SelectionCandidate::ImplCandidate(__self_0),
SelectionCandidate::ImplCandidate(__arg1_0)) =>
__self_0 == __arg1_0,
(SelectionCandidate::ProjectionCandidate {
idx: __self_0, kind: __self_1 },
SelectionCandidate::ProjectionCandidate {
idx: __arg1_0, kind: __arg1_1 }) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(SelectionCandidate::ClosureCandidate { is_const: __self_0 },
SelectionCandidate::ClosureCandidate { is_const: __arg1_0 })
=> __self_0 == __arg1_0,
(SelectionCandidate::ObjectCandidate(__self_0),
SelectionCandidate::ObjectCandidate(__arg1_0)) =>
__self_0 == __arg1_0,
(SelectionCandidate::TraitUpcastingUnsizeCandidate(__self_0),
SelectionCandidate::TraitUpcastingUnsizeCandidate(__arg1_0))
=> __self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for SelectionCandidate<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<ty::PolyTraitPredicate<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<DefId>;
let _: ::core::cmp::AssertParamIsEq<usize>;
let _: ::core::cmp::AssertParamIsEq<AliasBoundKind>;
let _: ::core::cmp::AssertParamIsEq<bool>;
}
}Eq, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for SelectionCandidate<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
SelectionCandidate::SizedCandidate =>
::core::fmt::Formatter::write_str(f, "SizedCandidate"),
SelectionCandidate::BuiltinCandidate =>
::core::fmt::Formatter::write_str(f, "BuiltinCandidate"),
SelectionCandidate::TransmutabilityCandidate =>
::core::fmt::Formatter::write_str(f,
"TransmutabilityCandidate"),
SelectionCandidate::ParamCandidate(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ParamCandidate", &__self_0),
SelectionCandidate::ImplCandidate(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ImplCandidate", &__self_0),
SelectionCandidate::AutoImplCandidate =>
::core::fmt::Formatter::write_str(f, "AutoImplCandidate"),
SelectionCandidate::ProjectionCandidate {
idx: __self_0, kind: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"ProjectionCandidate", "idx", __self_0, "kind", &__self_1),
SelectionCandidate::ClosureCandidate { is_const: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"ClosureCandidate", "is_const", &__self_0),
SelectionCandidate::AsyncClosureCandidate =>
::core::fmt::Formatter::write_str(f, "AsyncClosureCandidate"),
SelectionCandidate::AsyncFnKindHelperCandidate =>
::core::fmt::Formatter::write_str(f,
"AsyncFnKindHelperCandidate"),
SelectionCandidate::CoroutineCandidate =>
::core::fmt::Formatter::write_str(f, "CoroutineCandidate"),
SelectionCandidate::FutureCandidate =>
::core::fmt::Formatter::write_str(f, "FutureCandidate"),
SelectionCandidate::IteratorCandidate =>
::core::fmt::Formatter::write_str(f, "IteratorCandidate"),
SelectionCandidate::AsyncIteratorCandidate =>
::core::fmt::Formatter::write_str(f,
"AsyncIteratorCandidate"),
SelectionCandidate::FnPointerCandidate =>
::core::fmt::Formatter::write_str(f, "FnPointerCandidate"),
SelectionCandidate::PointerLikeCandidate =>
::core::fmt::Formatter::write_str(f, "PointerLikeCandidate"),
SelectionCandidate::TraitAliasCandidate =>
::core::fmt::Formatter::write_str(f, "TraitAliasCandidate"),
SelectionCandidate::ObjectCandidate(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ObjectCandidate", &__self_0),
SelectionCandidate::TraitUpcastingUnsizeCandidate(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"TraitUpcastingUnsizeCandidate", &__self_0),
SelectionCandidate::BuiltinObjectCandidate =>
::core::fmt::Formatter::write_str(f,
"BuiltinObjectCandidate"),
SelectionCandidate::BuiltinUnsizeCandidate =>
::core::fmt::Formatter::write_str(f,
"BuiltinUnsizeCandidate"),
SelectionCandidate::BikeshedGuaranteedNoDropCandidate =>
::core::fmt::Formatter::write_str(f,
"BikeshedGuaranteedNoDropCandidate"),
}
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for SelectionCandidate<'tcx> {
#[inline]
fn clone(&self) -> SelectionCandidate<'tcx> {
match self {
SelectionCandidate::SizedCandidate =>
SelectionCandidate::SizedCandidate,
SelectionCandidate::BuiltinCandidate =>
SelectionCandidate::BuiltinCandidate,
SelectionCandidate::TransmutabilityCandidate =>
SelectionCandidate::TransmutabilityCandidate,
SelectionCandidate::ParamCandidate(__self_0) =>
SelectionCandidate::ParamCandidate(::core::clone::Clone::clone(__self_0)),
SelectionCandidate::ImplCandidate(__self_0) =>
SelectionCandidate::ImplCandidate(::core::clone::Clone::clone(__self_0)),
SelectionCandidate::AutoImplCandidate =>
SelectionCandidate::AutoImplCandidate,
SelectionCandidate::ProjectionCandidate {
idx: __self_0, kind: __self_1 } =>
SelectionCandidate::ProjectionCandidate {
idx: ::core::clone::Clone::clone(__self_0),
kind: ::core::clone::Clone::clone(__self_1),
},
SelectionCandidate::ClosureCandidate { is_const: __self_0 } =>
SelectionCandidate::ClosureCandidate {
is_const: ::core::clone::Clone::clone(__self_0),
},
SelectionCandidate::AsyncClosureCandidate =>
SelectionCandidate::AsyncClosureCandidate,
SelectionCandidate::AsyncFnKindHelperCandidate =>
SelectionCandidate::AsyncFnKindHelperCandidate,
SelectionCandidate::CoroutineCandidate =>
SelectionCandidate::CoroutineCandidate,
SelectionCandidate::FutureCandidate =>
SelectionCandidate::FutureCandidate,
SelectionCandidate::IteratorCandidate =>
SelectionCandidate::IteratorCandidate,
SelectionCandidate::AsyncIteratorCandidate =>
SelectionCandidate::AsyncIteratorCandidate,
SelectionCandidate::FnPointerCandidate =>
SelectionCandidate::FnPointerCandidate,
SelectionCandidate::PointerLikeCandidate =>
SelectionCandidate::PointerLikeCandidate,
SelectionCandidate::TraitAliasCandidate =>
SelectionCandidate::TraitAliasCandidate,
SelectionCandidate::ObjectCandidate(__self_0) =>
SelectionCandidate::ObjectCandidate(::core::clone::Clone::clone(__self_0)),
SelectionCandidate::TraitUpcastingUnsizeCandidate(__self_0) =>
SelectionCandidate::TraitUpcastingUnsizeCandidate(::core::clone::Clone::clone(__self_0)),
SelectionCandidate::BuiltinObjectCandidate =>
SelectionCandidate::BuiltinObjectCandidate,
SelectionCandidate::BuiltinUnsizeCandidate =>
SelectionCandidate::BuiltinUnsizeCandidate,
SelectionCandidate::BikeshedGuaranteedNoDropCandidate =>
SelectionCandidate::BikeshedGuaranteedNoDropCandidate,
}
}
}Clone, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
for SelectionCandidate<'tcx> {
fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
SelectionCandidate::SizedCandidate => {}
SelectionCandidate::BuiltinCandidate => {}
SelectionCandidate::TransmutabilityCandidate => {}
SelectionCandidate::ParamCandidate(ref __binding_0) => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
SelectionCandidate::ImplCandidate(ref __binding_0) => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
SelectionCandidate::AutoImplCandidate => {}
SelectionCandidate::ProjectionCandidate {
idx: ref __binding_0, kind: ref __binding_1 } => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
SelectionCandidate::ClosureCandidate {
is_const: ref __binding_0 } => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
SelectionCandidate::AsyncClosureCandidate => {}
SelectionCandidate::AsyncFnKindHelperCandidate => {}
SelectionCandidate::CoroutineCandidate => {}
SelectionCandidate::FutureCandidate => {}
SelectionCandidate::IteratorCandidate => {}
SelectionCandidate::AsyncIteratorCandidate => {}
SelectionCandidate::FnPointerCandidate => {}
SelectionCandidate::PointerLikeCandidate => {}
SelectionCandidate::TraitAliasCandidate => {}
SelectionCandidate::ObjectCandidate(ref __binding_0) => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
SelectionCandidate::TraitUpcastingUnsizeCandidate(ref __binding_0)
=> {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
SelectionCandidate::BuiltinObjectCandidate => {}
SelectionCandidate::BuiltinUnsizeCandidate => {}
SelectionCandidate::BikeshedGuaranteedNoDropCandidate => {}
}
<__V::Result as ::rustc_middle::ty::VisitorResult>::output()
}
}
};TypeVisitable)]
98pub enum SelectionCandidate<'tcx> {
99/// A built-in implementation for the `Sized` trait. This is preferred
100 /// over all other candidates.
101SizedCandidate,
102103/// A builtin implementation for some specific traits, used in cases
104 /// where we cannot rely an ordinary library implementations.
105 ///
106 /// The most notable examples are `Copy` and `Clone`. This is also
107 /// used for the `DiscriminantKind` and `Pointee` trait, both of which have
108 /// an associated type.
109BuiltinCandidate,
110111/// Implementation of transmutability trait.
112TransmutabilityCandidate,
113114 ParamCandidate(ty::PolyTraitPredicate<'tcx>),
115 ImplCandidate(DefId),
116 AutoImplCandidate,
117118/// This is a trait matching with a projected type as `Self`, and we found
119 /// an applicable bound in the trait definition. The `usize` is an index
120 /// into the list returned by `tcx.item_bounds` and the `AliasBoundKind`
121 /// is whether this is candidate from recursion on the self type of a
122 /// projection.
123ProjectionCandidate {
124 idx: usize,
125 kind: AliasBoundKind,
126 },
127128/// Implementation of a `Fn`-family trait by one of the anonymous types
129 /// generated for an `||` expression.
130ClosureCandidate {
131 is_const: bool,
132 },
133134/// Implementation of an `AsyncFn`-family trait by one of the anonymous types
135 /// generated for an `async ||` expression.
136AsyncClosureCandidate,
137138/// Implementation of the `AsyncFnKindHelper` helper trait, which
139 /// is used internally to delay computation for async closures until after
140 /// upvar analysis is performed in HIR typeck.
141AsyncFnKindHelperCandidate,
142143/// Implementation of a `Coroutine` trait by one of the anonymous types
144 /// generated for a coroutine.
145CoroutineCandidate,
146147/// Implementation of a `Future` trait by one of the coroutine types
148 /// generated for an async construct.
149FutureCandidate,
150151/// Implementation of an `Iterator` trait by one of the coroutine types
152 /// generated for a `gen` construct.
153IteratorCandidate,
154155/// Implementation of an `AsyncIterator` trait by one of the coroutine types
156 /// generated for a `async gen` construct.
157AsyncIteratorCandidate,
158159/// Implementation of a `Fn`-family trait by one of the anonymous
160 /// types generated for a fn pointer type (e.g., `fn(int) -> int`)
161FnPointerCandidate,
162163/// Builtin impl of the `PointerLike` trait.
164PointerLikeCandidate,
165166 TraitAliasCandidate,
167168/// Matching `dyn Trait` with a supertrait of `Trait`. The index is the
169 /// position in the iterator returned by
170 /// `rustc_infer::traits::util::supertraits`.
171ObjectCandidate(usize),
172173/// Perform trait upcasting coercion of `dyn Trait` to a supertrait of `Trait`.
174 /// The index is the position in the iterator returned by
175 /// `rustc_infer::traits::util::supertraits`.
176TraitUpcastingUnsizeCandidate(usize),
177178 BuiltinObjectCandidate,
179180 BuiltinUnsizeCandidate,
181182 BikeshedGuaranteedNoDropCandidate,
183}
184185/// The result of trait evaluation. The order is important
186/// here as the evaluation of a list is the maximum of the
187/// evaluations.
188///
189/// The evaluation results are ordered:
190/// - `EvaluatedToOk` implies `EvaluatedToOkModuloRegions`
191/// implies `EvaluatedToAmbig` implies `EvaluatedToAmbigStackDependent`
192/// - the "union" of evaluation results is equal to their maximum -
193/// all the "potential success" candidates can potentially succeed,
194/// so they are noops when unioned with a definite error, and within
195/// the categories it's easy to see that the unions are correct.
196#[derive(#[automatically_derived]
impl ::core::marker::Copy for EvaluationResult { }Copy, #[automatically_derived]
impl ::core::clone::Clone for EvaluationResult {
#[inline]
fn clone(&self) -> EvaluationResult { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for EvaluationResult {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
EvaluationResult::EvaluatedToOk => "EvaluatedToOk",
EvaluationResult::EvaluatedToOkModuloRegions =>
"EvaluatedToOkModuloRegions",
EvaluationResult::EvaluatedToOkModuloOpaqueTypes =>
"EvaluatedToOkModuloOpaqueTypes",
EvaluationResult::EvaluatedToAmbig => "EvaluatedToAmbig",
EvaluationResult::EvaluatedToAmbigStackDependent =>
"EvaluatedToAmbigStackDependent",
EvaluationResult::EvaluatedToErr => "EvaluatedToErr",
})
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialOrd for EvaluationResult {
#[inline]
fn partial_cmp(&self, other: &EvaluationResult)
-> ::core::option::Option<::core::cmp::Ordering> {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
::core::cmp::PartialOrd::partial_cmp(&__self_discr, &__arg1_discr)
}
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for EvaluationResult {
#[inline]
fn cmp(&self, other: &EvaluationResult) -> ::core::cmp::Ordering {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr)
}
}Ord, #[automatically_derived]
impl ::core::cmp::PartialEq for EvaluationResult {
#[inline]
fn eq(&self, other: &EvaluationResult) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for EvaluationResult {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) {}
}Eq, const _: () =
{
impl<'__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_query_system::ich::StableHashingContext<'__ctx>>
for EvaluationResult {
#[inline]
fn hash_stable(&self,
__hcx:
&mut ::rustc_query_system::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
match *self {
EvaluationResult::EvaluatedToOk => {}
EvaluationResult::EvaluatedToOkModuloRegions => {}
EvaluationResult::EvaluatedToOkModuloOpaqueTypes => {}
EvaluationResult::EvaluatedToAmbig => {}
EvaluationResult::EvaluatedToAmbigStackDependent => {}
EvaluationResult::EvaluatedToErr => {}
}
}
}
};HashStable)]
197pub enum EvaluationResult {
198/// Evaluation successful.
199EvaluatedToOk,
200/// Evaluation successful, but there were unevaluated region obligations.
201EvaluatedToOkModuloRegions,
202/// Evaluation successful, but need to rerun because opaque types got
203 /// hidden types assigned without it being known whether the opaque types
204 /// are within their defining scope
205EvaluatedToOkModuloOpaqueTypes,
206/// Evaluation is known to be ambiguous -- it *might* hold for some
207 /// assignment of inference variables, but it might not.
208 ///
209 /// While this has the same meaning as `EvaluatedToAmbigStackDependent` -- we can't
210 /// know whether this obligation holds or not -- it is the result we
211 /// would get with an empty stack, and therefore is cacheable.
212EvaluatedToAmbig,
213/// Evaluation failed because of recursion involving inference
214 /// variables. We are somewhat imprecise there, so we don't actually
215 /// know the real result.
216 ///
217 /// This can't be trivially cached because the result depends on the
218 /// stack results.
219EvaluatedToAmbigStackDependent,
220/// Evaluation failed.
221EvaluatedToErr,
222}
223224impl EvaluationResult {
225/// Returns `true` if this evaluation result is known to apply, even
226 /// considering outlives constraints.
227pub fn must_apply_considering_regions(self) -> bool {
228self == EvaluatedToOk229 }
230231/// Returns `true` if this evaluation result is known to apply, ignoring
232 /// outlives constraints.
233pub fn must_apply_modulo_regions(self) -> bool {
234self <= EvaluatedToOkModuloRegions235 }
236237pub fn may_apply(self) -> bool {
238match self {
239EvaluatedToOkModuloOpaqueTypes240 | EvaluatedToOk241 | EvaluatedToOkModuloRegions242 | EvaluatedToAmbig243 | EvaluatedToAmbigStackDependent => true,
244245EvaluatedToErr => false,
246 }
247 }
248249pub fn is_stack_dependent(self) -> bool {
250match self {
251EvaluatedToAmbigStackDependent => true,
252253EvaluatedToOkModuloOpaqueTypes254 | EvaluatedToOk255 | EvaluatedToOkModuloRegions256 | EvaluatedToAmbig257 | EvaluatedToErr => false,
258 }
259 }
260}
261262/// Indicates that trait evaluation caused overflow and in which pass.
263#[derive(#[automatically_derived]
impl ::core::marker::Copy for OverflowError { }Copy, #[automatically_derived]
impl ::core::clone::Clone for OverflowError {
#[inline]
fn clone(&self) -> OverflowError {
let _: ::core::clone::AssertParamIsClone<ErrorGuaranteed>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for OverflowError {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
OverflowError::Error(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Error",
&__self_0),
OverflowError::Canonical =>
::core::fmt::Formatter::write_str(f, "Canonical"),
}
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for OverflowError {
#[inline]
fn eq(&self, other: &OverflowError) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(OverflowError::Error(__self_0),
OverflowError::Error(__arg1_0)) => __self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for OverflowError {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<ErrorGuaranteed>;
}
}Eq, const _: () =
{
impl<'__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_query_system::ich::StableHashingContext<'__ctx>>
for OverflowError {
#[inline]
fn hash_stable(&self,
__hcx:
&mut ::rustc_query_system::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
match *self {
OverflowError::Error(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
OverflowError::Canonical => {}
}
}
}
};HashStable)]
264pub enum OverflowError {
265 Error(ErrorGuaranteed),
266 Canonical,
267}
268269impl From<ErrorGuaranteed> for OverflowError {
270fn from(e: ErrorGuaranteed) -> OverflowError {
271 OverflowError::Error(e)
272 }
273}
274275impl<'tcx> From<OverflowError> for SelectionError<'tcx> {
276fn from(overflow_error: OverflowError) -> SelectionError<'tcx> {
277match overflow_error {
278 OverflowError::Error(e) => SelectionError::Overflow(OverflowError::Error(e)),
279 OverflowError::Canonical => SelectionError::Overflow(OverflowError::Canonical),
280 }
281 }
282}