1use std::cell::{Cell, RefCell};
6use std::cmp;
7use std::fmt::{self, Display};
8use std::ops::ControlFlow;
9
10use hir::def::DefKind;
11use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
12use rustc_data_structures::stack::ensure_sufficient_stack;
13use rustc_errors::{Diag, EmissionGuarantee};
14use rustc_hir::def_id::DefId;
15use rustc_hir::{self as hir, LangItem, find_attr};
16use rustc_infer::infer::BoundRegionConversionTime::{self, HigherRankedType};
17use rustc_infer::infer::DefineOpaqueTypes;
18use rustc_infer::infer::at::ToTrace;
19use rustc_infer::infer::relate::TypeRelation;
20use rustc_infer::traits::{PredicateObligations, TraitObligation};
21use rustc_macros::{TypeFoldable, TypeVisitable};
22use rustc_middle::bug;
23use rustc_middle::dep_graph::{DepKind, DepNodeIndex};
24pub use rustc_middle::traits::select::*;
25use rustc_middle::ty::abstract_const::NotConstEvaluatable;
26use rustc_middle::ty::error::TypeErrorToStringExt;
27use rustc_middle::ty::print::{PrintTraitRefExt as _, with_no_trimmed_paths};
28use rustc_middle::ty::{
29 self, CandidatePreferenceMode, CantBeErased, DeepRejectCtxt, GenericArgsRef,
30 PolyProjectionPredicate, SizedTraitKind, Ty, TyCtxt, TypeFoldable, TypeVisitableExt,
31 TypingMode, Unnormalized, Upcast, elaborate, may_use_unstable_feature,
32};
33use rustc_next_trait_solver::solve::AliasBoundKind;
34use rustc_span::Symbol;
35use tracing::{debug, instrument, trace};
36
37use self::EvaluationResult::*;
38use self::SelectionCandidate::*;
39use super::coherence::{self, Conflict};
40use super::project::ProjectionTermObligation;
41use super::util::closure_trait_ref_and_return_type;
42use super::{
43 ImplDerivedCause, Normalized, Obligation, ObligationCause, ObligationCauseCode,
44 PolyTraitObligation, PredicateObligation, Selection, SelectionError, SelectionResult,
45 TraitQueryMode, const_evaluatable, project, util, wf,
46};
47use crate::error_reporting::InferCtxtErrorExt;
48use crate::infer::{InferCtxt, InferOk, TypeFreshener};
49use crate::solve::InferCtxtSelectExt as _;
50use crate::traits::normalize::{normalize_with_depth, normalize_with_depth_to};
51use crate::traits::project::{ProjectAndUnifyResult, ProjectionCacheKeyExt};
52use crate::traits::{EvaluateConstErr, ProjectionCacheKey, effects, sizedness_fast_path};
53
54mod _match;
55mod candidate_assembly;
56mod confirmation;
57
58#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for IntercrateAmbiguityCause<'tcx> {
#[inline]
fn clone(&self) -> IntercrateAmbiguityCause<'tcx> {
match self {
IntercrateAmbiguityCause::DownstreamCrate {
trait_ref: __self_0, self_ty: __self_1 } =>
IntercrateAmbiguityCause::DownstreamCrate {
trait_ref: ::core::clone::Clone::clone(__self_0),
self_ty: ::core::clone::Clone::clone(__self_1),
},
IntercrateAmbiguityCause::UpstreamCrateUpdate {
trait_ref: __self_0, self_ty: __self_1 } =>
IntercrateAmbiguityCause::UpstreamCrateUpdate {
trait_ref: ::core::clone::Clone::clone(__self_0),
self_ty: ::core::clone::Clone::clone(__self_1),
},
IntercrateAmbiguityCause::ReservationImpl { message: __self_0 } =>
IntercrateAmbiguityCause::ReservationImpl {
message: ::core::clone::Clone::clone(__self_0),
},
}
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for IntercrateAmbiguityCause<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
IntercrateAmbiguityCause::DownstreamCrate {
trait_ref: __self_0, self_ty: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"DownstreamCrate", "trait_ref", __self_0, "self_ty",
&__self_1),
IntercrateAmbiguityCause::UpstreamCrateUpdate {
trait_ref: __self_0, self_ty: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"UpstreamCrateUpdate", "trait_ref", __self_0, "self_ty",
&__self_1),
IntercrateAmbiguityCause::ReservationImpl { message: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"ReservationImpl", "message", &__self_0),
}
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for IntercrateAmbiguityCause<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<ty::TraitRef<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<Option<Ty<'tcx>>>;
let _: ::core::cmp::AssertParamIsEq<ty::TraitRef<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<Option<Ty<'tcx>>>;
let _: ::core::cmp::AssertParamIsEq<Symbol>;
}
}Eq, #[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for IntercrateAmbiguityCause<'tcx> {
#[inline]
fn eq(&self, other: &IntercrateAmbiguityCause<'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) {
(IntercrateAmbiguityCause::DownstreamCrate {
trait_ref: __self_0, self_ty: __self_1 },
IntercrateAmbiguityCause::DownstreamCrate {
trait_ref: __arg1_0, self_ty: __arg1_1 }) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(IntercrateAmbiguityCause::UpstreamCrateUpdate {
trait_ref: __self_0, self_ty: __self_1 },
IntercrateAmbiguityCause::UpstreamCrateUpdate {
trait_ref: __arg1_0, self_ty: __arg1_1 }) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(IntercrateAmbiguityCause::ReservationImpl { message: __self_0
}, IntercrateAmbiguityCause::ReservationImpl {
message: __arg1_0 }) => __self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::hash::Hash for IntercrateAmbiguityCause<'tcx> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state);
match self {
IntercrateAmbiguityCause::DownstreamCrate {
trait_ref: __self_0, self_ty: __self_1 } => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
IntercrateAmbiguityCause::UpstreamCrateUpdate {
trait_ref: __self_0, self_ty: __self_1 } => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
IntercrateAmbiguityCause::ReservationImpl { message: __self_0 } =>
::core::hash::Hash::hash(__self_0, state),
}
}
}Hash)]
59pub enum IntercrateAmbiguityCause<'tcx> {
60 DownstreamCrate { trait_ref: ty::TraitRef<'tcx>, self_ty: Option<Ty<'tcx>> },
61 UpstreamCrateUpdate { trait_ref: ty::TraitRef<'tcx>, self_ty: Option<Ty<'tcx>> },
62 ReservationImpl { message: Symbol },
63}
64
65impl<'tcx> IntercrateAmbiguityCause<'tcx> {
66 pub fn add_intercrate_ambiguity_hint<G: EmissionGuarantee>(&self, err: &mut Diag<'_, G>) {
69 err.note(self.intercrate_ambiguity_hint());
70 }
71
72 pub fn intercrate_ambiguity_hint(&self) -> String {
73 {
let _guard = NoTrimmedGuard::new();
match self {
IntercrateAmbiguityCause::DownstreamCrate { trait_ref, self_ty } => {
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("downstream crates may implement trait `{0}`{1}",
trait_ref.print_trait_sugared(),
if let Some(self_ty) = self_ty {
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" for type `{0}`",
self_ty))
})
} else { String::new() }))
})
}
IntercrateAmbiguityCause::UpstreamCrateUpdate { trait_ref, self_ty }
=> {
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("upstream crates may add a new impl of trait `{0}`{1} in future versions",
trait_ref.print_trait_sugared(),
if let Some(self_ty) = self_ty {
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" for type `{0}`",
self_ty))
})
} else { String::new() }))
})
}
IntercrateAmbiguityCause::ReservationImpl { message } =>
message.to_string(),
}
}with_no_trimmed_paths!(match self {
74 IntercrateAmbiguityCause::DownstreamCrate { trait_ref, self_ty } => {
75 format!(
76 "downstream crates may implement trait `{trait_desc}`{self_desc}",
77 trait_desc = trait_ref.print_trait_sugared(),
78 self_desc = if let Some(self_ty) = self_ty {
79 format!(" for type `{self_ty}`")
80 } else {
81 String::new()
82 }
83 )
84 }
85 IntercrateAmbiguityCause::UpstreamCrateUpdate { trait_ref, self_ty } => {
86 format!(
87 "upstream crates may add a new impl of trait `{trait_desc}`{self_desc} \
88 in future versions",
89 trait_desc = trait_ref.print_trait_sugared(),
90 self_desc = if let Some(self_ty) = self_ty {
91 format!(" for type `{self_ty}`")
92 } else {
93 String::new()
94 }
95 )
96 }
97 IntercrateAmbiguityCause::ReservationImpl { message } => message.to_string(),
98 })
99 }
100}
101
102pub struct SelectionContext<'cx, 'tcx> {
103 pub infcx: &'cx InferCtxt<'tcx>,
104
105 freshener: TypeFreshener<'cx, 'tcx>,
111
112 intercrate_ambiguity_causes: Option<FxIndexSet<IntercrateAmbiguityCause<'tcx>>>,
119
120 query_mode: TraitQueryMode,
124}
125
126struct TraitObligationStack<'prev, 'tcx> {
128 obligation: &'prev PolyTraitObligation<'tcx>,
129
130 fresh_trait_pred: ty::PolyTraitPredicate<'tcx>,
133
134 reached_depth: Cell<usize>,
163
164 previous: TraitObligationStackList<'prev, 'tcx>,
165
166 depth: usize,
168
169 dfn: usize,
172}
173
174struct SelectionCandidateSet<'tcx> {
175 vec: Vec<SelectionCandidate<'tcx>>,
178
179 ambiguous: bool,
184}
185
186#[derive(#[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for EvaluatedCandidate<'tcx> {
#[inline]
fn eq(&self, other: &EvaluatedCandidate<'tcx>) -> bool {
self.candidate == other.candidate &&
self.evaluation == other.evaluation
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for EvaluatedCandidate<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<SelectionCandidate<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<EvaluationResult>;
}
}Eq, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for EvaluatedCandidate<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"EvaluatedCandidate", "candidate", &self.candidate, "evaluation",
&&self.evaluation)
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for EvaluatedCandidate<'tcx> {
#[inline]
fn clone(&self) -> EvaluatedCandidate<'tcx> {
EvaluatedCandidate {
candidate: ::core::clone::Clone::clone(&self.candidate),
evaluation: ::core::clone::Clone::clone(&self.evaluation),
}
}
}Clone)]
187struct EvaluatedCandidate<'tcx> {
188 candidate: SelectionCandidate<'tcx>,
189 evaluation: EvaluationResult,
190}
191
192impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
193 pub fn new(infcx: &'cx InferCtxt<'tcx>) -> SelectionContext<'cx, 'tcx> {
194 SelectionContext {
195 infcx,
196 freshener: TypeFreshener::new(infcx),
197 intercrate_ambiguity_causes: None,
198 query_mode: TraitQueryMode::Standard,
199 }
200 }
201
202 pub fn typing_mode(&self) -> TypingMode<'tcx, CantBeErased> {
203 self.infcx.typing_mode_raw().assert_not_erased()
204 }
205
206 pub fn with_query_mode(
207 infcx: &'cx InferCtxt<'tcx>,
208 query_mode: TraitQueryMode,
209 ) -> SelectionContext<'cx, 'tcx> {
210 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:210",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(210u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("query_mode")
}> =
::tracing::__macro_support::FieldName::new("query_mode");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("with_query_mode")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&query_mode)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?query_mode, "with_query_mode");
211 SelectionContext { query_mode, ..SelectionContext::new(infcx) }
212 }
213
214 pub fn enable_tracking_intercrate_ambiguity_causes(&mut self) {
217 if !self.typing_mode().is_coherence() {
::core::panicking::panic("assertion failed: self.typing_mode().is_coherence()")
};assert!(self.typing_mode().is_coherence());
218 if !self.intercrate_ambiguity_causes.is_none() {
::core::panicking::panic("assertion failed: self.intercrate_ambiguity_causes.is_none()")
};assert!(self.intercrate_ambiguity_causes.is_none());
219
220 self.intercrate_ambiguity_causes = Some(FxIndexSet::default());
221 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:221",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(221u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("selcx: enable_tracking_intercrate_ambiguity_causes")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("selcx: enable_tracking_intercrate_ambiguity_causes");
222 }
223
224 pub fn take_intercrate_ambiguity_causes(
228 &mut self,
229 ) -> FxIndexSet<IntercrateAmbiguityCause<'tcx>> {
230 if !self.typing_mode().is_coherence() {
::core::panicking::panic("assertion failed: self.typing_mode().is_coherence()")
};assert!(self.typing_mode().is_coherence());
231
232 self.intercrate_ambiguity_causes.take().unwrap_or_default()
233 }
234
235 pub fn tcx(&self) -> TyCtxt<'tcx> {
236 self.infcx.tcx
237 }
238
239 x;#[instrument(level = "debug", skip(self), ret)]
257 pub fn poly_select(
258 &mut self,
259 obligation: &PolyTraitObligation<'tcx>,
260 ) -> SelectionResult<'tcx, Selection<'tcx>> {
261 assert!(!self.infcx.next_trait_solver());
262
263 let candidate = match self.select_from_obligation(obligation) {
264 Err(SelectionError::Overflow(OverflowError::Canonical)) => {
265 assert!(self.query_mode == TraitQueryMode::Canonical);
268 return Err(SelectionError::Overflow(OverflowError::Canonical));
269 }
270 Err(e) => {
271 return Err(e);
272 }
273 Ok(None) => {
274 return Ok(None);
275 }
276 Ok(Some(candidate)) => candidate,
277 };
278
279 match self.confirm_candidate(obligation, candidate) {
280 Err(SelectionError::Overflow(OverflowError::Canonical)) => {
281 assert!(self.query_mode == TraitQueryMode::Canonical);
282 Err(SelectionError::Overflow(OverflowError::Canonical))
283 }
284 Err(e) => Err(e),
285 Ok(candidate) => Ok(Some(candidate)),
286 }
287 }
288
289 pub fn select(
290 &mut self,
291 obligation: &TraitObligation<'tcx>,
292 ) -> SelectionResult<'tcx, Selection<'tcx>> {
293 if self.infcx.next_trait_solver() {
294 return self.infcx.select_in_new_trait_solver(obligation);
295 }
296
297 self.poly_select(&Obligation {
298 cause: obligation.cause.clone(),
299 param_env: obligation.param_env,
300 predicate: ty::Binder::dummy(obligation.predicate),
301 recursion_depth: obligation.recursion_depth,
302 })
303 }
304
305 fn select_from_obligation(
306 &mut self,
307 obligation: &PolyTraitObligation<'tcx>,
308 ) -> SelectionResult<'tcx, SelectionCandidate<'tcx>> {
309 if true {
if !!obligation.predicate.has_escaping_bound_vars() {
::core::panicking::panic("assertion failed: !obligation.predicate.has_escaping_bound_vars()")
};
};debug_assert!(!obligation.predicate.has_escaping_bound_vars());
310
311 let pec = &ProvisionalEvaluationCache::default();
312 let stack = self.push_stack(TraitObligationStackList::empty(pec), obligation);
313
314 self.candidate_from_obligation(&stack)
315 }
316
317 x;#[instrument(level = "debug", skip(self), ret)]
318 fn candidate_from_obligation<'o>(
319 &mut self,
320 stack: &TraitObligationStack<'o, 'tcx>,
321 ) -> SelectionResult<'tcx, SelectionCandidate<'tcx>> {
322 debug_assert!(!self.infcx.next_trait_solver());
323 self.check_recursion_limit(stack.obligation, stack.obligation)?;
326
327 let cache_fresh_trait_pred =
332 stack.obligation.predicate.fold_with(&mut TypeFreshener::new(self.infcx));
333 debug!(?cache_fresh_trait_pred);
334 debug_assert!(!stack.obligation.predicate.has_escaping_bound_vars());
335
336 if let Some(c) =
337 self.check_candidate_cache(stack.obligation.param_env, cache_fresh_trait_pred)
338 {
339 debug!("CACHE HIT");
340 return c;
341 }
342
343 let (candidate, dep_node) =
350 self.in_task(|this| this.candidate_from_obligation_no_cache(stack));
351
352 debug!("CACHE MISS");
353 self.insert_candidate_cache(
354 stack.obligation.param_env,
355 cache_fresh_trait_pred,
356 dep_node,
357 candidate.clone(),
358 );
359 candidate
360 }
361
362 fn candidate_from_obligation_no_cache<'o>(
363 &mut self,
364 stack: &TraitObligationStack<'o, 'tcx>,
365 ) -> SelectionResult<'tcx, SelectionCandidate<'tcx>> {
366 if let Err(conflict) = self.is_knowable(stack) {
367 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:367",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(367u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("coherence stage: not knowable")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("coherence stage: not knowable");
368 if self.intercrate_ambiguity_causes.is_some() {
369 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:369",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(369u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("evaluate_stack: intercrate_ambiguity_causes is some")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("evaluate_stack: intercrate_ambiguity_causes is some");
370 if let Ok(candidate_set) = self.assemble_candidates(stack) {
372 let mut no_candidates_apply = true;
373
374 for c in candidate_set.vec.iter() {
375 if self.evaluate_candidate(stack, c)?.may_apply() {
376 no_candidates_apply = false;
377 break;
378 }
379 }
380
381 if !candidate_set.ambiguous && no_candidates_apply {
382 let trait_ref = self.infcx.resolve_vars_if_possible(
383 stack.obligation.predicate.skip_binder().trait_ref,
384 );
385 if !trait_ref.references_error() {
386 let self_ty = trait_ref.self_ty();
387 let self_ty = self_ty.has_concrete_skeleton().then(|| self_ty);
388 let cause = if let Conflict::Upstream = conflict {
389 IntercrateAmbiguityCause::UpstreamCrateUpdate { trait_ref, self_ty }
390 } else {
391 IntercrateAmbiguityCause::DownstreamCrate { trait_ref, self_ty }
392 };
393 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:393",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(393u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("cause")
}> =
::tracing::__macro_support::FieldName::new("cause");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("evaluate_stack: pushing cause")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&cause)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?cause, "evaluate_stack: pushing cause");
394 self.intercrate_ambiguity_causes.as_mut().unwrap().insert(cause);
395 }
396 }
397 }
398 }
399 return Ok(None);
400 }
401
402 let candidate_set = self.assemble_candidates(stack)?;
403
404 if candidate_set.ambiguous {
405 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:405",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(405u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("candidate set contains ambig")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("candidate set contains ambig");
406 return Ok(None);
407 }
408
409 let candidates = candidate_set.vec;
410
411 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:411",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(411u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("stack")
}> =
::tracing::__macro_support::FieldName::new("stack");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("candidates")
}> =
::tracing::__macro_support::FieldName::new("candidates");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("assembled {0} candidates",
candidates.len()) as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&stack)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidates)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?stack, ?candidates, "assembled {} candidates", candidates.len());
412
413 let mut candidates = self.filter_impls(candidates, stack.obligation);
423
424 if candidates.len() == 1 {
439 return self.filter_reservation_impls(candidates.pop().unwrap());
440 }
441
442 let candidates = candidates
445 .into_iter()
446 .map(|c| match self.evaluate_candidate(stack, &c) {
447 Ok(eval) if eval.may_apply() => {
448 Ok(Some(EvaluatedCandidate { candidate: c, evaluation: eval }))
449 }
450 Ok(_) => Ok(None),
451 Err(OverflowError::Canonical) => {
452 Err(SelectionError::Overflow(OverflowError::Canonical))
453 }
454 Err(OverflowError::Error(e)) => {
455 Err(SelectionError::Overflow(OverflowError::Error(e)))
456 }
457 })
458 .flat_map(Result::transpose)
459 .collect::<Result<Vec<_>, _>>()?;
460
461 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:461",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(461u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("stack")
}> =
::tracing::__macro_support::FieldName::new("stack");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("candidates")
}> =
::tracing::__macro_support::FieldName::new("candidates");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("{0} potentially applicable candidates",
candidates.len()) as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&stack)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidates)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?stack, ?candidates, "{} potentially applicable candidates", candidates.len());
462 if candidates.is_empty() {
472 if stack.obligation.predicate.references_error() {
477 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:477",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(477u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("stack.obligation.predicate")
}> =
::tracing::__macro_support::FieldName::new("stack.obligation.predicate");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("found error type in predicate, treating as ambiguous")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&stack.obligation.predicate)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?stack.obligation.predicate, "found error type in predicate, treating as ambiguous");
478 Ok(None)
479 } else {
480 Err(SelectionError::Unimplemented)
481 }
482 } else {
483 let has_non_region_infer = stack.obligation.predicate.has_non_region_infer();
484 let candidate_preference_mode =
485 CandidatePreferenceMode::compute(self.tcx(), stack.obligation.predicate.def_id());
486 if let Some(candidate) =
487 self.winnow_candidates(has_non_region_infer, candidate_preference_mode, candidates)
488 {
489 self.filter_reservation_impls(candidate)
490 } else {
491 Ok(None)
492 }
493 }
494 }
495
496 pub fn evaluate_root_obligation(
512 &mut self,
513 obligation: &PredicateObligation<'tcx>,
514 ) -> Result<EvaluationResult, OverflowError> {
515 if true {
if !!self.infcx.next_trait_solver() {
::core::panicking::panic("assertion failed: !self.infcx.next_trait_solver()")
};
};debug_assert!(!self.infcx.next_trait_solver());
516 self.evaluation_probe(|this| {
517 let goal =
518 this.infcx.resolve_vars_if_possible((obligation.predicate, obligation.param_env));
519 let mut result = this.evaluate_predicate_recursively(
520 TraitObligationStackList::empty(&ProvisionalEvaluationCache::default()),
521 obligation.clone(),
522 )?;
523 if this.infcx.resolve_vars_if_possible(goal) != goal {
526 result = result.max(EvaluatedToAmbig);
527 }
528 Ok(result)
529 })
530 }
531
532 fn evaluation_probe(
538 &mut self,
539 op: impl FnOnce(&mut Self) -> Result<EvaluationResult, OverflowError>,
540 ) -> Result<EvaluationResult, OverflowError> {
541 self.infcx.probe(|snapshot| -> Result<EvaluationResult, OverflowError> {
542 let outer_universe = self.infcx.universe();
543 let result = op(self)?;
544
545 match self.infcx.leak_check(outer_universe, Some(snapshot)) {
546 Ok(()) => {}
547 Err(_) => return Ok(EvaluatedToErr),
548 }
549
550 if self.infcx.opaque_types_added_in_snapshot(snapshot) {
551 return Ok(result.max(EvaluatedToOkModuloOpaqueTypes));
552 }
553
554 if self.infcx.region_constraints_added_in_snapshot(snapshot) {
555 Ok(result.max(EvaluatedToOkModuloRegions))
556 } else {
557 Ok(result)
558 }
559 })
560 }
561
562 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("evaluate_predicates_recursively",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(566u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("predicates")
}> =
::tracing::__macro_support::FieldName::new("predicates");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&predicates)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
Result<EvaluationResult, OverflowError> = loop {};
return __tracing_attr_fake_return;
}
{
let mut result = EvaluatedToOk;
for mut obligation in predicates {
obligation.set_depth_from_parent(stack.depth());
let eval =
self.evaluate_predicate_recursively(stack,
obligation.clone())?;
if let EvaluatedToErr = eval {
return Ok(EvaluatedToErr);
} else { result = cmp::max(result, eval); }
}
Ok(result)
}
}
}#[instrument(skip(self, stack), level = "debug")]
567 fn evaluate_predicates_recursively<'o, I>(
568 &mut self,
569 stack: TraitObligationStackList<'o, 'tcx>,
570 predicates: I,
571 ) -> Result<EvaluationResult, OverflowError>
572 where
573 I: IntoIterator<Item = PredicateObligation<'tcx>> + std::fmt::Debug,
574 {
575 let mut result = EvaluatedToOk;
576 for mut obligation in predicates {
577 obligation.set_depth_from_parent(stack.depth());
578 let eval = self.evaluate_predicate_recursively(stack, obligation.clone())?;
579 if let EvaluatedToErr = eval {
580 return Ok(EvaluatedToErr);
583 } else {
584 result = cmp::max(result, eval);
585 }
586 }
587 Ok(result)
588 }
589
590 x;#[instrument(
591 level = "debug",
592 skip(self, previous_stack),
593 fields(previous_stack = ?previous_stack.head())
594 ret,
595 )]
596 fn evaluate_predicate_recursively<'o>(
597 &mut self,
598 previous_stack: TraitObligationStackList<'o, 'tcx>,
599 obligation: PredicateObligation<'tcx>,
600 ) -> Result<EvaluationResult, OverflowError> {
601 debug_assert!(!self.infcx.next_trait_solver());
602 match previous_stack.head() {
607 Some(h) => self.check_recursion_limit(&obligation, h.obligation)?,
608 None => self.check_recursion_limit(&obligation, &obligation)?,
609 }
610
611 if !self.infcx.disable_trait_solver_fast_paths()
612 && sizedness_fast_path(self.tcx(), obligation.predicate, obligation.param_env)
613 {
614 return Ok(EvaluatedToOk);
615 }
616
617 ensure_sufficient_stack(|| {
618 let bound_predicate = obligation.predicate.kind();
619 match bound_predicate.skip_binder() {
620 ty::PredicateKind::Clause(ty::ClauseKind::Trait(t)) => {
621 let t = bound_predicate.rebind(t);
622 debug_assert!(!t.has_escaping_bound_vars());
623 let obligation = obligation.with(self.tcx(), t);
624 self.evaluate_trait_predicate_recursively(previous_stack, obligation)
625 }
626
627 ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(data)) => {
628 self.infcx.enter_forall(bound_predicate.rebind(data), |data| {
629 match effects::evaluate_host_effect_obligation(
630 self,
631 &obligation.with(self.tcx(), data),
632 ) {
633 Ok(nested) => {
634 self.evaluate_predicates_recursively(previous_stack, nested)
635 }
636 Err(effects::EvaluationFailure::Ambiguous) => Ok(EvaluatedToAmbig),
637 Err(effects::EvaluationFailure::NoSolution) => Ok(EvaluatedToErr),
638 }
639 })
640 }
641
642 ty::PredicateKind::Subtype(p) => {
643 let p = bound_predicate.rebind(p);
644 match self.infcx.subtype_predicate(&obligation.cause, obligation.param_env, p) {
646 Ok(Ok(InferOk { obligations, .. })) => {
647 self.evaluate_predicates_recursively(previous_stack, obligations)
648 }
649 Ok(Err(_)) => Ok(EvaluatedToErr),
650 Err(..) => Ok(EvaluatedToAmbig),
651 }
652 }
653
654 ty::PredicateKind::Coerce(p) => {
655 let p = bound_predicate.rebind(p);
656 match self.infcx.coerce_predicate(&obligation.cause, obligation.param_env, p) {
658 Ok(Ok(InferOk { obligations, .. })) => {
659 self.evaluate_predicates_recursively(previous_stack, obligations)
660 }
661 Ok(Err(_)) => Ok(EvaluatedToErr),
662 Err(..) => Ok(EvaluatedToAmbig),
663 }
664 }
665
666 ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(term)) => {
667 if term.is_trivially_wf(self.tcx()) {
668 return Ok(EvaluatedToOk);
669 }
670
671 let cache = previous_stack.cache;
692 let dfn = cache.next_dfn();
693
694 for stack_term in previous_stack.cache.wf_args.borrow().iter().rev() {
695 if stack_term.0 != term {
696 continue;
697 }
698 debug!("WellFormed({:?}) on stack", term);
699 if let Some(stack) = previous_stack.head {
700 let cycle = stack.iter().take_while(|s| s.depth > stack_term.1);
715 let tcx = self.tcx();
716 let cycle = cycle.map(|stack| stack.obligation.predicate.upcast(tcx));
717 if self.coinductive_match(cycle) {
718 stack.update_reached_depth(stack_term.1);
719 return Ok(EvaluatedToOk);
720 } else {
721 return Ok(EvaluatedToAmbigStackDependent);
722 }
723 }
724 return Ok(EvaluatedToOk);
725 }
726
727 match wf::obligations(
728 self.infcx,
729 obligation.param_env,
730 obligation.cause.body_def_id,
731 obligation.recursion_depth + 1,
732 term,
733 obligation.cause.span,
734 ) {
735 Some(obligations) => {
736 cache.wf_args.borrow_mut().push((term, previous_stack.depth()));
737 let result =
738 self.evaluate_predicates_recursively(previous_stack, obligations);
739 cache.wf_args.borrow_mut().pop();
740
741 let result = result?;
742
743 if !result.must_apply_modulo_regions() {
744 cache.on_failure(dfn);
745 }
746
747 cache.on_completion(dfn);
748
749 Ok(result)
750 }
751 None => Ok(EvaluatedToAmbig),
752 }
753 }
754
755 ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(pred)) => {
756 if pred.0.has_free_regions()
759 || pred.0.has_bound_regions()
760 || pred.0.has_non_region_infer()
761 || pred.0.has_non_region_param()
762 {
763 Ok(EvaluatedToOkModuloRegions)
764 } else {
765 Ok(EvaluatedToOk)
766 }
767 }
768
769 ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(..)) => {
770 Ok(EvaluatedToOkModuloRegions)
772 }
773
774 ty::PredicateKind::DynCompatible(trait_def_id) => {
775 if self.tcx().is_dyn_compatible(trait_def_id) {
780 Ok(EvaluatedToOk)
781 } else {
782 Ok(EvaluatedToErr)
783 }
784 }
785
786 ty::PredicateKind::Clause(ty::ClauseKind::Projection(data)) => {
787 let data = bound_predicate.rebind(data);
788 let project_obligation = obligation.with(self.tcx(), data);
789 match project::poly_project_and_unify_term(self, &project_obligation) {
790 ProjectAndUnifyResult::Holds(mut subobligations) => {
791 'compute_res: {
792 if let Some(key) =
797 ProjectionCacheKey::from_poly_projection_obligation(
798 self,
799 &project_obligation,
800 )
801 && let Some(cached_res) = self
802 .infcx
803 .inner
804 .borrow_mut()
805 .projection_cache()
806 .is_complete(key)
807 {
808 break 'compute_res Ok(cached_res);
809 }
810
811 for subobligation in subobligations.iter_mut() {
817 subobligation.set_depth_from_parent(obligation.recursion_depth);
818 }
819 let res = self.evaluate_predicates_recursively(
820 previous_stack,
821 subobligations,
822 );
823 if let Ok(eval_rslt) = res
824 && (eval_rslt == EvaluatedToOk
825 || eval_rslt == EvaluatedToOkModuloRegions)
826 && let Some(key) =
827 ProjectionCacheKey::from_poly_projection_obligation(
828 self,
829 &project_obligation,
830 )
831 {
832 self.infcx
837 .inner
838 .borrow_mut()
839 .projection_cache()
840 .complete(key, eval_rslt);
841 }
842 res
843 }
844 }
845 ProjectAndUnifyResult::FailedNormalization => Ok(EvaluatedToAmbig),
846 ProjectAndUnifyResult::Recursive => Ok(EvaluatedToAmbigStackDependent),
847 ProjectAndUnifyResult::MismatchedProjectionTypes(_) => Ok(EvaluatedToErr),
848 }
849 }
850
851 ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(symbol)) => {
852 if may_use_unstable_feature(self.infcx, obligation.param_env, symbol) {
853 Ok(EvaluatedToOk)
854 } else {
855 Ok(EvaluatedToAmbig)
856 }
857 }
858
859 ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(alias_const)) => {
860 match const_evaluatable::is_const_evaluatable(
861 self.infcx,
862 alias_const,
863 obligation.param_env,
864 obligation.cause.span,
865 ) {
866 Ok(()) => Ok(EvaluatedToOk),
867 Err(NotConstEvaluatable::MentionsInfer) => Ok(EvaluatedToAmbig),
868 Err(NotConstEvaluatable::MentionsParam) => Ok(EvaluatedToErr),
869 Err(_) => Ok(EvaluatedToErr),
870 }
871 }
872
873 ty::PredicateKind::ConstEquate(c1, c2) => {
874 let tcx = self.tcx();
875 assert!(
876 tcx.features().generic_const_exprs(),
877 "`ConstEquate` without a feature gate: {c1:?} {c2:?}",
878 );
879
880 {
881 let c1 = tcx.expand_abstract_consts(c1);
882 let c2 = tcx.expand_abstract_consts(c2);
883 debug!(
884 "evaluate_predicate_recursively: equating consts:\nc1= {:?}\nc2= {:?}",
885 c1, c2
886 );
887
888 match (c1.kind(), c2.kind()) {
889 (ty::ConstKind::Alias(_, a), ty::ConstKind::Alias(_, b))
890 if a.kind == b.kind
891 && matches!(
892 a.kind,
893 ty::AliasConstKind::Projection { .. }
894 | ty::AliasConstKind::Inherent { .. }
895 ) =>
896 {
897 if let Ok(InferOk { obligations, value: () }) = self
898 .infcx
899 .at(&obligation.cause, obligation.param_env)
900 .eq(
903 DefineOpaqueTypes::Yes,
904 ty::AliasTerm::from(a),
905 ty::AliasTerm::from(b),
906 )
907 {
908 return self.evaluate_predicates_recursively(
909 previous_stack,
910 obligations,
911 );
912 }
913 }
914 (_, ty::ConstKind::Alias(_, _)) | (ty::ConstKind::Alias(_, _), _) => (),
915 (_, _) => {
916 if let Ok(InferOk { obligations, value: () }) = self
917 .infcx
918 .at(&obligation.cause, obligation.param_env)
919 .eq(DefineOpaqueTypes::Yes, c1, c2)
922 {
923 return self.evaluate_predicates_recursively(
924 previous_stack,
925 obligations,
926 );
927 }
928 }
929 }
930 }
931
932 let evaluate = |c: ty::Const<'tcx>| {
933 if let ty::ConstKind::Alias(_, _) = c.kind() {
934 match crate::traits::try_evaluate_const(
935 self.infcx,
936 c,
937 obligation.param_env,
938 ) {
939 Ok(val) => Ok(val),
940 Err(e) => Err(e),
941 }
942 } else {
943 Ok(c)
944 }
945 };
946
947 match (evaluate(c1), evaluate(c2)) {
948 (Ok(c1), Ok(c2)) => {
949 match self.infcx.at(&obligation.cause, obligation.param_env).eq(
950 DefineOpaqueTypes::Yes,
953 c1,
954 c2,
955 ) {
956 Ok(inf_ok) => self.evaluate_predicates_recursively(
957 previous_stack,
958 inf_ok.into_obligations(),
959 ),
960 Err(_) => Ok(EvaluatedToErr),
961 }
962 }
963 (Err(EvaluateConstErr::InvalidConstParamTy(..)), _)
964 | (_, Err(EvaluateConstErr::InvalidConstParamTy(..))) => Ok(EvaluatedToErr),
965 (Err(EvaluateConstErr::EvaluationFailure(..)), _)
966 | (_, Err(EvaluateConstErr::EvaluationFailure(..))) => Ok(EvaluatedToErr),
967 (Err(EvaluateConstErr::HasGenericsOrInfers), _)
968 | (_, Err(EvaluateConstErr::HasGenericsOrInfers)) => {
969 if c1.has_non_region_infer() || c2.has_non_region_infer() {
970 Ok(EvaluatedToAmbig)
971 } else {
972 Ok(EvaluatedToErr)
974 }
975 }
976 }
977 }
978 ty::PredicateKind::NormalizesTo(..) => {
979 bug!("NormalizesTo is only used by the new solver")
980 }
981 ty::PredicateKind::Ambiguous => Ok(EvaluatedToAmbig),
982 ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
983 let ct = self.infcx.shallow_resolve_const(ct);
984 let ct_ty = match ct.kind() {
985 ty::ConstKind::Infer(_) => {
986 return Ok(EvaluatedToAmbig);
987 }
988 ty::ConstKind::Error(_) => return Ok(EvaluatedToOk),
989 ty::ConstKind::Value(cv) => cv.ty,
990 ty::ConstKind::Alias(_, alias_const) => {
991 alias_const.type_of(self.tcx()).skip_norm_wip()
992 }
993 ty::ConstKind::Expr(_) => return Ok(EvaluatedToOk),
995 ty::ConstKind::Placeholder(_) => {
996 bug!("placeholder const {:?} in old solver", ct)
997 }
998 ty::ConstKind::Bound(_, _) => bug!("escaping bound vars in {:?}", ct),
999 ty::ConstKind::Param(param_ct) => {
1000 param_ct.find_const_ty_from_env(obligation.param_env)
1001 }
1002 };
1003
1004 match self.infcx.at(&obligation.cause, obligation.param_env).eq(
1005 DefineOpaqueTypes::Yes,
1007 ct_ty,
1008 ty,
1009 ) {
1010 Ok(inf_ok) => self.evaluate_predicates_recursively(
1011 previous_stack,
1012 inf_ok.into_obligations(),
1013 ),
1014 Err(_) => Ok(EvaluatedToErr),
1015 }
1016 }
1017 }
1018 })
1019 }
1020
1021 x;#[instrument(skip(self, previous_stack), level = "debug", ret)]
1022 fn evaluate_trait_predicate_recursively<'o>(
1023 &mut self,
1024 previous_stack: TraitObligationStackList<'o, 'tcx>,
1025 mut obligation: PolyTraitObligation<'tcx>,
1026 ) -> Result<EvaluationResult, OverflowError> {
1027 if !self.typing_mode().is_coherence()
1028 && obligation.is_global()
1029 && obligation.param_env.caller_bounds().iter().all(|bound| bound.has_param())
1030 {
1031 debug!("in global");
1035 obligation.param_env = ty::ParamEnv::empty();
1036 }
1037
1038 let stack = self.push_stack(previous_stack, &obligation);
1039 let fresh_trait_pred = stack.fresh_trait_pred;
1040 let param_env = obligation.param_env;
1041
1042 debug!(?fresh_trait_pred);
1043
1044 if let Some(result) = self.check_evaluation_cache(param_env, fresh_trait_pred) {
1047 debug!("CACHE HIT");
1048 return Ok(result);
1049 }
1050
1051 if let Some(result) = stack.cache().get_provisional(fresh_trait_pred) {
1052 debug!("PROVISIONAL CACHE HIT");
1053 stack.update_reached_depth(result.reached_depth);
1054 return Ok(result.result);
1055 }
1056
1057 if let Some(cycle_result) = self.check_evaluation_cycle(&stack) {
1063 return Ok(cycle_result);
1064 }
1065
1066 let (result, dep_node) = self.in_task(|this| {
1067 let mut result = this.evaluate_stack(&stack)?;
1068
1069 if EvaluationResult::EvaluatedToErr == result
1077 && fresh_trait_pred.has_aliases()
1078 && fresh_trait_pred.is_global()
1079 {
1080 let mut nested_obligations = PredicateObligations::new();
1081 let predicate = normalize_with_depth_to(
1082 this,
1083 param_env,
1084 obligation.cause.clone(),
1085 obligation.recursion_depth + 1,
1086 Unnormalized::new_wip(obligation.predicate),
1087 &mut nested_obligations,
1088 );
1089 if predicate != obligation.predicate {
1090 let mut nested_result = EvaluationResult::EvaluatedToOk;
1091 for obligation in nested_obligations {
1092 nested_result = cmp::max(
1093 this.evaluate_predicate_recursively(previous_stack, obligation)?,
1094 nested_result,
1095 );
1096 }
1097
1098 if nested_result.must_apply_modulo_regions() {
1099 let obligation = obligation.with(this.tcx(), predicate);
1100 result = cmp::max(
1101 nested_result,
1102 this.evaluate_trait_predicate_recursively(previous_stack, obligation)?,
1103 );
1104 }
1105 }
1106 }
1107
1108 Ok::<_, OverflowError>(result)
1109 });
1110
1111 let result = result?;
1112
1113 if !result.must_apply_modulo_regions() {
1114 stack.cache().on_failure(stack.dfn);
1115 }
1116
1117 let reached_depth = stack.reached_depth.get();
1118 if reached_depth >= stack.depth {
1119 debug!("CACHE MISS");
1120 self.insert_evaluation_cache(param_env, fresh_trait_pred, dep_node, result);
1121 stack.cache().on_completion(stack.dfn);
1122 } else if let Some(_guar) = self.infcx.tainted_by_errors() {
1123 debug!("CACHE MISS (tainted by errors)");
1128 self.insert_evaluation_cache(param_env, fresh_trait_pred, dep_node, result);
1129 stack.cache().on_completion(stack.dfn);
1130 } else {
1131 debug!("PROVISIONAL");
1132 debug!(
1133 "caching provisionally because {:?} \
1134 is a cycle participant (at depth {}, reached depth {})",
1135 fresh_trait_pred, stack.depth, reached_depth,
1136 );
1137
1138 stack.cache().insert_provisional(stack.dfn, reached_depth, fresh_trait_pred, result);
1139 }
1140
1141 Ok(result)
1142 }
1143
1144 fn check_evaluation_cycle(
1164 &mut self,
1165 stack: &TraitObligationStack<'_, 'tcx>,
1166 ) -> Option<EvaluationResult> {
1167 if let Some(cycle_depth) = stack
1168 .iter()
1169 .skip(1) .find(|prev| {
1171 stack.obligation.param_env == prev.obligation.param_env
1172 && stack.fresh_trait_pred == prev.fresh_trait_pred
1173 })
1174 .map(|stack| stack.depth)
1175 {
1176 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:1176",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(1176u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("evaluate_stack --> recursive at depth {0}",
cycle_depth) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("evaluate_stack --> recursive at depth {}", cycle_depth);
1177
1178 stack.update_reached_depth(cycle_depth);
1185
1186 let cycle = stack.iter().skip(1).take_while(|s| s.depth >= cycle_depth);
1192 let tcx = self.tcx();
1193 let cycle = cycle.map(|stack| stack.obligation.predicate.upcast(tcx));
1194 if self.coinductive_match(cycle) {
1195 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:1195",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(1195u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("evaluate_stack --> recursive, coinductive")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("evaluate_stack --> recursive, coinductive");
1196 Some(EvaluatedToOk)
1197 } else {
1198 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:1198",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(1198u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("evaluate_stack --> recursive, inductive")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("evaluate_stack --> recursive, inductive");
1199 Some(EvaluatedToAmbigStackDependent)
1200 }
1201 } else {
1202 None
1203 }
1204 }
1205
1206 fn evaluate_stack<'o>(
1207 &mut self,
1208 stack: &TraitObligationStack<'o, 'tcx>,
1209 ) -> Result<EvaluationResult, OverflowError> {
1210 if true {
if !!self.infcx.next_trait_solver() {
::core::panicking::panic("assertion failed: !self.infcx.next_trait_solver()")
};
};debug_assert!(!self.infcx.next_trait_solver());
1211 let unbound_input_types =
1236 stack.fresh_trait_pred.skip_binder().trait_ref.args.types().any(|ty| ty.is_fresh());
1237
1238 if unbound_input_types
1239 && stack.iter().skip(1).any(|prev| {
1240 stack.obligation.param_env == prev.obligation.param_env
1241 && self.match_fresh_trait_preds(stack.fresh_trait_pred, prev.fresh_trait_pred)
1242 })
1243 {
1244 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:1244",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(1244u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("evaluate_stack --> unbound argument, recursive --> giving up")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("evaluate_stack --> unbound argument, recursive --> giving up");
1245 return Ok(EvaluatedToAmbigStackDependent);
1246 }
1247
1248 match self.candidate_from_obligation(stack) {
1249 Ok(Some(c)) => self.evaluate_candidate(stack, &c),
1250 Ok(None) => Ok(EvaluatedToAmbig),
1251 Err(SelectionError::Overflow(OverflowError::Canonical)) => {
1252 Err(OverflowError::Canonical)
1253 }
1254 Err(..) => Ok(EvaluatedToErr),
1255 }
1256 }
1257
1258 pub(crate) fn coinductive_match<I>(&mut self, mut cycle: I) -> bool
1267 where
1268 I: Iterator<Item = ty::Predicate<'tcx>>,
1269 {
1270 cycle.all(|p| match p.kind().skip_binder() {
1271 ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => {
1272 self.infcx.tcx.trait_is_coinductive(data.def_id())
1273 }
1274 ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => {
1275 self.infcx.tcx.features().generic_const_exprs()
1279 }
1280 _ => false,
1281 })
1282 }
1283
1284 x;#[instrument(
1288 level = "debug",
1289 skip(self, stack),
1290 fields(depth = stack.obligation.recursion_depth),
1291 ret
1292 )]
1293 fn evaluate_candidate<'o>(
1294 &mut self,
1295 stack: &TraitObligationStack<'o, 'tcx>,
1296 candidate: &SelectionCandidate<'tcx>,
1297 ) -> Result<EvaluationResult, OverflowError> {
1298 let mut result = self.evaluation_probe(|this| {
1299 match this.confirm_candidate(stack.obligation, candidate.clone()) {
1300 Ok(selection) => {
1301 debug!(?selection);
1302 this.evaluate_predicates_recursively(
1303 stack.list(),
1304 selection.nested_obligations().into_iter(),
1305 )
1306 }
1307 Err(..) => Ok(EvaluatedToErr),
1308 }
1309 })?;
1310
1311 if stack.fresh_trait_pred.has_erased_regions() {
1320 result = result.max(EvaluatedToOkModuloRegions);
1321 }
1322
1323 Ok(result)
1324 }
1325
1326 fn check_evaluation_cache(
1327 &self,
1328 param_env: ty::ParamEnv<'tcx>,
1329 trait_pred: ty::PolyTraitPredicate<'tcx>,
1330 ) -> Option<EvaluationResult> {
1331 let infcx = self.infcx;
1332 let tcx = infcx.tcx;
1333 if self.can_use_global_caches(param_env, trait_pred) {
1334 let key = (infcx.typing_env(param_env), trait_pred);
1335 if let Some(res) = tcx.evaluation_cache.get(&key, tcx) {
1336 Some(res)
1337 } else {
1338 if true {
{
match (&infcx.evaluation_cache.get(&(param_env, trait_pred), tcx),
&None) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
};debug_assert_eq!(infcx.evaluation_cache.get(&(param_env, trait_pred), tcx), None);
1339 None
1340 }
1341 } else {
1342 self.infcx.evaluation_cache.get(&(param_env, trait_pred), tcx)
1343 }
1344 }
1345
1346 fn insert_evaluation_cache(
1347 &mut self,
1348 param_env: ty::ParamEnv<'tcx>,
1349 trait_pred: ty::PolyTraitPredicate<'tcx>,
1350 dep_node: DepNodeIndex,
1351 result: EvaluationResult,
1352 ) {
1353 if result.is_stack_dependent() {
1356 return;
1357 }
1358
1359 let infcx = self.infcx;
1360 let tcx = infcx.tcx;
1361 if self.can_use_global_caches(param_env, trait_pred) {
1362 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:1362",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(1362u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("trait_pred")
}> =
::tracing::__macro_support::FieldName::new("trait_pred");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("result")
}> =
::tracing::__macro_support::FieldName::new("result");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("insert_evaluation_cache global")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_pred)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&result)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?trait_pred, ?result, "insert_evaluation_cache global");
1363 tcx.evaluation_cache.insert(
1365 (infcx.typing_env(param_env), trait_pred),
1366 dep_node,
1367 result,
1368 );
1369 return;
1370 } else {
1371 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:1371",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(1371u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("trait_pred")
}> =
::tracing::__macro_support::FieldName::new("trait_pred");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("result")
}> =
::tracing::__macro_support::FieldName::new("result");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("insert_evaluation_cache local")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_pred)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&result)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?trait_pred, ?result, "insert_evaluation_cache local");
1372 self.infcx.evaluation_cache.insert((param_env, trait_pred), dep_node, result);
1373 }
1374 }
1375
1376 fn check_recursion_depth<T>(
1377 &self,
1378 depth: usize,
1379 error_obligation: &Obligation<'tcx, T>,
1380 ) -> Result<(), OverflowError>
1381 where
1382 T: Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>> + Clone,
1383 {
1384 if !self.infcx.tcx.recursion_limit().value_within_limit(depth) {
1385 match self.query_mode {
1386 TraitQueryMode::Standard => {
1387 if let Some(e) = self.infcx.tainted_by_errors() {
1388 return Err(OverflowError::Error(e));
1389 }
1390 self.infcx.err_ctxt().report_overflow_obligation(error_obligation, true);
1391 }
1392 TraitQueryMode::Canonical => {
1393 return Err(OverflowError::Canonical);
1394 }
1395 }
1396 }
1397 Ok(())
1398 }
1399
1400 #[inline(always)]
1405 fn check_recursion_limit<T: Display + TypeFoldable<TyCtxt<'tcx>>, V>(
1406 &self,
1407 obligation: &Obligation<'tcx, T>,
1408 error_obligation: &Obligation<'tcx, V>,
1409 ) -> Result<(), OverflowError>
1410 where
1411 V: Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>> + Clone,
1412 {
1413 self.check_recursion_depth(obligation.recursion_depth, error_obligation)
1414 }
1415
1416 fn in_task<OP, R>(&mut self, op: OP) -> (R, DepNodeIndex)
1417 where
1418 OP: FnOnce(&mut Self) -> R,
1419 {
1420 self.tcx().dep_graph.with_anon_task(self.tcx(), DepKind::TraitSelect, || op(self))
1421 }
1422
1423 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("filter_impls",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(1425u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligation")
}> =
::tracing::__macro_support::FieldName::new("obligation");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Vec<SelectionCandidate<'tcx>> =
loop {};
return __tracing_attr_fake_return;
}
{
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:1431",
"rustc_trait_selection::traits::select",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(1431u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("{0:#?}",
candidates) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let tcx = self.tcx();
let mut result = Vec::with_capacity(candidates.len());
for candidate in candidates {
if let ImplCandidate(def_id) = candidate {
match (tcx.impl_polarity(def_id), obligation.polarity()) {
(ty::ImplPolarity::Reservation, _) |
(ty::ImplPolarity::Positive,
ty::PredicatePolarity::Positive) |
(ty::ImplPolarity::Negative,
ty::PredicatePolarity::Negative) => {
result.push(candidate);
}
_ => {}
}
} else { result.push(candidate); }
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:1450",
"rustc_trait_selection::traits::select",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(1450u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("{0:#?}",
result) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
result
}
}
}#[instrument(level = "debug", skip(self, candidates))]
1426 fn filter_impls(
1427 &mut self,
1428 candidates: Vec<SelectionCandidate<'tcx>>,
1429 obligation: &PolyTraitObligation<'tcx>,
1430 ) -> Vec<SelectionCandidate<'tcx>> {
1431 trace!("{candidates:#?}");
1432 let tcx = self.tcx();
1433 let mut result = Vec::with_capacity(candidates.len());
1434
1435 for candidate in candidates {
1436 if let ImplCandidate(def_id) = candidate {
1437 match (tcx.impl_polarity(def_id), obligation.polarity()) {
1438 (ty::ImplPolarity::Reservation, _)
1439 | (ty::ImplPolarity::Positive, ty::PredicatePolarity::Positive)
1440 | (ty::ImplPolarity::Negative, ty::PredicatePolarity::Negative) => {
1441 result.push(candidate);
1442 }
1443 _ => {}
1444 }
1445 } else {
1446 result.push(candidate);
1447 }
1448 }
1449
1450 trace!("{result:#?}");
1451 result
1452 }
1453
1454 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("filter_reservation_impls",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(1455u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("candidate")
}> =
::tracing::__macro_support::FieldName::new("candidate");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidate)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
SelectionResult<'tcx, SelectionCandidate<'tcx>> = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx();
if let ImplCandidate(def_id) = candidate &&
let ty::ImplPolarity::Reservation =
tcx.impl_polarity(def_id) {
if let Some(intercrate_ambiguity_clauses) =
&mut self.intercrate_ambiguity_causes {
let message =
{
{
'done:
{
for i in
::rustc_hir::attrs::HasAttrs::get_attrs(def_id, &tcx) {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(RustcReservationImpl(message))
=> {
break 'done Some(*message);
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
};
if let Some(message) = message {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:1468",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(1468u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("filter_reservation_impls: reservation impl ambiguity on {0:?}",
def_id) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
intercrate_ambiguity_clauses.insert(IntercrateAmbiguityCause::ReservationImpl {
message,
});
}
}
return Ok(None);
}
Ok(Some(candidate))
}
}
}#[instrument(level = "debug", skip(self))]
1456 fn filter_reservation_impls(
1457 &mut self,
1458 candidate: SelectionCandidate<'tcx>,
1459 ) -> SelectionResult<'tcx, SelectionCandidate<'tcx>> {
1460 let tcx = self.tcx();
1461 if let ImplCandidate(def_id) = candidate
1463 && let ty::ImplPolarity::Reservation = tcx.impl_polarity(def_id)
1464 {
1465 if let Some(intercrate_ambiguity_clauses) = &mut self.intercrate_ambiguity_causes {
1466 let message = find_attr!(tcx, def_id, RustcReservationImpl(message) => *message);
1467 if let Some(message) = message {
1468 debug!(
1469 "filter_reservation_impls: \
1470 reservation impl ambiguity on {:?}",
1471 def_id
1472 );
1473 intercrate_ambiguity_clauses
1474 .insert(IntercrateAmbiguityCause::ReservationImpl { message });
1475 }
1476 }
1477 return Ok(None);
1478 }
1479 Ok(Some(candidate))
1480 }
1481
1482 fn is_knowable<'o>(&mut self, stack: &TraitObligationStack<'o, 'tcx>) -> Result<(), Conflict> {
1483 let obligation = &stack.obligation;
1484 match self.typing_mode() {
1485 TypingMode::Coherence => {}
1486 TypingMode::Typeck { .. }
1487 | TypingMode::PostTypeckUntilBorrowck { .. }
1488 | TypingMode::PostBorrowck { .. }
1489 | TypingMode::PostAnalysis
1490 | TypingMode::Codegen => return Ok(()),
1491 }
1492
1493 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:1493",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(1493u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("is_knowable()")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("is_knowable()");
1494
1495 let predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
1496
1497 let trait_ref = predicate.skip_binder().trait_ref;
1501
1502 coherence::trait_ref_is_knowable(self.infcx, trait_ref, |ty| Ok::<_, !>(ty)).into_ok()
1503 }
1504
1505 fn can_use_global_caches(
1507 &self,
1508 param_env: ty::ParamEnv<'tcx>,
1509 pred: ty::PolyTraitPredicate<'tcx>,
1510 ) -> bool {
1511 if param_env.has_infer() || pred.has_infer() {
1515 return false;
1516 }
1517
1518 match self.typing_mode() {
1519 TypingMode::Coherence => false,
1526 TypingMode::Typeck { defining_opaque_types_and_generators: defining_opaque_types }
1535 | TypingMode::PostTypeckUntilBorrowck { defining_opaque_types } => {
1536 defining_opaque_types.is_empty()
1537 || (!pred.has_opaque_types() && !pred.has_coroutines())
1538 }
1539 TypingMode::PostBorrowck { .. } => true,
1542 TypingMode::PostAnalysis | TypingMode::Codegen => true,
1548 }
1549 }
1550
1551 fn check_candidate_cache(
1552 &mut self,
1553 param_env: ty::ParamEnv<'tcx>,
1554 cache_fresh_trait_pred: ty::PolyTraitPredicate<'tcx>,
1555 ) -> Option<SelectionResult<'tcx, SelectionCandidate<'tcx>>> {
1556 let infcx = self.infcx;
1557 let tcx = infcx.tcx;
1558 let pred = cache_fresh_trait_pred.skip_binder();
1559
1560 if self.can_use_global_caches(param_env, cache_fresh_trait_pred) {
1561 if let Some(res) = tcx.selection_cache.get(&(infcx.typing_env(param_env), pred), tcx) {
1562 return Some(res);
1563 } else if truecfg!(debug_assertions) {
1564 match infcx.selection_cache.get(&(param_env, pred), tcx) {
1565 None | Some(Err(SelectionError::Overflow(OverflowError::Canonical))) => {}
1566 res => ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected local cache result: {0:?}",
res))bug!("unexpected local cache result: {res:?}"),
1567 }
1568 }
1569 }
1570
1571 infcx.selection_cache.get(&(param_env, pred), tcx)
1575 }
1576
1577 fn can_cache_candidate(
1594 &self,
1595 result: &SelectionResult<'tcx, SelectionCandidate<'tcx>>,
1596 ) -> bool {
1597 match result {
1598 Ok(Some(SelectionCandidate::ParamCandidate(trait_ref))) => !trait_ref.has_infer(),
1599 _ => true,
1600 }
1601 }
1602
1603 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("insert_candidate_cache",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(1603u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("candidate")
}> =
::tracing::__macro_support::FieldName::new("candidate");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidate)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let infcx = self.infcx;
let tcx = infcx.tcx;
let pred = cache_fresh_trait_pred.skip_binder();
if !self.can_cache_candidate(&candidate) {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:1616",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(1616u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("pred")
}> =
::tracing::__macro_support::FieldName::new("pred");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("candidate")
}> =
::tracing::__macro_support::FieldName::new("candidate");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("insert_candidate_cache - candidate is not cacheable")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&pred)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidate)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
return;
}
if self.can_use_global_caches(param_env, cache_fresh_trait_pred) {
if let Err(SelectionError::Overflow(OverflowError::Canonical))
= candidate
{} else {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:1624",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(1624u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("pred")
}> =
::tracing::__macro_support::FieldName::new("pred");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("candidate")
}> =
::tracing::__macro_support::FieldName::new("candidate");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("insert_candidate_cache global")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&pred)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidate)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
if true {
if !!candidate.has_infer() {
::core::panicking::panic("assertion failed: !candidate.has_infer()")
};
};
tcx.selection_cache.insert((infcx.typing_env(param_env),
pred), dep_node, candidate);
return;
}
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:1637",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(1637u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("pred")
}> =
::tracing::__macro_support::FieldName::new("pred");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("candidate")
}> =
::tracing::__macro_support::FieldName::new("candidate");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("insert_candidate_cache local")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&pred)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidate)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
self.infcx.selection_cache.insert((param_env, pred), dep_node,
candidate);
}
}
}#[instrument(skip(self, param_env, cache_fresh_trait_pred, dep_node), level = "debug")]
1604 fn insert_candidate_cache(
1605 &mut self,
1606 param_env: ty::ParamEnv<'tcx>,
1607 cache_fresh_trait_pred: ty::PolyTraitPredicate<'tcx>,
1608 dep_node: DepNodeIndex,
1609 candidate: SelectionResult<'tcx, SelectionCandidate<'tcx>>,
1610 ) {
1611 let infcx = self.infcx;
1612 let tcx = infcx.tcx;
1613 let pred = cache_fresh_trait_pred.skip_binder();
1614
1615 if !self.can_cache_candidate(&candidate) {
1616 debug!(?pred, ?candidate, "insert_candidate_cache - candidate is not cacheable");
1617 return;
1618 }
1619
1620 if self.can_use_global_caches(param_env, cache_fresh_trait_pred) {
1621 if let Err(SelectionError::Overflow(OverflowError::Canonical)) = candidate {
1622 } else {
1624 debug!(?pred, ?candidate, "insert_candidate_cache global");
1625 debug_assert!(!candidate.has_infer());
1626
1627 tcx.selection_cache.insert(
1629 (infcx.typing_env(param_env), pred),
1630 dep_node,
1631 candidate,
1632 );
1633 return;
1634 }
1635 }
1636
1637 debug!(?pred, ?candidate, "insert_candidate_cache local");
1638 self.infcx.selection_cache.insert((param_env, pred), dep_node, candidate);
1639 }
1640
1641 pub(super) fn for_each_item_bound<T>(
1647 &mut self,
1648 mut self_ty: Ty<'tcx>,
1649 mut for_each: impl FnMut(
1650 &mut Self,
1651 ty::Clause<'tcx>,
1652 usize,
1653 AliasBoundKind,
1654 ) -> ControlFlow<T, ()>,
1655 on_ambiguity: impl FnOnce(),
1656 ) -> ControlFlow<T, ()> {
1657 let mut idx = 0;
1658 let mut alias_bound_kind = AliasBoundKind::SelfBounds;
1659
1660 loop {
1661 let (alias_ty, def_id) = match *self_ty.kind() {
1662 ty::Alias(
1663 _,
1664 alias_ty @ ty::AliasTy {
1665 kind: ty::Projection { def_id } | ty::Opaque { def_id },
1666 ..
1667 },
1668 ) => (alias_ty, def_id),
1669 ty::Infer(ty::TyVar(_)) => {
1670 on_ambiguity();
1671 return ControlFlow::Continue(());
1672 }
1673 _ => return ControlFlow::Continue(()),
1674 };
1675
1676 let relevant_bounds = if alias_bound_kind == AliasBoundKind::NonSelfBounds {
1681 self.tcx().item_non_self_bounds(def_id)
1682 } else {
1683 self.tcx().item_self_bounds(def_id)
1684 };
1685
1686 for bound in relevant_bounds.instantiate(self.tcx(), alias_ty.args).skip_norm_wip() {
1687 for_each(self, bound, idx, alias_bound_kind)?;
1688 idx += 1;
1689 }
1690
1691 if #[allow(non_exhaustive_omitted_patterns)] match alias_ty.kind {
ty::Projection { .. } => true,
_ => false,
}matches!(alias_ty.kind, ty::Projection { .. }) {
1692 self_ty = alias_ty.self_ty();
1693 } else {
1694 return ControlFlow::Continue(());
1695 }
1696
1697 alias_bound_kind = AliasBoundKind::NonSelfBounds;
1698 }
1699 }
1700
1701 fn match_normalize_trait_ref(
1705 &mut self,
1706 obligation: &PolyTraitObligation<'tcx>,
1707 placeholder_trait_ref: ty::TraitRef<'tcx>,
1708 trait_bound: ty::PolyTraitRef<'tcx>,
1709 ) -> Result<Option<ty::TraitRef<'tcx>>, ()> {
1710 if true {
if !!placeholder_trait_ref.has_escaping_bound_vars() {
::core::panicking::panic("assertion failed: !placeholder_trait_ref.has_escaping_bound_vars()")
};
};debug_assert!(!placeholder_trait_ref.has_escaping_bound_vars());
1711 if placeholder_trait_ref.def_id != trait_bound.def_id() {
1712 return Err(());
1714 }
1715
1716 let drcx = DeepRejectCtxt::relate_rigid_rigid(self.infcx.tcx);
1717 let obligation_args = obligation.predicate.skip_binder().trait_ref.args;
1718 if !drcx.args_may_unify(obligation_args, trait_bound.skip_binder().args) {
1719 return Err(());
1720 }
1721
1722 let trait_bound = self.infcx.instantiate_binder_with_fresh_vars(
1723 obligation.cause.span,
1724 HigherRankedType,
1725 trait_bound,
1726 );
1727 let Normalized { value: trait_bound, obligations: _ } = ensure_sufficient_stack(|| {
1728 normalize_with_depth(
1729 self,
1730 obligation.param_env,
1731 obligation.cause.clone(),
1732 obligation.recursion_depth + 1,
1733 ty::Unnormalized::new_wip(trait_bound),
1734 )
1735 });
1736 self.infcx
1737 .at(&obligation.cause, obligation.param_env)
1738 .eq(DefineOpaqueTypes::No, placeholder_trait_ref, trait_bound)
1739 .map(|InferOk { obligations: _, value: () }| {
1740 if !trait_bound.has_infer() && !trait_bound.has_placeholders() {
1743 Some(trait_bound)
1744 } else {
1745 None
1746 }
1747 })
1748 .map_err(|_| ())
1749 }
1750
1751 fn where_clause_may_apply<'o>(
1752 &mut self,
1753 stack: &TraitObligationStack<'o, 'tcx>,
1754 where_clause_trait_ref: ty::PolyTraitRef<'tcx>,
1755 ) -> Result<EvaluationResult, OverflowError> {
1756 self.evaluation_probe(|this| {
1757 match this.match_where_clause_trait_ref(stack.obligation, where_clause_trait_ref) {
1758 Ok(obligations) => this.evaluate_predicates_recursively(stack.list(), obligations),
1759 Err(()) => Ok(EvaluatedToErr),
1760 }
1761 })
1762 }
1763
1764 pub(super) fn match_projection_projections(
1771 &mut self,
1772 obligation: &ProjectionTermObligation<'tcx>,
1773 env_predicate: PolyProjectionPredicate<'tcx>,
1774 potentially_unnormalized_candidates: bool,
1775 ) -> ProjectionMatchesProjection {
1776 let def_id = obligation.predicate.expect_projection_def_id();
1777 if true {
{
match (&def_id, &env_predicate.item_def_id()) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
};debug_assert_eq!(def_id, env_predicate.item_def_id());
1778
1779 let mut nested_obligations = PredicateObligations::new();
1780 let infer_predicate = self.infcx.instantiate_binder_with_fresh_vars(
1781 obligation.cause.span,
1782 BoundRegionConversionTime::HigherRankedType,
1783 env_predicate,
1784 );
1785 let mut infer_projection = infer_predicate.projection_term;
1786 if potentially_unnormalized_candidates {
1787 infer_projection = ensure_sufficient_stack(|| {
1788 normalize_with_depth_to(
1789 self,
1790 obligation.param_env,
1791 obligation.cause.clone(),
1792 obligation.recursion_depth + 1,
1793 ty::Unnormalized::new_wip(infer_projection),
1794 &mut nested_obligations,
1795 )
1796 })
1797 }
1798
1799 let is_match = self
1800 .infcx
1801 .at(&obligation.cause, obligation.param_env)
1802 .eq(DefineOpaqueTypes::No, obligation.predicate, infer_projection)
1803 .is_ok_and(|InferOk { obligations, value: () }| {
1804 self.evaluate_predicates_recursively(
1805 TraitObligationStackList::empty(&ProvisionalEvaluationCache::default()),
1806 nested_obligations.into_iter().chain(obligations),
1807 )
1808 .is_ok_and(|res| res.may_apply())
1809 });
1810
1811 if is_match {
1812 let generics = self.tcx().generics_of(def_id);
1813 if !generics.is_own_empty()
1822 && obligation.predicate.args[generics.parent_count..].iter().any(|&p| {
1823 p.has_non_region_infer()
1824 && match p.kind() {
1825 ty::GenericArgKind::Const(ct) => {
1826 self.infcx.shallow_resolve_const(ct) != ct
1827 }
1828 ty::GenericArgKind::Type(ty) => self.infcx.shallow_resolve(ty) != ty,
1829 ty::GenericArgKind::Lifetime(_) => false,
1830 }
1831 })
1832 {
1833 ProjectionMatchesProjection::Ambiguous
1834 } else {
1835 ProjectionMatchesProjection::Yes
1836 }
1837 } else {
1838 ProjectionMatchesProjection::No
1839 }
1840 }
1841}
1842
1843impl<'tcx> SelectionContext<'_, 'tcx> {
1850 x;#[instrument(level = "debug", skip(self), ret)]
1855 fn winnow_candidates(
1856 &mut self,
1857 has_non_region_infer: bool,
1858 candidate_preference_mode: CandidatePreferenceMode,
1859 mut candidates: Vec<EvaluatedCandidate<'tcx>>,
1860 ) -> Option<SelectionCandidate<'tcx>> {
1861 if candidates.len() == 1 {
1862 return Some(candidates.pop().unwrap().candidate);
1863 }
1864
1865 let mut sized_candidates =
1867 candidates.iter().filter(|c| matches!(c.candidate, SizedCandidate));
1868 if let Some(sized_candidate) = sized_candidates.next() {
1869 debug_assert_eq!(sized_candidates.next(), None);
1872 if sized_candidate.evaluation.must_apply_modulo_regions() {
1876 return Some(sized_candidate.candidate.clone());
1877 } else {
1878 return None;
1879 }
1880 }
1881
1882 'search_victim: loop {
1886 for (i, this) in candidates.iter().enumerate() {
1887 let ParamCandidate(this) = this.candidate else { continue };
1888 for (j, other) in candidates.iter().enumerate() {
1889 if i == j {
1890 continue;
1891 }
1892
1893 let ParamCandidate(other) = other.candidate else { continue };
1894 if this == other {
1895 candidates.remove(j);
1896 continue 'search_victim;
1897 }
1898
1899 if this.skip_binder().trait_ref == other.skip_binder().trait_ref
1900 && this.skip_binder().polarity == other.skip_binder().polarity
1901 && !this.skip_binder().trait_ref.has_escaping_bound_vars()
1902 {
1903 candidates.remove(j);
1904 continue 'search_victim;
1905 }
1906 }
1907 }
1908
1909 break;
1910 }
1911
1912 let mut alias_bounds = candidates.iter().filter_map(|c| {
1913 if let ProjectionCandidate { idx, kind } = c.candidate {
1914 Some((idx, kind))
1915 } else {
1916 None
1917 }
1918 });
1919 if matches!(candidate_preference_mode, CandidatePreferenceMode::Marker) {
1922 match alias_bounds
1923 .clone()
1924 .filter_map(|(idx, kind)| (kind == AliasBoundKind::SelfBounds).then_some(idx))
1925 .try_reduce(|c1, c2| if has_non_region_infer { None } else { Some(c1.min(c2)) })
1926 {
1927 Some(Some(idx)) => {
1928 return Some(ProjectionCandidate { idx, kind: AliasBoundKind::SelfBounds });
1929 }
1930 Some(None) => {}
1931 None => return None,
1932 }
1933 }
1934
1935 let is_global = |c: ty::PolyTraitPredicate<'tcx>| c.is_global() && !c.has_bound_vars();
1942 let param_candidates = candidates
1943 .iter()
1944 .filter_map(|c| if let ParamCandidate(p) = c.candidate { Some(p) } else { None });
1945 let mut has_global_bounds = false;
1946 let mut param_candidate = None;
1947 for c in param_candidates {
1948 if is_global(c) {
1949 has_global_bounds = true;
1950 } else if param_candidate.replace(c).is_some() {
1951 return None;
1953 }
1954 }
1955 if let Some(predicate) = param_candidate {
1956 if has_global_bounds {
1958 return None;
1959 } else {
1960 return Some(ParamCandidate(predicate));
1961 }
1962 }
1963
1964 match alias_bounds.try_reduce(|(c1, k1), (c2, k2)| {
1969 if has_non_region_infer {
1970 None
1971 } else if c1 < c2 {
1972 Some((c1, k1))
1973 } else {
1974 Some((c2, k2))
1975 }
1976 }) {
1977 Some(Some((idx, kind))) => return Some(ProjectionCandidate { idx, kind }),
1978 Some(None) => {}
1979 None => return None,
1980 }
1981
1982 let object_bound = candidates
1991 .iter()
1992 .filter_map(|c| if let ObjectCandidate(i) = c.candidate { Some(i) } else { None })
1993 .try_reduce(|c1, c2| if has_non_region_infer { None } else { Some(c1.min(c2)) });
1994 match object_bound {
1995 Some(Some(index)) => {
1996 return if has_non_region_infer
1997 && candidates.iter().any(|c| matches!(c.candidate, ImplCandidate(_)))
1998 {
1999 None
2000 } else {
2001 Some(ObjectCandidate(index))
2002 };
2003 }
2004 Some(None) => {}
2005 None => return None,
2006 }
2007 let upcast_bound = candidates
2009 .iter()
2010 .filter_map(|c| {
2011 if let TraitUpcastingUnsizeCandidate(i) = c.candidate { Some(i) } else { None }
2012 })
2013 .try_reduce(|c1, c2| if has_non_region_infer { None } else { Some(c1.min(c2)) });
2014 match upcast_bound {
2015 Some(Some(index)) => return Some(TraitUpcastingUnsizeCandidate(index)),
2016 Some(None) => {}
2017 None => return None,
2018 }
2019
2020 let impls = candidates.iter().filter_map(|c| {
2022 if let ImplCandidate(def_id) = c.candidate {
2023 Some((def_id, c.evaluation))
2024 } else {
2025 None
2026 }
2027 });
2028 let mut impl_candidate = None;
2029 for c in impls {
2030 if let Some(prev) = impl_candidate.replace(c) {
2031 if self.prefer_lhs_over_victim(has_non_region_infer, c, prev.0) {
2032 } else if self.prefer_lhs_over_victim(has_non_region_infer, prev, c.0) {
2034 impl_candidate = Some(prev);
2036 } else {
2037 return None;
2039 }
2040 }
2041 }
2042 if let Some((def_id, _evaluation)) = impl_candidate {
2043 if candidates.iter().all(|c| match c.candidate {
2046 SizedCandidate
2047 | BuiltinCandidate
2048 | TransmutabilityCandidate
2049 | AutoImplCandidate
2050 | ClosureCandidate { .. }
2051 | AsyncClosureCandidate
2052 | AsyncFnKindHelperCandidate
2053 | CoroutineCandidate
2054 | FutureCandidate
2055 | IteratorCandidate
2056 | AsyncIteratorCandidate
2057 | FnPointerCandidate
2058 | TraitAliasCandidate
2059 | TraitUpcastingUnsizeCandidate(_)
2060 | BuiltinObjectCandidate
2061 | BuiltinUnsizeCandidate
2062 | BikeshedGuaranteedNoDropCandidate => false,
2063 ParamCandidate(_) | ImplCandidate(_) => true,
2066 ProjectionCandidate { .. } | ObjectCandidate(_) => unreachable!(),
2067 }) {
2068 return Some(ImplCandidate(def_id));
2069 } else {
2070 return None;
2071 }
2072 }
2073
2074 if candidates.len() == 1 {
2075 Some(candidates.pop().unwrap().candidate)
2076 } else {
2077 let mut not_a_global_where_bound = candidates
2080 .into_iter()
2081 .filter(|c| !matches!(c.candidate, ParamCandidate(p) if is_global(p)));
2082 not_a_global_where_bound
2083 .next()
2084 .map(|c| c.candidate)
2085 .filter(|_| not_a_global_where_bound.next().is_none())
2086 }
2087 }
2088
2089 fn prefer_lhs_over_victim(
2090 &self,
2091 has_non_region_infer: bool,
2092 (lhs, lhs_evaluation): (DefId, EvaluationResult),
2093 victim: DefId,
2094 ) -> bool {
2095 let tcx = self.tcx();
2096 if lhs_evaluation.must_apply_modulo_regions() {
2103 if tcx.specializes((lhs, victim)) {
2104 return true;
2105 }
2106 }
2107
2108 match tcx.impls_are_allowed_to_overlap(lhs, victim) {
2109 Some(ty::ImplOverlapKind::Permitted { marker: false }) => {
2112 lhs_evaluation.must_apply_considering_regions()
2113 }
2114 Some(ty::ImplOverlapKind::Permitted { marker: true }) => {
2115 !has_non_region_infer && lhs_evaluation.must_apply_considering_regions()
2155 }
2156 None => false,
2157 }
2158 }
2159}
2160
2161impl<'tcx> SelectionContext<'_, 'tcx> {
2162 fn sizedness_conditions(
2163 &mut self,
2164 self_ty: Ty<'tcx>,
2165 sizedness: SizedTraitKind,
2166 ) -> ty::Binder<'tcx, Vec<Ty<'tcx>>> {
2167 match self_ty.kind() {
2168 ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
2169 | ty::Uint(_)
2170 | ty::Int(_)
2171 | ty::Bool
2172 | ty::Float(_)
2173 | ty::FnDef(..)
2174 | ty::FnPtr(..)
2175 | ty::RawPtr(..)
2176 | ty::Char
2177 | ty::Ref(..)
2178 | ty::Coroutine(..)
2179 | ty::CoroutineWitness(..)
2180 | ty::Array(..)
2181 | ty::Closure(..)
2182 | ty::CoroutineClosure(..)
2183 | ty::Never
2184 | ty::Error(_) => ty::Binder::dummy(::alloc::vec::Vec::new()vec![]),
2185
2186 ty::Str | ty::Slice(_) | ty::Dynamic(..) => match sizedness {
2187 SizedTraitKind::Sized => {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("tried to assemble `Sized` for unsized type")));
}unreachable!("tried to assemble `Sized` for unsized type"),
2188 SizedTraitKind::MetaSized => ty::Binder::dummy(::alloc::vec::Vec::new()vec![]),
2189 },
2190
2191 ty::Foreign(..) => {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("tried to assemble `Sized` for unsized type")));
}unreachable!("tried to assemble `Sized` for unsized type"),
2192
2193 ty::Tuple(tys) => {
2194 ty::Binder::dummy(tys.last().map_or_else(Vec::new, |&last| ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[last]))vec![last]))
2195 }
2196
2197 ty::Pat(ty, _) => ty::Binder::dummy(::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[*ty]))vec![*ty]),
2198
2199 ty::Adt(def, args) => {
2200 if let Some(crit) = def.sizedness_constraint(self.tcx(), sizedness) {
2201 ty::Binder::dummy(::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[crit.instantiate(self.tcx(), args).skip_norm_wip()]))vec![crit.instantiate(self.tcx(), args).skip_norm_wip()])
2202 } else {
2203 ty::Binder::dummy(::alloc::vec::Vec::new()vec![])
2204 }
2205 }
2206
2207 ty::UnsafeBinder(binder_ty) => binder_ty.map_bound(|ty| ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[ty]))vec![ty]),
2208
2209 ty::Alias(..)
2210 | ty::Param(_)
2211 | ty::Placeholder(..)
2212 | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_))
2213 | ty::Bound(..) => {
2214 ::rustc_middle::util::bug::bug_fmt(format_args!("asked to assemble `Sized` of unexpected type: {0:?}",
self_ty));bug!("asked to assemble `Sized` of unexpected type: {:?}", self_ty);
2215 }
2216 }
2217 }
2218
2219 fn copy_clone_conditions(&mut self, self_ty: Ty<'tcx>) -> ty::Binder<'tcx, Vec<Ty<'tcx>>> {
2220 match *self_ty.kind() {
2221 ty::FnDef(..) | ty::FnPtr(..) | ty::Error(_) => ty::Binder::dummy(::alloc::vec::Vec::new()vec![]),
2222
2223 ty::Uint(_)
2224 | ty::Int(_)
2225 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
2226 | ty::Bool
2227 | ty::Float(_)
2228 | ty::Char
2229 | ty::RawPtr(..)
2230 | ty::Never
2231 | ty::Ref(_, _, hir::Mutability::Not)
2232 | ty::Array(..) => {
2233 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("tried to assemble `Sized` for type with libcore-provided impl")));
}unreachable!("tried to assemble `Sized` for type with libcore-provided impl")
2234 }
2235
2236 ty::UnsafeBinder(_) => {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("tried to assemble `Sized` for unsafe binder")));
}unreachable!("tried to assemble `Sized` for unsafe binder"),
2239
2240 ty::Tuple(tys) => {
2241 ty::Binder::dummy(tys.iter().collect())
2243 }
2244
2245 ty::Pat(ty, _) => {
2246 ty::Binder::dummy(::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[ty]))vec![ty])
2248 }
2249
2250 ty::Coroutine(def_id, args) => match self.tcx().coroutine_movability(def_id) {
2251 hir::Movability::Static => {
2252 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("tried to assemble `Clone` for static coroutine")));
}unreachable!("tried to assemble `Clone` for static coroutine")
2253 }
2254 hir::Movability::Movable => {
2255 if self.tcx().features().coroutine_clone() {
2256 ty::Binder::dummy(::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[args.as_coroutine().tupled_upvars_ty(),
Ty::new_coroutine_witness_for_coroutine(self.tcx(), def_id,
args)]))vec![
2257 args.as_coroutine().tupled_upvars_ty(),
2258 Ty::new_coroutine_witness_for_coroutine(self.tcx(), def_id, args),
2259 ])
2260 } else {
2261 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("tried to assemble `Clone` for coroutine without enabled feature")));
}unreachable!(
2262 "tried to assemble `Clone` for coroutine without enabled feature"
2263 )
2264 }
2265 }
2266 },
2267
2268 ty::CoroutineWitness(def_id, args) => self
2269 .infcx
2270 .tcx
2271 .coroutine_hidden_types(def_id)
2272 .instantiate(self.infcx.tcx, args)
2273 .skip_norm_wip()
2274 .map_bound(|witness| witness.types.to_vec()),
2275
2276 ty::Closure(_, args) => ty::Binder::dummy(args.as_closure().upvar_tys().to_vec()),
2277
2278 ty::CoroutineClosure(_, args) => {
2279 ty::Binder::dummy(args.as_coroutine_closure().upvar_tys().to_vec())
2280 }
2281
2282 ty::Foreign(..)
2283 | ty::Str
2284 | ty::Slice(_)
2285 | ty::Dynamic(..)
2286 | ty::Adt(..)
2287 | ty::Alias(..)
2288 | ty::Param(..)
2289 | ty::Placeholder(..)
2290 | ty::Bound(..)
2291 | ty::Ref(_, _, ty::Mutability::Mut)
2292 | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
2293 ::rustc_middle::util::bug::bug_fmt(format_args!("asked to assemble builtin bounds of unexpected type: {0:?}",
self_ty));bug!("asked to assemble builtin bounds of unexpected type: {:?}", self_ty);
2294 }
2295 }
2296 }
2297
2298 fn coroutine_is_gen(&mut self, self_ty: Ty<'tcx>) -> bool {
2299 #[allow(non_exhaustive_omitted_patterns)] match *self_ty.kind() {
ty::Coroutine(did, ..) if self.tcx().coroutine_is_gen(did) => true,
_ => false,
}matches!(*self_ty.kind(), ty::Coroutine(did, ..)
2300 if self.tcx().coroutine_is_gen(did))
2301 }
2302
2303 x;#[instrument(level = "debug", skip(self), ret)]
2315 fn constituent_types_for_auto_trait(
2316 &self,
2317 t: Ty<'tcx>,
2318 ) -> Result<ty::Binder<'tcx, AutoImplConstituents<'tcx>>, SelectionError<'tcx>> {
2319 Ok(match *t.kind() {
2320 ty::Uint(_)
2321 | ty::Int(_)
2322 | ty::Bool
2323 | ty::Float(_)
2324 | ty::FnDef(..)
2325 | ty::FnPtr(..)
2326 | ty::Error(_)
2327 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
2328 | ty::Never
2329 | ty::Char => {
2330 ty::Binder::dummy(AutoImplConstituents { types: vec![], assumptions: vec![] })
2331 }
2332
2333 ty::Foreign(..) => {
2337 ty::Binder::dummy(AutoImplConstituents { types: vec![], assumptions: vec![] })
2338 }
2339
2340 ty::UnsafeBinder(ty) => {
2341 ty.map_bound(|ty| AutoImplConstituents { types: vec![ty], assumptions: vec![] })
2342 }
2343
2344 ty::Str => ty::Binder::dummy(AutoImplConstituents {
2346 types: vec![Ty::new_slice(self.tcx(), self.tcx().types.u8)],
2347 assumptions: vec![],
2348 }),
2349
2350 ty::Placeholder(..)
2351 | ty::Dynamic(..)
2352 | ty::Param(..)
2353 | ty::Alias(
2354 _,
2355 ty::AliasTy {
2356 kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. },
2357 ..
2358 },
2359 )
2360 | ty::Bound(..)
2361 | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
2362 bug!("asked to assemble constituent types of unexpected type: {:?}", t);
2363 }
2364
2365 ty::RawPtr(element_ty, _) | ty::Ref(_, element_ty, _) => {
2366 ty::Binder::dummy(AutoImplConstituents {
2367 types: vec![element_ty],
2368 assumptions: vec![],
2369 })
2370 }
2371
2372 ty::Pat(ty, _) | ty::Array(ty, _) | ty::Slice(ty) => {
2373 ty::Binder::dummy(AutoImplConstituents { types: vec![ty], assumptions: vec![] })
2374 }
2375
2376 ty::Tuple(tys) => {
2377 ty::Binder::dummy(AutoImplConstituents {
2379 types: tys.iter().collect(),
2380 assumptions: vec![],
2381 })
2382 }
2383
2384 ty::Closure(_, args) => {
2385 let ty = self.infcx.shallow_resolve(args.as_closure().tupled_upvars_ty());
2386 ty::Binder::dummy(AutoImplConstituents { types: vec![ty], assumptions: vec![] })
2387 }
2388
2389 ty::CoroutineClosure(_, args) => {
2390 let ty = self.infcx.shallow_resolve(args.as_coroutine_closure().tupled_upvars_ty());
2391 ty::Binder::dummy(AutoImplConstituents { types: vec![ty], assumptions: vec![] })
2392 }
2393
2394 ty::Coroutine(def_id, args) => {
2395 let ty = self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty());
2396 let tcx = self.tcx();
2397 let witness = Ty::new_coroutine_witness_for_coroutine(tcx, def_id, args);
2398 ty::Binder::dummy(AutoImplConstituents {
2399 types: vec![ty, witness],
2400 assumptions: vec![],
2401 })
2402 }
2403
2404 ty::CoroutineWitness(def_id, args) => self
2405 .infcx
2406 .tcx
2407 .coroutine_hidden_types(def_id)
2408 .instantiate(self.infcx.tcx, args)
2409 .skip_norm_wip()
2410 .map_bound(|witness| AutoImplConstituents {
2411 types: witness.types.to_vec(),
2412 assumptions: witness.assumptions.to_vec(),
2413 }),
2414
2415 ty::Adt(def, args) if def.is_phantom_data() => {
2417 ty::Binder::dummy(AutoImplConstituents {
2418 types: args.types().collect(),
2419 assumptions: vec![],
2420 })
2421 }
2422
2423 ty::Adt(def, args) => ty::Binder::dummy(AutoImplConstituents {
2424 types: def.all_fields().map(|f| f.ty(self.tcx(), args).skip_norm_wip()).collect(),
2425 assumptions: vec![],
2426 }),
2427
2428 ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => {
2429 if self.infcx.can_define_opaque_ty(def_id) {
2430 unreachable!()
2431 } else {
2432 let ty = self.tcx().type_of_opaque(def_id);
2436 ty::Binder::dummy(AutoImplConstituents {
2437 types: vec![ty.instantiate(self.tcx(), args).skip_norm_wip()],
2438 assumptions: vec![],
2439 })
2440 }
2441 }
2442 })
2443 }
2444
2445 fn collect_predicates_for_types(
2446 &mut self,
2447 param_env: ty::ParamEnv<'tcx>,
2448 cause: ObligationCause<'tcx>,
2449 recursion_depth: usize,
2450 trait_def_id: DefId,
2451 types: Vec<Ty<'tcx>>,
2452 ) -> PredicateObligations<'tcx> {
2453 types
2468 .into_iter()
2469 .flat_map(|placeholder_ty| {
2470 let Normalized { value: normalized_ty, mut obligations } =
2471 ensure_sufficient_stack(|| {
2472 normalize_with_depth(
2473 self,
2474 param_env,
2475 cause.clone(),
2476 recursion_depth,
2477 Unnormalized::new_wip(placeholder_ty),
2478 )
2479 });
2480
2481 let tcx = self.tcx();
2482 let trait_ref = if tcx.generics_of(trait_def_id).own_params.len() == 1 {
2483 ty::TraitRef::new(tcx, trait_def_id, [normalized_ty])
2484 } else {
2485 let err_args = ty::GenericArgs::extend_with_error(
2488 tcx,
2489 trait_def_id,
2490 &[normalized_ty.into()],
2491 );
2492 ty::TraitRef::new_from_args(tcx, trait_def_id, err_args)
2493 };
2494
2495 let obligation = Obligation::new(self.tcx(), cause.clone(), param_env, trait_ref);
2496 obligations.push(obligation);
2497 obligations
2498 })
2499 .collect()
2500 }
2501
2502 fn rematch_impl(
2513 &mut self,
2514 impl_def_id: DefId,
2515 obligation: &PolyTraitObligation<'tcx>,
2516 ) -> Normalized<'tcx, GenericArgsRef<'tcx>> {
2517 let impl_trait_header = self.tcx().impl_trait_header(impl_def_id);
2518 match self.match_impl(impl_def_id, impl_trait_header, obligation) {
2519 Ok(args) => args,
2520 Err(()) => {
2521 let predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
2522 ::rustc_middle::util::bug::bug_fmt(format_args!("impl {0:?} was matchable against {1:?} but now is not",
impl_def_id, predicate))bug!("impl {impl_def_id:?} was matchable against {predicate:?} but now is not")
2523 }
2524 }
2525 }
2526
2527 x;#[instrument(level = "debug", skip(self), ret)]
2528 fn match_impl(
2529 &mut self,
2530 impl_def_id: DefId,
2531 impl_trait_header: ty::ImplTraitHeader<'tcx>,
2532 obligation: &PolyTraitObligation<'tcx>,
2533 ) -> Result<Normalized<'tcx, GenericArgsRef<'tcx>>, ()> {
2534 let placeholder_obligation =
2535 self.infcx.enter_forall_and_leak_universe(obligation.predicate);
2536 let placeholder_obligation_trait_ref = placeholder_obligation.trait_ref;
2537
2538 let impl_args = self.infcx.fresh_args_for_item(obligation.cause.span, impl_def_id);
2539
2540 let trait_ref = impl_trait_header.trait_ref.instantiate(self.tcx(), impl_args);
2541 debug!(?impl_trait_header);
2542
2543 let mut nested_obligations = PredicateObligations::new();
2544 let impl_trait_ref = ensure_sufficient_stack(|| {
2545 normalize_with_depth_to(
2546 self,
2547 obligation.param_env,
2548 obligation.cause.clone(),
2549 obligation.recursion_depth + 1,
2550 trait_ref,
2551 &mut nested_obligations,
2552 )
2553 });
2554
2555 debug!(?impl_trait_ref, ?placeholder_obligation_trait_ref);
2556
2557 let cause = ObligationCause::new(
2558 obligation.cause.span,
2559 obligation.cause.body_def_id,
2560 ObligationCauseCode::MatchImpl(obligation.cause.clone(), impl_def_id),
2561 );
2562
2563 let InferOk { obligations, .. } = self
2564 .infcx
2565 .at(&cause, obligation.param_env)
2566 .eq(DefineOpaqueTypes::No, placeholder_obligation_trait_ref, impl_trait_ref)
2567 .map_err(|e| {
2568 debug!("match_impl: failed eq_trait_refs due to `{}`", e.to_string(self.tcx()))
2569 })?;
2570 nested_obligations.extend(obligations);
2571
2572 if impl_trait_header.polarity == ty::ImplPolarity::Reservation
2573 && !self.typing_mode().is_coherence()
2574 {
2575 debug!("reservation impls only apply in intercrate mode");
2576 return Err(());
2577 }
2578
2579 Ok(Normalized { value: impl_args, obligations: nested_obligations })
2580 }
2581
2582 fn match_upcast_principal(
2583 &mut self,
2584 obligation: &PolyTraitObligation<'tcx>,
2585 unnormalized_upcast_principal: ty::Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>,
2586 a_data: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
2587 b_data: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
2588 a_region: ty::Region<'tcx>,
2589 b_region: ty::Region<'tcx>,
2590 ) -> SelectionResult<'tcx, PredicateObligations<'tcx>> {
2591 let tcx = self.tcx();
2592 let mut nested = PredicateObligations::new();
2593
2594 let a_auto_traits: FxIndexSet<DefId> = a_data
2598 .auto_traits()
2599 .chain(
2600 a_data
2601 .principal_def_id()
2602 .map(|principal_def_id| {
2603 elaborate::supertrait_def_ids(tcx, principal_def_id)
2604 .filter(|def_id| tcx.trait_is_auto(*def_id))
2605 })
2606 .into_flat_iter(),
2607 )
2608 .collect();
2609
2610 let upcast_principal = normalize_with_depth_to(
2611 self,
2612 obligation.param_env,
2613 obligation.cause.clone(),
2614 obligation.recursion_depth + 1,
2615 unnormalized_upcast_principal,
2616 &mut nested,
2617 );
2618
2619 for bound in b_data {
2620 match bound.skip_binder() {
2621 ty::ExistentialPredicate::Trait(target_principal) => {
2624 let hr_source_principal = upcast_principal.map_bound(|trait_ref| {
2625 ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)
2626 });
2627 let hr_target_principal = bound.rebind(target_principal);
2628
2629 nested.extend(
2630 self.infcx
2631 .enter_forall(hr_target_principal, |target_principal| {
2632 let source_principal =
2633 self.infcx.instantiate_binder_with_fresh_vars(
2634 obligation.cause.span,
2635 HigherRankedType,
2636 hr_source_principal,
2637 );
2638 self.infcx.at(&obligation.cause, obligation.param_env).eq_trace(
2639 DefineOpaqueTypes::Yes,
2640 ToTrace::to_trace(
2641 &obligation.cause,
2642 hr_target_principal,
2643 hr_source_principal,
2644 ),
2645 target_principal,
2646 source_principal,
2647 )
2648 })
2649 .map_err(|_| SelectionError::Unimplemented)?
2650 .into_obligations(),
2651 );
2652 }
2653 ty::ExistentialPredicate::Projection(target_projection) => {
2659 let hr_target_projection = bound.rebind(target_projection);
2660
2661 let mut matching_projections =
2662 a_data.projection_bounds().filter(|&hr_source_projection| {
2663 hr_source_projection.item_def_id() == hr_target_projection.item_def_id()
2666 && self.infcx.probe(|_| {
2667 self.infcx
2668 .enter_forall(hr_target_projection, |target_projection| {
2669 let source_projection =
2670 self.infcx.instantiate_binder_with_fresh_vars(
2671 obligation.cause.span,
2672 HigherRankedType,
2673 hr_source_projection,
2674 );
2675 self.infcx
2676 .at(&obligation.cause, obligation.param_env)
2677 .eq_trace(
2678 DefineOpaqueTypes::Yes,
2679 ToTrace::to_trace(
2680 &obligation.cause,
2681 hr_target_projection,
2682 hr_source_projection,
2683 ),
2684 target_projection,
2685 source_projection,
2686 )
2687 })
2688 .is_ok()
2689 })
2690 });
2691
2692 let Some(hr_source_projection) = matching_projections.next() else {
2693 return Err(SelectionError::Unimplemented);
2694 };
2695 if matching_projections.next().is_some() {
2696 return Ok(None);
2697 }
2698 nested.extend(
2699 self.infcx
2700 .enter_forall(hr_target_projection, |target_projection| {
2701 let source_projection =
2702 self.infcx.instantiate_binder_with_fresh_vars(
2703 obligation.cause.span,
2704 HigherRankedType,
2705 hr_source_projection,
2706 );
2707 self.infcx.at(&obligation.cause, obligation.param_env).eq_trace(
2708 DefineOpaqueTypes::Yes,
2709 ToTrace::to_trace(
2710 &obligation.cause,
2711 hr_target_projection,
2712 hr_source_projection,
2713 ),
2714 target_projection,
2715 source_projection,
2716 )
2717 })
2718 .map_err(|_| SelectionError::Unimplemented)?
2719 .into_obligations(),
2720 );
2721 }
2722 ty::ExistentialPredicate::AutoTrait(def_id) => {
2724 if !a_auto_traits.contains(&def_id) {
2725 return Err(SelectionError::Unimplemented);
2726 }
2727 }
2728 }
2729 }
2730
2731 nested.push(Obligation::with_depth(
2732 tcx,
2733 obligation.cause.clone(),
2734 obligation.recursion_depth + 1,
2735 obligation.param_env,
2736 ty::Binder::dummy(ty::OutlivesPredicate(a_region, b_region)),
2737 ));
2738
2739 Ok(Some(nested))
2740 }
2741
2742 fn match_where_clause_trait_ref(
2746 &mut self,
2747 obligation: &PolyTraitObligation<'tcx>,
2748 where_clause_trait_ref: ty::PolyTraitRef<'tcx>,
2749 ) -> Result<PredicateObligations<'tcx>, ()> {
2750 self.match_poly_trait_ref(obligation, where_clause_trait_ref)
2751 }
2752
2753 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("match_poly_trait_ref",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(2755u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligation")
}> =
::tracing::__macro_support::FieldName::new("obligation");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("poly_trait_ref")
}> =
::tracing::__macro_support::FieldName::new("poly_trait_ref");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&poly_trait_ref)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
Result<PredicateObligations<'tcx>, ()> = loop {};
return __tracing_attr_fake_return;
}
{
let predicate =
self.infcx.enter_forall_and_leak_universe(obligation.predicate);
let trait_ref =
self.infcx.instantiate_binder_with_fresh_vars(obligation.cause.span,
HigherRankedType, poly_trait_ref);
self.infcx.at(&obligation.cause,
obligation.param_env).eq(DefineOpaqueTypes::No,
predicate.trait_ref,
trait_ref).map(|InferOk { obligations, .. }|
obligations).map_err(|_| ())
}
}
}#[instrument(skip(self), level = "debug")]
2756 fn match_poly_trait_ref(
2757 &mut self,
2758 obligation: &PolyTraitObligation<'tcx>,
2759 poly_trait_ref: ty::PolyTraitRef<'tcx>,
2760 ) -> Result<PredicateObligations<'tcx>, ()> {
2761 let predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
2762 let trait_ref = self.infcx.instantiate_binder_with_fresh_vars(
2763 obligation.cause.span,
2764 HigherRankedType,
2765 poly_trait_ref,
2766 );
2767 self.infcx
2768 .at(&obligation.cause, obligation.param_env)
2769 .eq(DefineOpaqueTypes::No, predicate.trait_ref, trait_ref)
2770 .map(|InferOk { obligations, .. }| obligations)
2771 .map_err(|_| ())
2772 }
2773
2774 fn match_fresh_trait_preds(
2778 &self,
2779 previous: ty::PolyTraitPredicate<'tcx>,
2780 current: ty::PolyTraitPredicate<'tcx>,
2781 ) -> bool {
2782 let mut matcher = _match::MatchAgainstFreshVars::new(self.tcx());
2783 matcher.relate(previous, current).is_ok()
2784 }
2785
2786 fn push_stack<'o>(
2787 &mut self,
2788 previous_stack: TraitObligationStackList<'o, 'tcx>,
2789 obligation: &'o PolyTraitObligation<'tcx>,
2790 ) -> TraitObligationStack<'o, 'tcx> {
2791 let fresh_trait_pred = obligation.predicate.fold_with(&mut self.freshener);
2792
2793 let dfn = previous_stack.cache.next_dfn();
2794 let depth = previous_stack.depth() + 1;
2795 TraitObligationStack {
2796 obligation,
2797 fresh_trait_pred,
2798 reached_depth: Cell::new(depth),
2799 previous: previous_stack,
2800 dfn,
2801 depth,
2802 }
2803 }
2804
2805 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("closure_trait_ref_unnormalized",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(2805u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fn_trait_def_id")
}> =
::tracing::__macro_support::FieldName::new("fn_trait_def_id");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_trait_def_id)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: ty::PolyTraitRef<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let ty::Closure(_, args) =
*self_ty.kind() else {
::rustc_middle::util::bug::bug_fmt(format_args!("expected closure, found {0}",
self_ty));
};
let closure_sig = args.as_closure().sig();
closure_trait_ref_and_return_type(self.tcx(), fn_trait_def_id,
self_ty, closure_sig,
util::TupleArgumentsFlag::No).map_bound(|(trait_ref, _)|
trait_ref)
}
}
}#[instrument(skip(self), level = "debug")]
2806 fn closure_trait_ref_unnormalized(
2807 &mut self,
2808 self_ty: Ty<'tcx>,
2809 fn_trait_def_id: DefId,
2810 ) -> ty::PolyTraitRef<'tcx> {
2811 let ty::Closure(_, args) = *self_ty.kind() else {
2812 bug!("expected closure, found {self_ty}");
2813 };
2814 let closure_sig = args.as_closure().sig();
2815
2816 closure_trait_ref_and_return_type(
2817 self.tcx(),
2818 fn_trait_def_id,
2819 self_ty,
2820 closure_sig,
2821 util::TupleArgumentsFlag::No,
2822 )
2823 .map_bound(|(trait_ref, _)| trait_ref)
2824 }
2825
2826 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("impl_or_trait_obligations",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(2830u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("recursion_depth")
}> =
::tracing::__macro_support::FieldName::new("recursion_depth");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_id")
}> =
::tracing::__macro_support::FieldName::new("def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("args")
}> =
::tracing::__macro_support::FieldName::new("args");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("parent_trait_pred")
}> =
::tracing::__macro_support::FieldName::new("parent_trait_pred");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&recursion_depth
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&parent_trait_pred)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: PredicateObligations<'tcx> =
loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx();
let predicates = tcx.predicates_of(def_id);
{
match (&predicates.parent, &None) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
let predicates = predicates.instantiate_own(tcx, args);
let mut obligations =
PredicateObligations::with_capacity(predicates.len());
for (index, (predicate, span)) in
predicates.into_iter().enumerate() {
let cause =
if tcx.is_lang_item(parent_trait_pred.def_id(),
LangItem::CoerceUnsized) {
cause.clone()
} else {
cause.clone().derived_cause(parent_trait_pred,
|derived|
{
ObligationCauseCode::ImplDerived(Box::new(ImplDerivedCause {
derived,
impl_or_alias_def_id: def_id,
impl_def_predicate_index: Some(index),
span,
}))
})
};
let clause =
normalize_with_depth_to(self, param_env, cause.clone(),
recursion_depth, predicate, &mut obligations);
obligations.push(Obligation {
cause,
recursion_depth,
param_env,
predicate: clause.as_predicate(),
});
}
if tcx.def_kind(def_id) == (DefKind::Impl { of_trait: true }) {
for clause in
tcx.impl_super_outlives(def_id).iter_instantiated(tcx, args)
{
let clause =
normalize_with_depth_to(self, param_env, cause.clone(),
recursion_depth, clause, &mut obligations);
obligations.push(Obligation {
cause: cause.clone(),
recursion_depth,
param_env,
predicate: clause.as_predicate(),
});
}
}
obligations
}
}
}#[instrument(level = "debug", skip(self, cause, param_env))]
2831 fn impl_or_trait_obligations(
2832 &mut self,
2833 cause: &ObligationCause<'tcx>,
2834 recursion_depth: usize,
2835 param_env: ty::ParamEnv<'tcx>,
2836 def_id: DefId, args: GenericArgsRef<'tcx>, parent_trait_pred: ty::Binder<'tcx, ty::TraitPredicate<'tcx>>,
2839 ) -> PredicateObligations<'tcx> {
2840 let tcx = self.tcx();
2841
2842 let predicates = tcx.predicates_of(def_id);
2857 assert_eq!(predicates.parent, None);
2858 let predicates = predicates.instantiate_own(tcx, args);
2859 let mut obligations = PredicateObligations::with_capacity(predicates.len());
2860 for (index, (predicate, span)) in predicates.into_iter().enumerate() {
2861 let cause = if tcx.is_lang_item(parent_trait_pred.def_id(), LangItem::CoerceUnsized) {
2862 cause.clone()
2863 } else {
2864 cause.clone().derived_cause(parent_trait_pred, |derived| {
2865 ObligationCauseCode::ImplDerived(Box::new(ImplDerivedCause {
2866 derived,
2867 impl_or_alias_def_id: def_id,
2868 impl_def_predicate_index: Some(index),
2869 span,
2870 }))
2871 })
2872 };
2873 let clause = normalize_with_depth_to(
2874 self,
2875 param_env,
2876 cause.clone(),
2877 recursion_depth,
2878 predicate,
2879 &mut obligations,
2880 );
2881 obligations.push(Obligation {
2882 cause,
2883 recursion_depth,
2884 param_env,
2885 predicate: clause.as_predicate(),
2886 });
2887 }
2888
2889 if tcx.def_kind(def_id) == (DefKind::Impl { of_trait: true }) {
2891 for clause in tcx.impl_super_outlives(def_id).iter_instantiated(tcx, args) {
2892 let clause = normalize_with_depth_to(
2893 self,
2894 param_env,
2895 cause.clone(),
2896 recursion_depth,
2897 clause,
2898 &mut obligations,
2899 );
2900 obligations.push(Obligation {
2901 cause: cause.clone(),
2902 recursion_depth,
2903 param_env,
2904 predicate: clause.as_predicate(),
2905 });
2906 }
2907 }
2908
2909 obligations
2910 }
2911
2912 pub(super) fn should_stall_coroutine(&self, def_id: DefId) -> bool {
2913 match self.typing_mode() {
2914 TypingMode::Typeck { defining_opaque_types_and_generators: stalled_generators } => {
2915 def_id.as_local().is_some_and(|def_id| stalled_generators.contains(&def_id))
2916 }
2917 TypingMode::Coherence
2918 | TypingMode::PostAnalysis
2919 | TypingMode::Codegen
2920 | TypingMode::PostTypeckUntilBorrowck { defining_opaque_types: _ }
2921 | TypingMode::PostBorrowck { defined_opaque_types: _ } => false,
2922 }
2923 }
2924}
2925
2926impl<'o, 'tcx> TraitObligationStack<'o, 'tcx> {
2927 fn list(&'o self) -> TraitObligationStackList<'o, 'tcx> {
2928 TraitObligationStackList::with(self)
2929 }
2930
2931 fn cache(&self) -> &'o ProvisionalEvaluationCache<'tcx> {
2932 self.previous.cache
2933 }
2934
2935 fn iter(&'o self) -> TraitObligationStackList<'o, 'tcx> {
2936 self.list()
2937 }
2938
2939 fn update_reached_depth(&self, reached_depth: usize) {
2942 if !(self.depth >= reached_depth) {
{
::core::panicking::panic_fmt(format_args!("invoked `update_reached_depth` with something under this stack: self.depth={0} reached_depth={1}",
self.depth, reached_depth));
}
};assert!(
2943 self.depth >= reached_depth,
2944 "invoked `update_reached_depth` with something under this stack: \
2945 self.depth={} reached_depth={}",
2946 self.depth,
2947 reached_depth,
2948 );
2949 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:2949",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(2949u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("reached_depth")
}> =
::tracing::__macro_support::FieldName::new("reached_depth");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("update_reached_depth")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&reached_depth as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(reached_depth, "update_reached_depth");
2950 let mut p = self;
2951 while reached_depth < p.depth {
2952 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:2952",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(2952u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("p.fresh_trait_pred")
}> =
::tracing::__macro_support::FieldName::new("p.fresh_trait_pred");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("update_reached_depth: marking as cycle participant")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&p.fresh_trait_pred)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?p.fresh_trait_pred, "update_reached_depth: marking as cycle participant");
2953 p.reached_depth.set(p.reached_depth.get().min(reached_depth));
2954 p = p.previous.head.unwrap();
2955 }
2956 }
2957}
2958
2959struct ProvisionalEvaluationCache<'tcx> {
3013 dfn: Cell<usize>,
3015
3016 map: RefCell<FxIndexMap<ty::PolyTraitPredicate<'tcx>, ProvisionalEvaluation>>,
3032
3033 wf_args: RefCell<Vec<(ty::Term<'tcx>, usize)>>,
3041}
3042
3043#[derive(#[automatically_derived]
impl ::core::marker::Copy for ProvisionalEvaluation { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ProvisionalEvaluation {
#[inline]
fn clone(&self) -> ProvisionalEvaluation {
let _: ::core::clone::AssertParamIsClone<usize>;
let _: ::core::clone::AssertParamIsClone<EvaluationResult>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for ProvisionalEvaluation {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f,
"ProvisionalEvaluation", "from_dfn", &self.from_dfn,
"reached_depth", &self.reached_depth, "result", &&self.result)
}
}Debug)]
3046struct ProvisionalEvaluation {
3047 from_dfn: usize,
3048 reached_depth: usize,
3049 result: EvaluationResult,
3050}
3051
3052impl<'tcx> Default for ProvisionalEvaluationCache<'tcx> {
3053 fn default() -> Self {
3054 Self { dfn: Cell::new(0), map: Default::default(), wf_args: Default::default() }
3055 }
3056}
3057
3058impl<'tcx> ProvisionalEvaluationCache<'tcx> {
3059 fn next_dfn(&self) -> usize {
3061 let result = self.dfn.get();
3062 self.dfn.set(result + 1);
3063 result
3064 }
3065
3066 fn get_provisional(
3071 &self,
3072 fresh_trait_pred: ty::PolyTraitPredicate<'tcx>,
3073 ) -> Option<ProvisionalEvaluation> {
3074 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:3074",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(3074u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fresh_trait_pred")
}> =
::tracing::__macro_support::FieldName::new("fresh_trait_pred");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("get_provisional = {0:#?}",
self.map.borrow().get(&fresh_trait_pred)) as
&dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fresh_trait_pred)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
3075 ?fresh_trait_pred,
3076 "get_provisional = {:#?}",
3077 self.map.borrow().get(&fresh_trait_pred),
3078 );
3079 Some(*self.map.borrow().get(&fresh_trait_pred)?)
3080 }
3081
3082 fn insert_provisional(
3087 &self,
3088 from_dfn: usize,
3089 reached_depth: usize,
3090 fresh_trait_pred: ty::PolyTraitPredicate<'tcx>,
3091 result: EvaluationResult,
3092 ) {
3093 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:3093",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(3093u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("from_dfn")
}> =
::tracing::__macro_support::FieldName::new("from_dfn");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fresh_trait_pred")
}> =
::tracing::__macro_support::FieldName::new("fresh_trait_pred");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("result")
}> =
::tracing::__macro_support::FieldName::new("result");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("insert_provisional")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&from_dfn)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fresh_trait_pred)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&result)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?from_dfn, ?fresh_trait_pred, ?result, "insert_provisional");
3094
3095 let mut map = self.map.borrow_mut();
3096
3097 for (_k, v) in &mut *map {
3112 if v.from_dfn >= from_dfn {
3113 v.reached_depth = reached_depth.min(v.reached_depth);
3114 }
3115 }
3116
3117 map.insert(fresh_trait_pred, ProvisionalEvaluation { from_dfn, reached_depth, result });
3118 }
3119
3120 fn on_failure(&self, dfn: usize) {
3129 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:3129",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(3129u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("dfn")
}> =
::tracing::__macro_support::FieldName::new("dfn");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("on_failure")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&dfn)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?dfn, "on_failure");
3130 self.map.borrow_mut().retain(|key, eval| {
3131 if !eval.from_dfn >= dfn {
3132 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:3132",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(3132u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("on_failure: removing {0:?}",
key) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("on_failure: removing {:?}", key);
3133 false
3134 } else {
3135 true
3136 }
3137 });
3138 }
3139
3140 fn on_completion(&self, dfn: usize) {
3178 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:3178",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(3178u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("dfn")
}> =
::tracing::__macro_support::FieldName::new("dfn");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("on_completion")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&dfn)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?dfn, "on_completion");
3179 self.map.borrow_mut().retain(|fresh_trait_pred, eval| {
3180 if eval.from_dfn >= dfn {
3181 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/mod.rs:3181",
"rustc_trait_selection::traits::select",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/mod.rs"),
::tracing_core::__macro_support::Option::Some(3181u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fresh_trait_pred")
}> =
::tracing::__macro_support::FieldName::new("fresh_trait_pred");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("eval")
}> =
::tracing::__macro_support::FieldName::new("eval");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("on_completion")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fresh_trait_pred)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&eval)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?fresh_trait_pred, ?eval, "on_completion");
3182 return false;
3183 }
3184 true
3185 });
3186 }
3187}
3188
3189#[derive(#[automatically_derived]
impl<'o, 'tcx> ::core::marker::Copy for TraitObligationStackList<'o, 'tcx> { }Copy, #[automatically_derived]
impl<'o, 'tcx> ::core::clone::Clone for TraitObligationStackList<'o, 'tcx> {
#[inline]
fn clone(&self) -> TraitObligationStackList<'o, 'tcx> {
let _:
::core::clone::AssertParamIsClone<&'o ProvisionalEvaluationCache<'tcx>>;
let _:
::core::clone::AssertParamIsClone<Option<&'o TraitObligationStack<'o,
'tcx>>>;
*self
}
}Clone)]
3190struct TraitObligationStackList<'o, 'tcx> {
3191 cache: &'o ProvisionalEvaluationCache<'tcx>,
3192 head: Option<&'o TraitObligationStack<'o, 'tcx>>,
3193}
3194
3195impl<'o, 'tcx> TraitObligationStackList<'o, 'tcx> {
3196 fn empty(cache: &'o ProvisionalEvaluationCache<'tcx>) -> TraitObligationStackList<'o, 'tcx> {
3197 TraitObligationStackList { cache, head: None }
3198 }
3199
3200 fn with(r: &'o TraitObligationStack<'o, 'tcx>) -> TraitObligationStackList<'o, 'tcx> {
3201 TraitObligationStackList { cache: r.cache(), head: Some(r) }
3202 }
3203
3204 fn head(&self) -> Option<&'o TraitObligationStack<'o, 'tcx>> {
3205 self.head
3206 }
3207
3208 fn depth(&self) -> usize {
3209 if let Some(head) = self.head { head.depth } else { 0 }
3210 }
3211}
3212
3213impl<'o, 'tcx> Iterator for TraitObligationStackList<'o, 'tcx> {
3214 type Item = &'o TraitObligationStack<'o, 'tcx>;
3215
3216 fn next(&mut self) -> Option<&'o TraitObligationStack<'o, 'tcx>> {
3217 let o = self.head?;
3218 *self = o.previous;
3219 Some(o)
3220 }
3221}
3222
3223impl<'o, 'tcx> fmt::Debug for TraitObligationStack<'o, 'tcx> {
3224 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3225 f.write_fmt(format_args!("TraitObligationStack({0:?})", self.obligation))write!(f, "TraitObligationStack({:?})", self.obligation)
3226 }
3227}
3228
3229pub(crate) enum ProjectionMatchesProjection {
3230 Yes,
3231 Ambiguous,
3232 No,
3233}
3234
3235#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for AutoImplConstituents<'tcx> {
#[inline]
fn clone(&self) -> AutoImplConstituents<'tcx> {
AutoImplConstituents {
types: ::core::clone::Clone::clone(&self.types),
assumptions: ::core::clone::Clone::clone(&self.assumptions),
}
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for AutoImplConstituents<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"AutoImplConstituents", "types", &self.types, "assumptions",
&&self.assumptions)
}
}Debug, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
for AutoImplConstituents<'tcx> {
fn try_fold_with<__F: ::rustc_middle::ty::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Result<Self, __F::Error> {
Ok(match self {
AutoImplConstituents {
types: __binding_0, assumptions: __binding_1 } => {
AutoImplConstituents {
types: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
assumptions: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?,
}
}
})
}
fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Self {
match self {
AutoImplConstituents {
types: __binding_0, assumptions: __binding_1 } => {
AutoImplConstituents {
types: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
assumptions: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder),
}
}
}
}
}
};TypeFoldable, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
for AutoImplConstituents<'tcx> {
fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
AutoImplConstituents {
types: ref __binding_0, assumptions: 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);
}
}
}
}
}
<__V::Result as ::rustc_middle::ty::VisitorResult>::output()
}
}
};TypeVisitable)]
3236pub(crate) struct AutoImplConstituents<'tcx> {
3237 pub types: Vec<Ty<'tcx>>,
3238 pub assumptions: Vec<ty::ArgOutlivesPredicate<'tcx>>,
3239}