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_errors::{Diag, EmissionGuarantee};
13use rustc_hir::attrs::lang_items::LangItem;
14use rustc_hir::def_id::DefId;
15use rustc_hir::{self as hir, 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::{ImplSource, 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 PolyProjectionClause, SizedTraitKind, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, TypingMode,
31 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::PolyTraitClause<'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(ImplSource::Builtin(..)) if self.typing_mode().is_reflection() => {
286 Err(SelectionError::Unimplemented)
289 }
290 Ok(candidate) => Ok(Some(candidate)),
291 }
292 }
293
294 pub fn select(
295 &mut self,
296 obligation: &TraitObligation<'tcx>,
297 ) -> SelectionResult<'tcx, Selection<'tcx>> {
298 if self.infcx.next_trait_solver() {
299 return self.infcx.select_in_new_trait_solver(obligation);
300 }
301
302 self.poly_select(&Obligation {
303 cause: obligation.cause.clone(),
304 param_env: obligation.param_env,
305 predicate: ty::Binder::dummy(obligation.predicate),
306 recursion_depth: obligation.recursion_depth,
307 })
308 }
309
310 fn select_from_obligation(
311 &mut self,
312 obligation: &PolyTraitObligation<'tcx>,
313 ) -> SelectionResult<'tcx, SelectionCandidate<'tcx>> {
314 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());
315
316 let pec = &ProvisionalEvaluationCache::default();
317 let stack = self.push_stack(TraitObligationStackList::empty(pec), obligation);
318
319 self.candidate_from_obligation(&stack)
320 }
321
322 x;#[instrument(level = "debug", skip(self), ret)]
323 fn candidate_from_obligation<'o>(
324 &mut self,
325 stack: &TraitObligationStack<'o, 'tcx>,
326 ) -> SelectionResult<'tcx, SelectionCandidate<'tcx>> {
327 debug_assert!(!self.infcx.next_trait_solver());
328 self.check_recursion_limit(stack.obligation, stack.obligation)?;
331
332 let cache_fresh_trait_pred =
337 stack.obligation.predicate.fold_with(&mut TypeFreshener::new(self.infcx));
338 debug!(?cache_fresh_trait_pred);
339 debug_assert!(!stack.obligation.predicate.has_escaping_bound_vars());
340
341 if let Some(c) =
342 self.check_candidate_cache(stack.obligation.param_env, cache_fresh_trait_pred)
343 {
344 debug!("CACHE HIT");
345 return c;
346 }
347
348 let (candidate, dep_node) =
355 self.in_task(|this| this.candidate_from_obligation_no_cache(stack));
356
357 debug!("CACHE MISS");
358 self.insert_candidate_cache(
359 stack.obligation.param_env,
360 cache_fresh_trait_pred,
361 dep_node,
362 candidate.clone(),
363 );
364 candidate
365 }
366
367 fn candidate_from_obligation_no_cache<'o>(
368 &mut self,
369 stack: &TraitObligationStack<'o, 'tcx>,
370 ) -> SelectionResult<'tcx, SelectionCandidate<'tcx>> {
371 if let Err(conflict) = self.is_knowable(stack) {
372 {
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:372",
"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(372u32),
::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");
373 if self.intercrate_ambiguity_causes.is_some() {
374 {
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:374",
"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(374u32),
::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");
375 if let Ok(candidate_set) = self.assemble_candidates(stack) {
377 let mut no_candidates_apply = true;
378
379 for c in candidate_set.vec.iter() {
380 if self.evaluate_candidate(stack, c)?.may_apply() {
381 no_candidates_apply = false;
382 break;
383 }
384 }
385
386 if !candidate_set.ambiguous && no_candidates_apply {
387 let trait_ref = self.infcx.resolve_vars_if_possible(
388 stack.obligation.predicate.skip_binder().trait_ref,
389 );
390 if !trait_ref.references_error() {
391 let self_ty = trait_ref.self_ty();
392 let self_ty = self_ty.has_concrete_skeleton().then(|| self_ty);
393 let cause = if let Conflict::Upstream = conflict {
394 IntercrateAmbiguityCause::UpstreamCrateUpdate { trait_ref, self_ty }
395 } else {
396 IntercrateAmbiguityCause::DownstreamCrate { trait_ref, self_ty }
397 };
398 {
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:398",
"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(398u32),
::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");
399 self.intercrate_ambiguity_causes.as_mut().unwrap().insert(cause);
400 }
401 }
402 }
403 }
404 return Ok(None);
405 }
406
407 let candidate_set = self.assemble_candidates(stack)?;
408
409 if candidate_set.ambiguous {
410 {
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:410",
"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(410u32),
::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");
411 return Ok(None);
412 }
413
414 let candidates = candidate_set.vec;
415
416 {
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:416",
"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(416u32),
::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());
417
418 let mut candidates = self.filter_impls(candidates, stack.obligation);
428
429 if candidates.len() == 1 {
444 return self.filter_reservation_impls(candidates.pop().unwrap());
445 }
446
447 let candidates = candidates
450 .into_iter()
451 .map(|c| match self.evaluate_candidate(stack, &c) {
452 Ok(eval) if eval.may_apply() => {
453 Ok(Some(EvaluatedCandidate { candidate: c, evaluation: eval }))
454 }
455 Ok(_) => Ok(None),
456 Err(OverflowError::Canonical) => {
457 Err(SelectionError::Overflow(OverflowError::Canonical))
458 }
459 Err(OverflowError::Error(e)) => {
460 Err(SelectionError::Overflow(OverflowError::Error(e)))
461 }
462 })
463 .flat_map(Result::transpose)
464 .collect::<Result<Vec<_>, _>>()?;
465
466 {
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:466",
"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(466u32),
::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());
467 if candidates.is_empty() {
477 if stack.obligation.predicate.references_error() {
482 {
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:482",
"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(482u32),
::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");
483 Ok(None)
484 } else {
485 Err(SelectionError::Unimplemented)
486 }
487 } else {
488 let has_non_region_infer = stack.obligation.predicate.has_non_region_infer();
489 let candidate_preference_mode =
490 CandidatePreferenceMode::compute(self.tcx(), stack.obligation.predicate.def_id());
491 if let Some(candidate) =
492 self.winnow_candidates(has_non_region_infer, candidate_preference_mode, candidates)
493 {
494 self.filter_reservation_impls(candidate)
495 } else {
496 Ok(None)
497 }
498 }
499 }
500
501 pub fn evaluate_root_obligation(
517 &mut self,
518 obligation: &PredicateObligation<'tcx>,
519 ) -> Result<EvaluationResult, OverflowError> {
520 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());
521 self.evaluation_probe(|this| {
522 let goal =
523 this.infcx.resolve_vars_if_possible((obligation.predicate, obligation.param_env));
524 let mut result = this.evaluate_predicate_recursively(
525 TraitObligationStackList::empty(&ProvisionalEvaluationCache::default()),
526 obligation.clone(),
527 )?;
528 if this.infcx.resolve_vars_if_possible(goal) != goal {
531 result = result.max(EvaluatedToAmbig);
532 }
533 Ok(result)
534 })
535 }
536
537 fn evaluation_probe(
543 &mut self,
544 op: impl FnOnce(&mut Self) -> Result<EvaluationResult, OverflowError>,
545 ) -> Result<EvaluationResult, OverflowError> {
546 self.infcx.probe(|snapshot| -> Result<EvaluationResult, OverflowError> {
547 let outer_universe = self.infcx.universe();
548 let result = op(self)?;
549
550 match self.infcx.leak_check(outer_universe, Some(snapshot)) {
551 Ok(()) => {}
552 Err(_) => return Ok(EvaluatedToErr),
553 }
554
555 if self.infcx.opaque_types_added_in_snapshot(snapshot) {
556 return Ok(result.max(EvaluatedToOkModuloOpaqueTypes));
557 }
558
559 if self.infcx.region_constraints_added_in_snapshot(snapshot) {
560 Ok(result.max(EvaluatedToOkModuloRegions))
561 } else {
562 Ok(result)
563 }
564 })
565 }
566
567 #[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(571u32),
::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")]
572 fn evaluate_predicates_recursively<'o, I>(
573 &mut self,
574 stack: TraitObligationStackList<'o, 'tcx>,
575 predicates: I,
576 ) -> Result<EvaluationResult, OverflowError>
577 where
578 I: IntoIterator<Item = PredicateObligation<'tcx>> + std::fmt::Debug,
579 {
580 let mut result = EvaluatedToOk;
581 for mut obligation in predicates {
582 obligation.set_depth_from_parent(stack.depth());
583 let eval = self.evaluate_predicate_recursively(stack, obligation.clone())?;
584 if let EvaluatedToErr = eval {
585 return Ok(EvaluatedToErr);
588 } else {
589 result = cmp::max(result, eval);
590 }
591 }
592 Ok(result)
593 }
594
595 x;#[instrument(
596 level = "debug",
597 skip(self, previous_stack),
598 fields(previous_stack = ?previous_stack.head())
599 ret,
600 )]
601 fn evaluate_predicate_recursively<'o>(
602 &mut self,
603 previous_stack: TraitObligationStackList<'o, 'tcx>,
604 obligation: PredicateObligation<'tcx>,
605 ) -> Result<EvaluationResult, OverflowError> {
606 debug_assert!(!self.infcx.next_trait_solver());
607 match previous_stack.head() {
612 Some(h) => self.check_recursion_limit(&obligation, h.obligation)?,
613 None => self.check_recursion_limit(&obligation, &obligation)?,
614 }
615
616 if !self.infcx.disable_trait_solver_fast_paths()
617 && sizedness_fast_path(self.tcx(), obligation.predicate, obligation.param_env)
618 {
619 return Ok(EvaluatedToOk);
620 }
621
622 let bound_predicate = obligation.predicate.kind();
623 match bound_predicate.skip_binder() {
624 ty::PredicateKind::Clause(ty::ClauseKind::Trait(t)) => {
625 let t = bound_predicate.rebind(t);
626 debug_assert!(!t.has_escaping_bound_vars());
627 let obligation = obligation.with(self.tcx(), t);
628 self.evaluate_trait_predicate_recursively(previous_stack, obligation)
629 }
630
631 ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(data)) => {
632 self.infcx.enter_forall(bound_predicate.rebind(data), |data| {
633 match effects::evaluate_host_effect_obligation(
634 self,
635 &obligation.with(self.tcx(), data),
636 ) {
637 Ok(nested) => self.evaluate_predicates_recursively(previous_stack, nested),
638 Err(effects::EvaluationFailure::Ambiguous) => Ok(EvaluatedToAmbig),
639 Err(effects::EvaluationFailure::NoSolution) => Ok(EvaluatedToErr),
640 }
641 })
642 }
643
644 ty::PredicateKind::Subtype(p) => {
645 let p = bound_predicate.rebind(p);
646 match self.infcx.subtype_predicate(&obligation.cause, obligation.param_env, p) {
648 Ok(Ok(InferOk { obligations, .. })) => {
649 self.evaluate_predicates_recursively(previous_stack, obligations)
650 }
651 Ok(Err(_)) => Ok(EvaluatedToErr),
652 Err(..) => Ok(EvaluatedToAmbig),
653 }
654 }
655
656 ty::PredicateKind::Coerce(p) => {
657 let p = bound_predicate.rebind(p);
658 match self.infcx.coerce_predicate(&obligation.cause, obligation.param_env, p) {
660 Ok(Ok(InferOk { obligations, .. })) => {
661 self.evaluate_predicates_recursively(previous_stack, obligations)
662 }
663 Ok(Err(_)) => Ok(EvaluatedToErr),
664 Err(..) => Ok(EvaluatedToAmbig),
665 }
666 }
667
668 ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(term)) => {
669 if term.is_trivially_wf(self.tcx()) {
670 return Ok(EvaluatedToOk);
671 }
672
673 let cache = previous_stack.cache;
694 let dfn = cache.next_dfn();
695
696 for stack_term in previous_stack.cache.wf_args.borrow().iter().rev() {
697 if stack_term.0 != term {
698 continue;
699 }
700 debug!("WellFormed({:?}) on stack", term);
701 if let Some(stack) = previous_stack.head {
702 let cycle = stack.iter().take_while(|s| s.depth > stack_term.1);
717 let tcx = self.tcx();
718 let cycle = cycle.map(|stack| stack.obligation.predicate.upcast(tcx));
719 if self.coinductive_match(cycle) {
720 stack.update_reached_depth(stack_term.1);
721 return Ok(EvaluatedToOk);
722 } else {
723 return Ok(EvaluatedToAmbigStackDependent);
724 }
725 }
726 return Ok(EvaluatedToOk);
727 }
728
729 match wf::obligations(
730 self.infcx,
731 obligation.param_env,
732 obligation.cause.body_def_id,
733 obligation.recursion_depth + 1,
734 term,
735 obligation.cause.span,
736 ) {
737 Some(obligations) => {
738 cache.wf_args.borrow_mut().push((term, previous_stack.depth()));
739 let result =
740 self.evaluate_predicates_recursively(previous_stack, obligations);
741 cache.wf_args.borrow_mut().pop();
742
743 let result = result?;
744
745 if !result.must_apply_modulo_regions() {
746 cache.on_failure(dfn);
747 }
748
749 cache.on_completion(dfn);
750
751 Ok(result)
752 }
753 None => Ok(EvaluatedToAmbig),
754 }
755 }
756
757 ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(pred)) => {
758 if pred.0.has_free_regions()
761 || pred.0.has_bound_regions()
762 || pred.0.has_non_region_infer()
763 || pred.0.has_non_region_param()
764 {
765 Ok(EvaluatedToOkModuloRegions)
766 } else {
767 Ok(EvaluatedToOk)
768 }
769 }
770
771 ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(..)) => {
772 Ok(EvaluatedToOkModuloRegions)
774 }
775
776 ty::PredicateKind::DynCompatible(trait_def_id) => {
777 if self.tcx().is_dyn_compatible(trait_def_id) {
782 Ok(EvaluatedToOk)
783 } else {
784 Ok(EvaluatedToErr)
785 }
786 }
787
788 ty::PredicateKind::Clause(ty::ClauseKind::Projection(data)) => {
789 let data = bound_predicate.rebind(data);
790 let project_obligation = obligation.with(self.tcx(), data);
791 match project::poly_project_and_unify_term(self, &project_obligation) {
792 ProjectAndUnifyResult::Holds(mut subobligations) => {
793 'compute_res: {
794 if let Some(key) = ProjectionCacheKey::from_poly_projection_obligation(
799 self,
800 &project_obligation,
801 ) && let Some(cached_res) =
802 self.infcx.inner.borrow_mut().projection_cache().is_complete(key)
803 {
804 break 'compute_res Ok(cached_res);
805 }
806
807 for subobligation in subobligations.iter_mut() {
813 subobligation.set_depth_from_parent(obligation.recursion_depth);
814 }
815 let res = self
816 .evaluate_predicates_recursively(previous_stack, subobligations);
817 if let Ok(eval_rslt) = res
818 && (eval_rslt == EvaluatedToOk
819 || eval_rslt == EvaluatedToOkModuloRegions)
820 && let Some(key) =
821 ProjectionCacheKey::from_poly_projection_obligation(
822 self,
823 &project_obligation,
824 )
825 {
826 self.infcx
831 .inner
832 .borrow_mut()
833 .projection_cache()
834 .complete(key, eval_rslt);
835 }
836 res
837 }
838 }
839 ProjectAndUnifyResult::FailedNormalization => Ok(EvaluatedToAmbig),
840 ProjectAndUnifyResult::Recursive => Ok(EvaluatedToAmbigStackDependent),
841 ProjectAndUnifyResult::MismatchedProjectionTypes(_) => Ok(EvaluatedToErr),
842 }
843 }
844
845 ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(symbol)) => {
846 if may_use_unstable_feature(self.infcx, obligation.param_env, symbol) {
847 Ok(EvaluatedToOk)
848 } else {
849 Ok(EvaluatedToAmbig)
850 }
851 }
852
853 ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(alias_const)) => {
854 match const_evaluatable::is_const_evaluatable(
855 self.infcx,
856 alias_const,
857 obligation.param_env,
858 obligation.cause.span,
859 ) {
860 Ok(()) => Ok(EvaluatedToOk),
861 Err(NotConstEvaluatable::MentionsInfer) => Ok(EvaluatedToAmbig),
862 Err(NotConstEvaluatable::MentionsParam) => Ok(EvaluatedToErr),
863 Err(_) => Ok(EvaluatedToErr),
864 }
865 }
866
867 ty::PredicateKind::ConstEquate(c1, c2) => {
868 let tcx = self.tcx();
869 assert!(
870 tcx.features().generic_const_exprs(),
871 "`ConstEquate` without a feature gate: {c1:?} {c2:?}",
872 );
873
874 {
875 let c1 = tcx.expand_abstract_consts(c1);
876 let c2 = tcx.expand_abstract_consts(c2);
877 debug!(
878 "evaluate_predicate_recursively: equating consts:\nc1= {:?}\nc2= {:?}",
879 c1, c2
880 );
881
882 match (c1.kind(), c2.kind()) {
883 (ty::ConstKind::Alias(_, a), ty::ConstKind::Alias(_, b))
884 if a.kind == b.kind
885 && matches!(
886 a.kind,
887 ty::AliasConstKind::Projection { .. }
888 | ty::AliasConstKind::Inherent { .. }
889 ) =>
890 {
891 if let Ok(InferOk { obligations, value: () }) = self
892 .infcx
893 .at(&obligation.cause, obligation.param_env)
894 .eq(
897 DefineOpaqueTypes::Yes,
898 ty::AliasTerm::from(a),
899 ty::AliasTerm::from(b),
900 )
901 {
902 return self
903 .evaluate_predicates_recursively(previous_stack, obligations);
904 }
905 }
906 (_, ty::ConstKind::Alias(_, _)) | (ty::ConstKind::Alias(_, _), _) => (),
907 (_, _) => {
908 if let Ok(InferOk { obligations, value: () }) = self
909 .infcx
910 .at(&obligation.cause, obligation.param_env)
911 .eq(DefineOpaqueTypes::Yes, c1, c2)
914 {
915 return self
916 .evaluate_predicates_recursively(previous_stack, obligations);
917 }
918 }
919 }
920 }
921
922 let evaluate = |c: ty::Const<'tcx>| {
923 if let ty::ConstKind::Alias(_, _) = c.kind() {
924 crate::traits::try_evaluate_const(
925 self.infcx,
926 c,
927 obligation.param_env,
928 |v| Ok::<_, !>(v.skip_norm_wip()),
929 )
930 } else {
931 Ok(c)
932 }
933 };
934
935 match (evaluate(c1), evaluate(c2)) {
936 (Ok(c1), Ok(c2)) => {
937 match self.infcx.at(&obligation.cause, obligation.param_env).eq(
938 DefineOpaqueTypes::Yes,
941 c1,
942 c2,
943 ) {
944 Ok(inf_ok) => self.evaluate_predicates_recursively(
945 previous_stack,
946 inf_ok.into_obligations(),
947 ),
948 Err(_) => Ok(EvaluatedToErr),
949 }
950 }
951 (Err(EvaluateConstErr::InvalidConstParamTy(..)), _)
952 | (_, Err(EvaluateConstErr::InvalidConstParamTy(..))) => Ok(EvaluatedToErr),
953 (Err(EvaluateConstErr::EvaluationFailure(..)), _)
954 | (_, Err(EvaluateConstErr::EvaluationFailure(..))) => Ok(EvaluatedToErr),
955 (Err(EvaluateConstErr::HasGenericsOrInfers), _)
956 | (_, Err(EvaluateConstErr::HasGenericsOrInfers)) => {
957 if c1.has_non_region_infer() || c2.has_non_region_infer() {
958 Ok(EvaluatedToAmbig)
959 } else {
960 Ok(EvaluatedToErr)
962 }
963 }
964 }
965 }
966 ty::PredicateKind::NormalizesTo(..) => {
967 bug!("NormalizesTo is only used by the new solver")
968 }
969 ty::PredicateKind::Ambiguous => Ok(EvaluatedToAmbig),
970 ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
971 let ct = self.infcx.shallow_resolve_const(ct);
972 let ct_ty = match ct.kind() {
973 ty::ConstKind::Infer(_) => {
974 return Ok(EvaluatedToAmbig);
975 }
976 ty::ConstKind::Error(_) => return Ok(EvaluatedToOk),
977 ty::ConstKind::Value(cv) => cv.ty,
978 ty::ConstKind::Alias(_, alias_const) => {
979 alias_const.type_of(self.tcx()).skip_norm_wip()
980 }
981 ty::ConstKind::Expr(_) => return Ok(EvaluatedToOk),
983 ty::ConstKind::Placeholder(_) => {
984 bug!("placeholder const {:?} in old solver", ct)
985 }
986 ty::ConstKind::Bound(_, _) => bug!("escaping bound vars in {:?}", ct),
987 ty::ConstKind::Param(param_ct) => {
988 param_ct.find_const_ty_from_env(obligation.param_env)
989 }
990 };
991
992 match self.infcx.at(&obligation.cause, obligation.param_env).eq(
993 DefineOpaqueTypes::Yes,
995 ct_ty,
996 ty,
997 ) {
998 Ok(inf_ok) => self
999 .evaluate_predicates_recursively(previous_stack, inf_ok.into_obligations()),
1000 Err(_) => Ok(EvaluatedToErr),
1001 }
1002 }
1003 }
1004 }
1005
1006 x;#[instrument(skip(self, previous_stack), level = "debug", ret)]
1007 fn evaluate_trait_predicate_recursively<'o>(
1008 &mut self,
1009 previous_stack: TraitObligationStackList<'o, 'tcx>,
1010 mut obligation: PolyTraitObligation<'tcx>,
1011 ) -> Result<EvaluationResult, OverflowError> {
1012 if !self.typing_mode().is_coherence()
1013 && obligation.is_global()
1014 && obligation.param_env.caller_bounds().iter().all(|bound| bound.has_param())
1015 {
1016 debug!("in global");
1020 obligation.param_env = ty::ParamEnv::empty();
1021 }
1022
1023 let stack = self.push_stack(previous_stack, &obligation);
1024 let fresh_trait_pred = stack.fresh_trait_pred;
1025 let param_env = obligation.param_env;
1026
1027 debug!(?fresh_trait_pred);
1028
1029 if let Some(result) = self.check_evaluation_cache(param_env, fresh_trait_pred) {
1032 debug!("CACHE HIT");
1033 return Ok(result);
1034 }
1035
1036 if let Some(result) = stack.cache().get_provisional(fresh_trait_pred) {
1037 debug!("PROVISIONAL CACHE HIT");
1038 stack.update_reached_depth(result.reached_depth);
1039 return Ok(result.result);
1040 }
1041
1042 if let Some(cycle_result) = self.check_evaluation_cycle(&stack) {
1048 return Ok(cycle_result);
1049 }
1050
1051 let (result, dep_node) = self.in_task(|this| {
1052 let mut result = this.evaluate_stack(&stack)?;
1053
1054 if EvaluationResult::EvaluatedToErr == result
1062 && fresh_trait_pred.has_aliases()
1063 && fresh_trait_pred.is_global()
1064 {
1065 let mut nested_obligations = PredicateObligations::new();
1066 let predicate = normalize_with_depth_to(
1067 this,
1068 param_env,
1069 obligation.cause.clone(),
1070 obligation.recursion_depth + 1,
1071 Unnormalized::new_wip(obligation.predicate),
1072 &mut nested_obligations,
1073 );
1074 if predicate != obligation.predicate {
1075 let mut nested_result = EvaluationResult::EvaluatedToOk;
1076 for obligation in nested_obligations {
1077 nested_result = cmp::max(
1078 this.evaluate_predicate_recursively(previous_stack, obligation)?,
1079 nested_result,
1080 );
1081 }
1082
1083 if nested_result.must_apply_modulo_regions() {
1084 let obligation = obligation.with(this.tcx(), predicate);
1085 result = cmp::max(
1086 nested_result,
1087 this.evaluate_trait_predicate_recursively(previous_stack, obligation)?,
1088 );
1089 }
1090 }
1091 }
1092
1093 Ok::<_, OverflowError>(result)
1094 });
1095
1096 let result = result?;
1097
1098 if !result.must_apply_modulo_regions() {
1099 stack.cache().on_failure(stack.dfn);
1100 }
1101
1102 let reached_depth = stack.reached_depth.get();
1103 if reached_depth >= stack.depth {
1104 debug!("CACHE MISS");
1105 self.insert_evaluation_cache(param_env, fresh_trait_pred, dep_node, result);
1106 stack.cache().on_completion(stack.dfn);
1107 } else if let Some(_guar) = self.infcx.tainted_by_errors() {
1108 debug!("CACHE MISS (tainted by errors)");
1113 self.insert_evaluation_cache(param_env, fresh_trait_pred, dep_node, result);
1114 stack.cache().on_completion(stack.dfn);
1115 } else {
1116 debug!("PROVISIONAL");
1117 debug!(
1118 "caching provisionally because {:?} \
1119 is a cycle participant (at depth {}, reached depth {})",
1120 fresh_trait_pred, stack.depth, reached_depth,
1121 );
1122
1123 stack.cache().insert_provisional(stack.dfn, reached_depth, fresh_trait_pred, result);
1124 }
1125
1126 Ok(result)
1127 }
1128
1129 fn check_evaluation_cycle(
1149 &mut self,
1150 stack: &TraitObligationStack<'_, 'tcx>,
1151 ) -> Option<EvaluationResult> {
1152 if let Some(cycle_depth) = stack
1153 .iter()
1154 .skip(1) .find(|prev| {
1156 stack.obligation.param_env == prev.obligation.param_env
1157 && stack.fresh_trait_pred == prev.fresh_trait_pred
1158 })
1159 .map(|stack| stack.depth)
1160 {
1161 {
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:1161",
"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(1161u32),
::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);
1162
1163 stack.update_reached_depth(cycle_depth);
1170
1171 let cycle = stack.iter().skip(1).take_while(|s| s.depth >= cycle_depth);
1177 let tcx = self.tcx();
1178 let cycle = cycle.map(|stack| stack.obligation.predicate.upcast(tcx));
1179 if self.coinductive_match(cycle) {
1180 {
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:1180",
"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(1180u32),
::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");
1181 Some(EvaluatedToOk)
1182 } else {
1183 {
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:1183",
"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(1183u32),
::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");
1184 Some(EvaluatedToAmbigStackDependent)
1185 }
1186 } else {
1187 None
1188 }
1189 }
1190
1191 fn evaluate_stack<'o>(
1192 &mut self,
1193 stack: &TraitObligationStack<'o, 'tcx>,
1194 ) -> Result<EvaluationResult, OverflowError> {
1195 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());
1196 let unbound_input_types =
1223 stack.fresh_trait_pred.skip_binder().trait_ref.args.types().any(|ty| ty.is_fresh());
1224
1225 if unbound_input_types
1226 && stack.iter().skip(1).any(|prev| {
1227 stack.obligation.param_env == prev.obligation.param_env
1228 && self.match_fresh_trait_preds(stack.fresh_trait_pred, prev.fresh_trait_pred)
1229 })
1230 {
1231 {
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:1231",
"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(1231u32),
::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");
1232 return Ok(EvaluatedToAmbigStackDependent);
1233 }
1234
1235 match self.candidate_from_obligation(stack) {
1236 Ok(Some(c)) => self.evaluate_candidate(stack, &c),
1237 Ok(None) => Ok(EvaluatedToAmbig),
1238 Err(SelectionError::Overflow(OverflowError::Canonical)) => {
1239 Err(OverflowError::Canonical)
1240 }
1241 Err(..) => Ok(EvaluatedToErr),
1242 }
1243 }
1244
1245 pub(crate) fn coinductive_match<I>(&mut self, mut cycle: I) -> bool
1254 where
1255 I: Iterator<Item = ty::Predicate<'tcx>>,
1256 {
1257 cycle.all(|p| match p.kind().skip_binder() {
1258 ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => {
1259 self.infcx.tcx.trait_is_coinductive(data.def_id())
1260 }
1261 ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => {
1262 self.infcx.tcx.features().generic_const_exprs()
1266 }
1267 _ => false,
1268 })
1269 }
1270
1271 x;#[instrument(
1275 level = "debug",
1276 skip(self, stack),
1277 fields(depth = stack.obligation.recursion_depth),
1278 ret
1279 )]
1280 fn evaluate_candidate<'o>(
1281 &mut self,
1282 stack: &TraitObligationStack<'o, 'tcx>,
1283 candidate: &SelectionCandidate<'tcx>,
1284 ) -> Result<EvaluationResult, OverflowError> {
1285 let mut result = self.evaluation_probe(|this| {
1286 match this.confirm_candidate(stack.obligation, candidate.clone()) {
1287 Ok(selection) => {
1288 debug!(?selection);
1289 if let ImplSource::Builtin(..) = selection
1290 && this.typing_mode().is_reflection()
1291 {
1292 return Ok(EvaluatedToErr);
1293 }
1294 this.evaluate_predicates_recursively(
1295 stack.list(),
1296 selection.nested_obligations().into_iter(),
1297 )
1298 }
1299 Err(..) => Ok(EvaluatedToErr),
1300 }
1301 })?;
1302
1303 if stack.fresh_trait_pred.has_erased_regions() {
1312 result = result.max(EvaluatedToOkModuloRegions);
1313 }
1314
1315 Ok(result)
1316 }
1317
1318 fn check_evaluation_cache(
1319 &self,
1320 param_env: ty::ParamEnv<'tcx>,
1321 trait_pred: ty::PolyTraitClause<'tcx>,
1322 ) -> Option<EvaluationResult> {
1323 let infcx = self.infcx;
1324 let tcx = infcx.tcx;
1325 if self.can_use_global_caches(param_env, trait_pred) {
1326 let key = (infcx.typing_env(param_env), trait_pred);
1327 if let Some(res) = tcx.caches.evaluation_cache.get(&key, tcx) {
1328 Some(res)
1329 } else {
1330 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);
1331 None
1332 }
1333 } else {
1334 self.infcx.evaluation_cache.get(&(param_env, trait_pred), tcx)
1335 }
1336 }
1337
1338 fn insert_evaluation_cache(
1339 &mut self,
1340 param_env: ty::ParamEnv<'tcx>,
1341 trait_pred: ty::PolyTraitClause<'tcx>,
1342 dep_node: DepNodeIndex,
1343 result: EvaluationResult,
1344 ) {
1345 if result.is_stack_dependent() {
1348 return;
1349 }
1350
1351 let infcx = self.infcx;
1352 let tcx = infcx.tcx;
1353 if self.can_use_global_caches(param_env, trait_pred) {
1354 {
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:1354",
"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(1354u32),
::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");
1355 tcx.caches.evaluation_cache.insert(
1357 (infcx.typing_env(param_env), trait_pred),
1358 dep_node,
1359 result,
1360 );
1361 return;
1362 } else {
1363 {
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:1363",
"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(1363u32),
::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");
1364 self.infcx.evaluation_cache.insert((param_env, trait_pred), dep_node, result);
1365 }
1366 }
1367
1368 fn check_recursion_depth<T>(
1369 &self,
1370 depth: usize,
1371 error_obligation: &Obligation<'tcx, T>,
1372 ) -> Result<(), OverflowError>
1373 where
1374 T: Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>> + Clone,
1375 {
1376 if !self.infcx.tcx.recursion_limit().value_within_limit(depth) {
1377 match self.query_mode {
1378 TraitQueryMode::Standard => {
1379 if let Some(e) = self.infcx.tainted_by_errors() {
1380 return Err(OverflowError::Error(e));
1381 }
1382 self.infcx.err_ctxt().report_overflow_obligation(error_obligation, true);
1383 }
1384 TraitQueryMode::Canonical => {
1385 return Err(OverflowError::Canonical);
1386 }
1387 }
1388 }
1389 Ok(())
1390 }
1391
1392 #[inline(always)]
1397 fn check_recursion_limit<T: Display + TypeFoldable<TyCtxt<'tcx>>, V>(
1398 &self,
1399 obligation: &Obligation<'tcx, T>,
1400 error_obligation: &Obligation<'tcx, V>,
1401 ) -> Result<(), OverflowError>
1402 where
1403 V: Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>> + Clone,
1404 {
1405 self.check_recursion_depth(obligation.recursion_depth, error_obligation)
1406 }
1407
1408 fn in_task<OP, R>(&mut self, op: OP) -> (R, DepNodeIndex)
1409 where
1410 OP: FnOnce(&mut Self) -> R,
1411 {
1412 self.tcx().dep_graph.with_anon_task(self.tcx(), DepKind::TraitSelect, || op(self))
1413 }
1414
1415 #[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(1417u32),
::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:1423",
"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(1423u32),
::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::ClausePolarity::Positive) |
(ty::ImplPolarity::Negative, ty::ClausePolarity::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:1442",
"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(1442u32),
::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))]
1418 fn filter_impls(
1419 &mut self,
1420 candidates: Vec<SelectionCandidate<'tcx>>,
1421 obligation: &PolyTraitObligation<'tcx>,
1422 ) -> Vec<SelectionCandidate<'tcx>> {
1423 trace!("{candidates:#?}");
1424 let tcx = self.tcx();
1425 let mut result = Vec::with_capacity(candidates.len());
1426
1427 for candidate in candidates {
1428 if let ImplCandidate(def_id) = candidate {
1429 match (tcx.impl_polarity(def_id), obligation.polarity()) {
1430 (ty::ImplPolarity::Reservation, _)
1431 | (ty::ImplPolarity::Positive, ty::ClausePolarity::Positive)
1432 | (ty::ImplPolarity::Negative, ty::ClausePolarity::Negative) => {
1433 result.push(candidate);
1434 }
1435 _ => {}
1436 }
1437 } else {
1438 result.push(candidate);
1439 }
1440 }
1441
1442 trace!("{result:#?}");
1443 result
1444 }
1445
1446 #[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(1447u32),
::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_attr_ir::HasAttrs::get_attrs(def_id, &tcx)
{
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(RustcReservationImpl(message))
=> {
break 'done Some(*message);
}
::rustc_attr_ir::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:1460",
"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(1460u32),
::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))]
1448 fn filter_reservation_impls(
1449 &mut self,
1450 candidate: SelectionCandidate<'tcx>,
1451 ) -> SelectionResult<'tcx, SelectionCandidate<'tcx>> {
1452 let tcx = self.tcx();
1453 if let ImplCandidate(def_id) = candidate
1455 && let ty::ImplPolarity::Reservation = tcx.impl_polarity(def_id)
1456 {
1457 if let Some(intercrate_ambiguity_clauses) = &mut self.intercrate_ambiguity_causes {
1458 let message = find_attr!(tcx, def_id, RustcReservationImpl(message) => *message);
1459 if let Some(message) = message {
1460 debug!(
1461 "filter_reservation_impls: \
1462 reservation impl ambiguity on {:?}",
1463 def_id
1464 );
1465 intercrate_ambiguity_clauses
1466 .insert(IntercrateAmbiguityCause::ReservationImpl { message });
1467 }
1468 }
1469 return Ok(None);
1470 }
1471 Ok(Some(candidate))
1472 }
1473
1474 fn is_knowable<'o>(&mut self, stack: &TraitObligationStack<'o, 'tcx>) -> Result<(), Conflict> {
1475 let obligation = &stack.obligation;
1476 match self.typing_mode() {
1477 TypingMode::Coherence => {}
1478 TypingMode::Typeck { .. }
1479 | TypingMode::PostTypeckUntilBorrowck { .. }
1480 | TypingMode::Reflection
1481 | TypingMode::PostBorrowck { .. }
1482 | TypingMode::PostAnalysis
1483 | TypingMode::Codegen => return Ok(()),
1484 }
1485
1486 {
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:1486",
"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(1486u32),
::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()");
1487
1488 let predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
1489
1490 let trait_ref = predicate.skip_binder().trait_ref;
1494
1495 coherence::trait_ref_is_knowable(self.infcx, trait_ref, |ty| Ok::<_, !>(ty)).into_ok()
1496 }
1497
1498 fn can_use_global_caches(
1500 &self,
1501 param_env: ty::ParamEnv<'tcx>,
1502 pred: ty::PolyTraitClause<'tcx>,
1503 ) -> bool {
1504 if param_env.has_infer() || pred.has_infer() {
1508 return false;
1509 }
1510
1511 match self.typing_mode() {
1512 TypingMode::Coherence => false,
1519 TypingMode::Typeck { defining_opaque_types_and_generators: defining_opaque_types }
1528 | TypingMode::PostTypeckUntilBorrowck { defining_opaque_types } => {
1529 defining_opaque_types.is_empty()
1530 || (!pred.has_opaque_types() && !pred.has_coroutines())
1531 }
1532 TypingMode::Reflection => false,
1535 TypingMode::PostBorrowck { .. } => true,
1538 TypingMode::PostAnalysis | TypingMode::Codegen => true,
1544 }
1545 }
1546
1547 fn check_candidate_cache(
1548 &mut self,
1549 param_env: ty::ParamEnv<'tcx>,
1550 cache_fresh_trait_pred: ty::PolyTraitClause<'tcx>,
1551 ) -> Option<SelectionResult<'tcx, SelectionCandidate<'tcx>>> {
1552 let infcx = self.infcx;
1553 let tcx = infcx.tcx;
1554 let pred = cache_fresh_trait_pred.skip_binder();
1555
1556 if self.can_use_global_caches(param_env, cache_fresh_trait_pred) {
1557 if let Some(res) =
1558 tcx.caches.selection_cache.get(&(infcx.typing_env(param_env), pred), tcx)
1559 {
1560 return Some(res);
1561 } else if truecfg!(debug_assertions) {
1562 match infcx.selection_cache.get(&(param_env, pred), tcx) {
1563 None | Some(Err(SelectionError::Overflow(OverflowError::Canonical))) => {}
1564 res => ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected local cache result: {0:?}",
res))bug!("unexpected local cache result: {res:?}"),
1565 }
1566 }
1567 }
1568
1569 infcx.selection_cache.get(&(param_env, pred), tcx)
1573 }
1574
1575 fn can_cache_candidate(
1592 &self,
1593 result: &SelectionResult<'tcx, SelectionCandidate<'tcx>>,
1594 ) -> bool {
1595 match result {
1596 Ok(Some(SelectionCandidate::ParamCandidate(trait_ref))) => !trait_ref.has_infer(),
1597 _ => true,
1598 }
1599 }
1600
1601 #[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(1601u32),
::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:1614",
"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(1614u32),
::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:1622",
"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(1622u32),
::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.caches.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:1635",
"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(1635u32),
::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")]
1602 fn insert_candidate_cache(
1603 &mut self,
1604 param_env: ty::ParamEnv<'tcx>,
1605 cache_fresh_trait_pred: ty::PolyTraitClause<'tcx>,
1606 dep_node: DepNodeIndex,
1607 candidate: SelectionResult<'tcx, SelectionCandidate<'tcx>>,
1608 ) {
1609 let infcx = self.infcx;
1610 let tcx = infcx.tcx;
1611 let pred = cache_fresh_trait_pred.skip_binder();
1612
1613 if !self.can_cache_candidate(&candidate) {
1614 debug!(?pred, ?candidate, "insert_candidate_cache - candidate is not cacheable");
1615 return;
1616 }
1617
1618 if self.can_use_global_caches(param_env, cache_fresh_trait_pred) {
1619 if let Err(SelectionError::Overflow(OverflowError::Canonical)) = candidate {
1620 } else {
1622 debug!(?pred, ?candidate, "insert_candidate_cache global");
1623 debug_assert!(!candidate.has_infer());
1624
1625 tcx.caches.selection_cache.insert(
1627 (infcx.typing_env(param_env), pred),
1628 dep_node,
1629 candidate,
1630 );
1631 return;
1632 }
1633 }
1634
1635 debug!(?pred, ?candidate, "insert_candidate_cache local");
1636 self.infcx.selection_cache.insert((param_env, pred), dep_node, candidate);
1637 }
1638
1639 pub(super) fn for_each_item_bound<T>(
1645 &mut self,
1646 mut self_ty: Ty<'tcx>,
1647 mut for_each: impl FnMut(
1648 &mut Self,
1649 ty::Clause<'tcx>,
1650 usize,
1651 AliasBoundKind,
1652 ) -> ControlFlow<T, ()>,
1653 on_ambiguity: impl FnOnce(),
1654 ) -> ControlFlow<T, ()> {
1655 let mut idx = 0;
1656 let mut alias_bound_kind = AliasBoundKind::SelfBounds;
1657
1658 loop {
1659 let (alias_ty, def_id) = match *self_ty.kind() {
1660 ty::Alias(
1661 _,
1662 alias_ty @ ty::AliasTy {
1663 kind: ty::Projection { def_id } | ty::Opaque { def_id },
1664 ..
1665 },
1666 ) => (alias_ty, def_id),
1667 ty::Infer(ty::TyVar(_)) => {
1668 on_ambiguity();
1669 return ControlFlow::Continue(());
1670 }
1671 _ => return ControlFlow::Continue(()),
1672 };
1673
1674 let relevant_bounds = if alias_bound_kind == AliasBoundKind::NonSelfBounds {
1679 self.tcx().item_non_self_bounds(def_id)
1680 } else {
1681 self.tcx().item_self_bounds(def_id)
1682 };
1683
1684 for bound in relevant_bounds.instantiate(self.tcx(), alias_ty.args).skip_norm_wip() {
1685 for_each(self, bound, idx, alias_bound_kind)?;
1686 idx += 1;
1687 }
1688
1689 if #[allow(non_exhaustive_omitted_patterns)] match alias_ty.kind {
ty::Projection { .. } => true,
_ => false,
}matches!(alias_ty.kind, ty::Projection { .. }) {
1690 self_ty = alias_ty.self_ty();
1691 } else {
1692 return ControlFlow::Continue(());
1693 }
1694
1695 alias_bound_kind = AliasBoundKind::NonSelfBounds;
1696 }
1697 }
1698
1699 fn match_normalize_trait_ref(
1703 &mut self,
1704 obligation: &PolyTraitObligation<'tcx>,
1705 placeholder_trait_ref: ty::TraitRef<'tcx>,
1706 trait_bound: ty::PolyTraitRef<'tcx>,
1707 ) -> Result<Option<ty::TraitRef<'tcx>>, ()> {
1708 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());
1709 if placeholder_trait_ref.def_id != trait_bound.def_id() {
1710 return Err(());
1712 }
1713
1714 let drcx = DeepRejectCtxt::relate_rigid_rigid(self.infcx.tcx);
1715 let obligation_args = obligation.predicate.skip_binder().trait_ref.args;
1716 if !drcx.args_may_unify(obligation_args, trait_bound.skip_binder().args) {
1717 return Err(());
1718 }
1719
1720 let trait_bound = self.infcx.instantiate_binder_with_fresh_vars(
1721 obligation.cause.span,
1722 HigherRankedType,
1723 trait_bound,
1724 );
1725 let Normalized { value: trait_bound, obligations: _ } = normalize_with_depth(
1726 self,
1727 obligation.param_env,
1728 obligation.cause.clone(),
1729 obligation.recursion_depth + 1,
1730 ty::Unnormalized::new_wip(trait_bound),
1731 );
1732 self.infcx
1733 .at(&obligation.cause, obligation.param_env)
1734 .eq(DefineOpaqueTypes::No, placeholder_trait_ref, trait_bound)
1735 .map(|InferOk { obligations: _, value: () }| {
1736 if !trait_bound.has_infer() && !trait_bound.has_placeholders() {
1739 Some(trait_bound)
1740 } else {
1741 None
1742 }
1743 })
1744 .map_err(|_| ())
1745 }
1746
1747 fn where_clause_may_apply<'o>(
1748 &mut self,
1749 stack: &TraitObligationStack<'o, 'tcx>,
1750 where_clause_trait_ref: ty::PolyTraitRef<'tcx>,
1751 ) -> Result<EvaluationResult, OverflowError> {
1752 self.evaluation_probe(|this| {
1753 match this.match_where_clause_trait_ref(stack.obligation, where_clause_trait_ref) {
1754 Ok(obligations) => this.evaluate_predicates_recursively(stack.list(), obligations),
1755 Err(()) => Ok(EvaluatedToErr),
1756 }
1757 })
1758 }
1759
1760 pub(super) fn match_projection_projections(
1767 &mut self,
1768 obligation: &ProjectionTermObligation<'tcx>,
1769 env_predicate: PolyProjectionClause<'tcx>,
1770 potentially_unnormalized_candidates: bool,
1771 ) -> ProjectionMatchesProjection {
1772 let def_id = obligation.predicate.expect_projection_def_id();
1773 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());
1774
1775 let mut nested_obligations = PredicateObligations::new();
1776 let infer_predicate = self.infcx.instantiate_binder_with_fresh_vars(
1777 obligation.cause.span,
1778 BoundRegionConversionTime::HigherRankedType,
1779 env_predicate,
1780 );
1781 let mut infer_projection = infer_predicate.projection_term;
1782 if potentially_unnormalized_candidates {
1783 infer_projection = normalize_with_depth_to(
1784 self,
1785 obligation.param_env,
1786 obligation.cause.clone(),
1787 obligation.recursion_depth + 1,
1788 ty::Unnormalized::new_wip(infer_projection),
1789 &mut nested_obligations,
1790 )
1791 }
1792
1793 let is_match = self
1794 .infcx
1795 .at(&obligation.cause, obligation.param_env)
1796 .eq(DefineOpaqueTypes::No, obligation.predicate, infer_projection)
1797 .is_ok_and(|InferOk { obligations, value: () }| {
1798 self.evaluate_predicates_recursively(
1799 TraitObligationStackList::empty(&ProvisionalEvaluationCache::default()),
1800 nested_obligations.into_iter().chain(obligations),
1801 )
1802 .is_ok_and(|res| res.may_apply())
1803 });
1804
1805 if is_match {
1806 let generics = self.tcx().generics_of(def_id);
1807 if !generics.is_own_empty()
1816 && obligation.predicate.args[generics.parent_count..].iter().any(|&p| {
1817 p.has_non_region_infer()
1818 && match p.kind() {
1819 ty::GenericArgKind::Const(ct) => {
1820 self.infcx.shallow_resolve_const(ct) != ct
1821 }
1822 ty::GenericArgKind::Type(ty) => self.infcx.shallow_resolve(ty) != ty,
1823 ty::GenericArgKind::Lifetime(_) => false,
1824 }
1825 })
1826 {
1827 ProjectionMatchesProjection::Ambiguous
1828 } else {
1829 ProjectionMatchesProjection::Yes
1830 }
1831 } else {
1832 ProjectionMatchesProjection::No
1833 }
1834 }
1835}
1836
1837impl<'tcx> SelectionContext<'_, 'tcx> {
1844 x;#[instrument(level = "debug", skip(self), ret)]
1849 fn winnow_candidates(
1850 &mut self,
1851 has_non_region_infer: bool,
1852 candidate_preference_mode: CandidatePreferenceMode,
1853 mut candidates: Vec<EvaluatedCandidate<'tcx>>,
1854 ) -> Option<SelectionCandidate<'tcx>> {
1855 if candidates.len() == 1 {
1856 return Some(candidates.pop().unwrap().candidate);
1857 }
1858
1859 let mut sized_candidates =
1861 candidates.iter().filter(|c| matches!(c.candidate, SizedCandidate));
1862 if let Some(sized_candidate) = sized_candidates.next() {
1863 debug_assert_eq!(sized_candidates.next(), None);
1866 if sized_candidate.evaluation.must_apply_modulo_regions() {
1870 return Some(sized_candidate.candidate.clone());
1871 } else {
1872 return None;
1873 }
1874 }
1875
1876 'search_victim: loop {
1880 for (i, this) in candidates.iter().enumerate() {
1881 let ParamCandidate(this) = this.candidate else { continue };
1882 for (j, other) in candidates.iter().enumerate() {
1883 if i == j {
1884 continue;
1885 }
1886
1887 let ParamCandidate(other) = other.candidate else { continue };
1888 if this == other {
1889 candidates.remove(j);
1890 continue 'search_victim;
1891 }
1892
1893 if this.skip_binder().trait_ref == other.skip_binder().trait_ref
1894 && this.skip_binder().polarity == other.skip_binder().polarity
1895 && !this.skip_binder().trait_ref.has_escaping_bound_vars()
1896 {
1897 candidates.remove(j);
1898 continue 'search_victim;
1899 }
1900 }
1901 }
1902
1903 break;
1904 }
1905
1906 let mut alias_bounds = candidates.iter().filter_map(|c| {
1907 if let ProjectionCandidate { idx, kind } = c.candidate {
1908 Some((idx, kind))
1909 } else {
1910 None
1911 }
1912 });
1913 if matches!(candidate_preference_mode, CandidatePreferenceMode::Marker) {
1916 match alias_bounds
1917 .clone()
1918 .filter_map(|(idx, kind)| (kind == AliasBoundKind::SelfBounds).then_some(idx))
1919 .try_reduce(|c1, c2| if has_non_region_infer { None } else { Some(c1.min(c2)) })
1920 {
1921 Some(Some(idx)) => {
1922 return Some(ProjectionCandidate { idx, kind: AliasBoundKind::SelfBounds });
1923 }
1924 Some(None) => {}
1925 None => return None,
1926 }
1927 }
1928
1929 let is_global = |c: ty::PolyTraitClause<'tcx>| c.is_global() && !c.has_bound_vars();
1936 let param_candidates = candidates
1937 .iter()
1938 .filter_map(|c| if let ParamCandidate(p) = c.candidate { Some(p) } else { None });
1939 let mut has_global_bounds = false;
1940 let mut param_candidate = None;
1941 for c in param_candidates {
1942 if is_global(c) {
1943 has_global_bounds = true;
1944 } else if param_candidate.replace(c).is_some() {
1945 return None;
1947 }
1948 }
1949 if let Some(predicate) = param_candidate {
1950 if has_global_bounds {
1952 return None;
1953 } else {
1954 return Some(ParamCandidate(predicate));
1955 }
1956 }
1957
1958 match alias_bounds.try_reduce(|(c1, k1), (c2, k2)| {
1963 if has_non_region_infer {
1964 None
1965 } else if c1 < c2 {
1966 Some((c1, k1))
1967 } else {
1968 Some((c2, k2))
1969 }
1970 }) {
1971 Some(Some((idx, kind))) => return Some(ProjectionCandidate { idx, kind }),
1972 Some(None) => {}
1973 None => return None,
1974 }
1975
1976 let object_bound = candidates
1985 .iter()
1986 .filter_map(|c| if let ObjectCandidate(i) = c.candidate { Some(i) } else { None })
1987 .try_reduce(|c1, c2| if has_non_region_infer { None } else { Some(c1.min(c2)) });
1988 match object_bound {
1989 Some(Some(index)) => {
1990 return if has_non_region_infer
1991 && candidates.iter().any(|c| matches!(c.candidate, ImplCandidate(_)))
1992 {
1993 None
1994 } else {
1995 Some(ObjectCandidate(index))
1996 };
1997 }
1998 Some(None) => {}
1999 None => return None,
2000 }
2001 let upcast_bound = candidates
2003 .iter()
2004 .filter_map(|c| {
2005 if let TraitUpcastingUnsizeCandidate(i) = c.candidate { Some(i) } else { None }
2006 })
2007 .try_reduce(|c1, c2| if has_non_region_infer { None } else { Some(c1.min(c2)) });
2008 match upcast_bound {
2009 Some(Some(index)) => return Some(TraitUpcastingUnsizeCandidate(index)),
2010 Some(None) => {}
2011 None => return None,
2012 }
2013
2014 let impls = candidates.iter().filter_map(|c| {
2016 if let ImplCandidate(def_id) = c.candidate {
2017 Some((def_id, c.evaluation))
2018 } else {
2019 None
2020 }
2021 });
2022 let mut impl_candidate = None;
2023 for c in impls {
2024 if let Some(prev) = impl_candidate.replace(c) {
2025 if self.prefer_lhs_over_victim(has_non_region_infer, c, prev.0) {
2026 } else if self.prefer_lhs_over_victim(has_non_region_infer, prev, c.0) {
2028 impl_candidate = Some(prev);
2030 } else {
2031 return None;
2033 }
2034 }
2035 }
2036 if let Some((def_id, _evaluation)) = impl_candidate {
2037 if candidates.iter().all(|c| match c.candidate {
2040 SizedCandidate
2041 | BuiltinCandidate
2042 | TransmutabilityCandidate
2043 | AutoImplCandidate
2044 | ClosureCandidate { .. }
2045 | AsyncClosureCandidate
2046 | AsyncFnKindHelperCandidate
2047 | CoroutineCandidate
2048 | FutureCandidate
2049 | IteratorCandidate
2050 | AsyncIteratorCandidate
2051 | FnPointerCandidate
2052 | TraitAliasCandidate
2053 | TraitUpcastingUnsizeCandidate(_)
2054 | BuiltinObjectCandidate
2055 | BuiltinUnsizeCandidate
2056 | TryAsDynCandidate
2057 | BikeshedGuaranteedNoDropCandidate => false,
2058 ParamCandidate(_) | ImplCandidate(_) => true,
2061 ProjectionCandidate { .. } | ObjectCandidate(_) => unreachable!(),
2062 }) {
2063 return Some(ImplCandidate(def_id));
2064 } else {
2065 return None;
2066 }
2067 }
2068
2069 if candidates.len() == 1 {
2070 Some(candidates.pop().unwrap().candidate)
2071 } else {
2072 let mut not_a_global_where_bound = candidates
2075 .into_iter()
2076 .filter(|c| !matches!(c.candidate, ParamCandidate(p) if is_global(p)));
2077 not_a_global_where_bound
2078 .next()
2079 .map(|c| c.candidate)
2080 .filter(|_| not_a_global_where_bound.next().is_none())
2081 }
2082 }
2083
2084 fn prefer_lhs_over_victim(
2085 &self,
2086 has_non_region_infer: bool,
2087 (lhs, lhs_evaluation): (DefId, EvaluationResult),
2088 victim: DefId,
2089 ) -> bool {
2090 let tcx = self.tcx();
2091 if lhs_evaluation.must_apply_modulo_regions() {
2098 if tcx.specializes((lhs, victim)) {
2099 return true;
2100 }
2101 }
2102
2103 match tcx.impls_are_allowed_to_overlap(lhs, victim) {
2104 Some(ty::ImplOverlapKind::Permitted { marker: false }) => {
2107 lhs_evaluation.must_apply_considering_regions()
2108 }
2109 Some(ty::ImplOverlapKind::Permitted { marker: true }) => {
2110 !has_non_region_infer && lhs_evaluation.must_apply_considering_regions()
2150 }
2151 None => false,
2152 }
2153 }
2154}
2155
2156impl<'tcx> SelectionContext<'_, 'tcx> {
2157 fn sizedness_conditions(
2158 &mut self,
2159 self_ty: Ty<'tcx>,
2160 sizedness: SizedTraitKind,
2161 ) -> ty::Binder<'tcx, Vec<Ty<'tcx>>> {
2162 match self_ty.kind() {
2163 ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
2164 | ty::Uint(_)
2165 | ty::Int(_)
2166 | ty::Bool
2167 | ty::Float(_)
2168 | ty::FnDef(..)
2169 | ty::FnPtr(..)
2170 | ty::RawPtr(..)
2171 | ty::Char
2172 | ty::Ref(..)
2173 | ty::Coroutine(..)
2174 | ty::CoroutineWitness(..)
2175 | ty::Array(..)
2176 | ty::Closure(..)
2177 | ty::CoroutineClosure(..)
2178 | ty::Never
2179 | ty::Error(_) => ty::Binder::dummy(::alloc::vec::Vec::new()vec![]),
2180
2181 ty::Str | ty::Slice(_) | ty::Dynamic(..) => match sizedness {
2182 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"),
2183 SizedTraitKind::MetaSized => ty::Binder::dummy(::alloc::vec::Vec::new()vec![]),
2184 },
2185
2186 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"),
2187
2188 ty::Tuple(tys) => {
2189 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]))
2190 }
2191
2192 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]),
2193
2194 ty::Adt(def, args) => {
2195 if let Some(crit) = def.sizedness_constraint(self.tcx(), sizedness) {
2196 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()])
2197 } else {
2198 ty::Binder::dummy(::alloc::vec::Vec::new()vec![])
2199 }
2200 }
2201
2202 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]),
2203
2204 ty::Alias(..)
2205 | ty::Param(_)
2206 | ty::Placeholder(..)
2207 | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_))
2208 | ty::Bound(..) => {
2209 ::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);
2210 }
2211 }
2212 }
2213
2214 fn copy_clone_conditions(&mut self, self_ty: Ty<'tcx>) -> ty::Binder<'tcx, Vec<Ty<'tcx>>> {
2215 match *self_ty.kind() {
2216 ty::FnDef(..) | ty::FnPtr(..) | ty::Error(_) => ty::Binder::dummy(::alloc::vec::Vec::new()vec![]),
2217
2218 ty::Uint(_)
2219 | ty::Int(_)
2220 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
2221 | ty::Bool
2222 | ty::Float(_)
2223 | ty::Char
2224 | ty::RawPtr(..)
2225 | ty::Never
2226 | ty::Ref(_, _, hir::Mutability::Not)
2227 | ty::Array(..) => {
2228 {
::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")
2229 }
2230
2231 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"),
2234
2235 ty::Tuple(tys) => {
2236 ty::Binder::dummy(tys.iter().collect())
2238 }
2239
2240 ty::Pat(ty, _) => {
2241 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])
2243 }
2244
2245 ty::Coroutine(def_id, args) => match self.tcx().coroutine_movability(def_id) {
2246 hir::Movability::Static => {
2247 {
::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")
2248 }
2249 hir::Movability::Movable => {
2250 if self.tcx().features().coroutine_clone() {
2251 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![
2252 args.as_coroutine().tupled_upvars_ty(),
2253 Ty::new_coroutine_witness_for_coroutine(self.tcx(), def_id, args),
2254 ])
2255 } else {
2256 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("tried to assemble `Clone` for coroutine without enabled feature")));
}unreachable!(
2257 "tried to assemble `Clone` for coroutine without enabled feature"
2258 )
2259 }
2260 }
2261 },
2262
2263 ty::CoroutineWitness(def_id, args) => self
2264 .infcx
2265 .tcx
2266 .coroutine_hidden_types(def_id)
2267 .instantiate(self.infcx.tcx, args)
2268 .skip_norm_wip()
2269 .map_bound(|witness| witness.types.to_vec()),
2270
2271 ty::Closure(_, args) => ty::Binder::dummy(args.as_closure().upvar_tys().to_vec()),
2272
2273 ty::CoroutineClosure(_, args) => {
2274 ty::Binder::dummy(args.as_coroutine_closure().upvar_tys().to_vec())
2275 }
2276
2277 ty::Foreign(..)
2278 | ty::Str
2279 | ty::Slice(_)
2280 | ty::Dynamic(..)
2281 | ty::Adt(..)
2282 | ty::Alias(..)
2283 | ty::Param(..)
2284 | ty::Placeholder(..)
2285 | ty::Bound(..)
2286 | ty::Ref(_, _, ty::Mutability::Mut)
2287 | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
2288 ::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);
2289 }
2290 }
2291 }
2292
2293 fn coroutine_is_gen(&mut self, self_ty: Ty<'tcx>) -> bool {
2294 #[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, ..)
2295 if self.tcx().coroutine_is_gen(did))
2296 }
2297
2298 x;#[instrument(level = "debug", skip(self), ret)]
2310 fn constituent_types_for_auto_trait(
2311 &self,
2312 t: Ty<'tcx>,
2313 ) -> Result<ty::Binder<'tcx, AutoImplConstituents<'tcx>>, SelectionError<'tcx>> {
2314 Ok(match *t.kind() {
2315 ty::Uint(_)
2316 | ty::Int(_)
2317 | ty::Bool
2318 | ty::Float(_)
2319 | ty::FnDef(..)
2320 | ty::FnPtr(..)
2321 | ty::Error(_)
2322 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
2323 | ty::Never
2324 | ty::Char => {
2325 ty::Binder::dummy(AutoImplConstituents { types: vec![], assumptions: vec![] })
2326 }
2327
2328 ty::Foreign(..) => {
2332 ty::Binder::dummy(AutoImplConstituents { types: vec![], assumptions: vec![] })
2333 }
2334
2335 ty::UnsafeBinder(ty) => {
2336 ty.map_bound(|ty| AutoImplConstituents { types: vec![ty], assumptions: vec![] })
2337 }
2338
2339 ty::Str => ty::Binder::dummy(AutoImplConstituents {
2341 types: vec![Ty::new_slice(self.tcx(), self.tcx().types.u8)],
2342 assumptions: vec![],
2343 }),
2344
2345 ty::Placeholder(..)
2346 | ty::Dynamic(..)
2347 | ty::Param(..)
2348 | ty::Alias(
2349 _,
2350 ty::AliasTy {
2351 kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. },
2352 ..
2353 },
2354 )
2355 | ty::Bound(..)
2356 | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
2357 bug!("asked to assemble constituent types of unexpected type: {:?}", t);
2358 }
2359
2360 ty::RawPtr(element_ty, _) | ty::Ref(_, element_ty, _) => {
2361 ty::Binder::dummy(AutoImplConstituents {
2362 types: vec![element_ty],
2363 assumptions: vec![],
2364 })
2365 }
2366
2367 ty::Pat(ty, _) | ty::Array(ty, _) | ty::Slice(ty) => {
2368 ty::Binder::dummy(AutoImplConstituents { types: vec![ty], assumptions: vec![] })
2369 }
2370
2371 ty::Tuple(tys) => {
2372 ty::Binder::dummy(AutoImplConstituents {
2374 types: tys.iter().collect(),
2375 assumptions: vec![],
2376 })
2377 }
2378
2379 ty::Closure(_, args) => {
2380 let ty = self.infcx.shallow_resolve(args.as_closure().tupled_upvars_ty());
2381 ty::Binder::dummy(AutoImplConstituents { types: vec![ty], assumptions: vec![] })
2382 }
2383
2384 ty::CoroutineClosure(_, args) => {
2385 let ty = self.infcx.shallow_resolve(args.as_coroutine_closure().tupled_upvars_ty());
2386 ty::Binder::dummy(AutoImplConstituents { types: vec![ty], assumptions: vec![] })
2387 }
2388
2389 ty::Coroutine(def_id, args) => {
2390 let ty = self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty());
2391 let tcx = self.tcx();
2392 let witness = Ty::new_coroutine_witness_for_coroutine(tcx, def_id, args);
2393 ty::Binder::dummy(AutoImplConstituents {
2394 types: vec![ty, witness],
2395 assumptions: vec![],
2396 })
2397 }
2398
2399 ty::CoroutineWitness(def_id, args) => self
2400 .infcx
2401 .tcx
2402 .coroutine_hidden_types(def_id)
2403 .instantiate(self.infcx.tcx, args)
2404 .skip_norm_wip()
2405 .map_bound(|witness| AutoImplConstituents {
2406 types: witness.types.to_vec(),
2407 assumptions: witness.assumptions.to_vec(),
2408 }),
2409
2410 ty::Adt(def, args) if def.is_phantom_data() => {
2412 ty::Binder::dummy(AutoImplConstituents {
2413 types: args.types().collect(),
2414 assumptions: vec![],
2415 })
2416 }
2417
2418 ty::Adt(def, args) => ty::Binder::dummy(AutoImplConstituents {
2419 types: def.all_fields().map(|f| f.ty(self.tcx(), args).skip_norm_wip()).collect(),
2420 assumptions: vec![],
2421 }),
2422
2423 ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => {
2424 if self.infcx.can_define_opaque_ty(def_id) {
2425 unreachable!()
2426 } else {
2427 let ty = self.tcx().type_of_opaque(def_id);
2431 ty::Binder::dummy(AutoImplConstituents {
2432 types: vec![ty.instantiate(self.tcx(), args).skip_norm_wip()],
2433 assumptions: vec![],
2434 })
2435 }
2436 }
2437 })
2438 }
2439
2440 fn collect_predicates_for_types(
2441 &mut self,
2442 param_env: ty::ParamEnv<'tcx>,
2443 cause: ObligationCause<'tcx>,
2444 recursion_depth: usize,
2445 trait_def_id: DefId,
2446 types: Vec<Ty<'tcx>>,
2447 ) -> PredicateObligations<'tcx> {
2448 types
2463 .into_iter()
2464 .flat_map(|placeholder_ty| {
2465 let Normalized { value: normalized_ty, mut obligations } = normalize_with_depth(
2466 self,
2467 param_env,
2468 cause.clone(),
2469 recursion_depth,
2470 Unnormalized::new_wip(placeholder_ty),
2471 );
2472
2473 let tcx = self.tcx();
2474 let trait_ref = if tcx.generics_of(trait_def_id).own_params.len() == 1 {
2475 ty::TraitRef::new(tcx, trait_def_id, [normalized_ty])
2476 } else {
2477 let err_args = ty::GenericArgs::extend_with_error(
2480 tcx,
2481 trait_def_id,
2482 &[normalized_ty.into()],
2483 );
2484 ty::TraitRef::new_from_args(tcx, trait_def_id, err_args)
2485 };
2486
2487 let obligation = Obligation::new(self.tcx(), cause.clone(), param_env, trait_ref);
2488 obligations.push(obligation);
2489 obligations
2490 })
2491 .collect()
2492 }
2493
2494 fn rematch_impl(
2505 &mut self,
2506 impl_def_id: DefId,
2507 obligation: &PolyTraitObligation<'tcx>,
2508 ) -> Normalized<'tcx, GenericArgsRef<'tcx>> {
2509 let impl_trait_header = self.tcx().impl_trait_header(impl_def_id);
2510 match self.match_impl(impl_def_id, impl_trait_header, obligation) {
2511 Ok(args) => args,
2512 Err(()) => {
2513 let predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
2514 ::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")
2515 }
2516 }
2517 }
2518
2519 x;#[instrument(level = "debug", skip(self), ret)]
2520 fn match_impl(
2521 &mut self,
2522 impl_def_id: DefId,
2523 impl_trait_header: ty::ImplTraitHeader<'tcx>,
2524 obligation: &PolyTraitObligation<'tcx>,
2525 ) -> Result<Normalized<'tcx, GenericArgsRef<'tcx>>, ()> {
2526 let placeholder_obligation =
2527 self.infcx.enter_forall_and_leak_universe(obligation.predicate);
2528 let placeholder_obligation_trait_ref = placeholder_obligation.trait_ref;
2529
2530 let impl_args = self.infcx.fresh_args_for_item(obligation.cause.span, impl_def_id);
2531
2532 let trait_ref = impl_trait_header.trait_ref.instantiate(self.tcx(), impl_args);
2533 debug!(?impl_trait_header);
2534
2535 let mut nested_obligations = PredicateObligations::new();
2536 let impl_trait_ref = normalize_with_depth_to(
2537 self,
2538 obligation.param_env,
2539 obligation.cause.clone(),
2540 obligation.recursion_depth + 1,
2541 trait_ref,
2542 &mut nested_obligations,
2543 );
2544
2545 debug!(?impl_trait_ref, ?placeholder_obligation_trait_ref);
2546
2547 let cause = ObligationCause::new(
2548 obligation.cause.span,
2549 obligation.cause.body_def_id,
2550 ObligationCauseCode::MatchImpl(obligation.cause.clone(), impl_def_id),
2551 );
2552
2553 let InferOk { obligations, .. } = self
2554 .infcx
2555 .at(&cause, obligation.param_env)
2556 .eq(DefineOpaqueTypes::No, placeholder_obligation_trait_ref, impl_trait_ref)
2557 .map_err(|e| {
2558 debug!("match_impl: failed eq_trait_refs due to `{}`", e.to_string(self.tcx()))
2559 })?;
2560 nested_obligations.extend(obligations);
2561
2562 match self.typing_mode() {
2563 TypingMode::Coherence => {}
2564 TypingMode::Reflection
2565 if !self.tcx().impl_is_fully_generic_for_reflection(impl_def_id) =>
2566 {
2567 debug!("reflection mode only allows fully generic impls");
2568 return Err(());
2569 }
2570
2571 TypingMode::Typeck { .. }
2572 | TypingMode::PostTypeckUntilBorrowck { .. }
2573 | TypingMode::PostBorrowck { .. }
2574 | TypingMode::Codegen
2575 | TypingMode::ErasedNotCoherence(_)
2576 | TypingMode::Reflection
2577 | TypingMode::PostAnalysis => {
2578 if impl_trait_header.polarity == ty::ImplPolarity::Reservation {
2579 debug!("reservation impls only apply in intercrate mode");
2580 return Err(());
2581 }
2582 }
2583 }
2584
2585 Ok(Normalized { value: impl_args, obligations: nested_obligations })
2586 }
2587
2588 fn match_upcast_principal(
2589 &mut self,
2590 obligation: &PolyTraitObligation<'tcx>,
2591 unnormalized_upcast_principal: ty::Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>,
2592 a_data: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
2593 b_data: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
2594 a_region: ty::Region<'tcx>,
2595 b_region: ty::Region<'tcx>,
2596 ) -> SelectionResult<'tcx, PredicateObligations<'tcx>> {
2597 let tcx = self.tcx();
2598 let mut nested = PredicateObligations::new();
2599
2600 let a_auto_traits: FxIndexSet<DefId> = a_data
2604 .auto_traits()
2605 .chain(
2606 a_data
2607 .principal_def_id()
2608 .map(|principal_def_id| {
2609 elaborate::supertrait_def_ids(tcx, principal_def_id)
2610 .filter(|def_id| tcx.trait_is_auto(*def_id))
2611 })
2612 .into_flat_iter(),
2613 )
2614 .collect();
2615
2616 let upcast_principal = normalize_with_depth_to(
2617 self,
2618 obligation.param_env,
2619 obligation.cause.clone(),
2620 obligation.recursion_depth + 1,
2621 unnormalized_upcast_principal,
2622 &mut nested,
2623 );
2624
2625 for bound in b_data {
2626 match bound.skip_binder() {
2627 ty::ExistentialPredicate::Trait(target_principal) => {
2630 let hr_source_principal = upcast_principal.map_bound(|trait_ref| {
2631 ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)
2632 });
2633 let hr_target_principal = bound.rebind(target_principal);
2634
2635 nested.extend(
2636 self.infcx
2637 .enter_forall(hr_target_principal, |target_principal| {
2638 let source_principal =
2639 self.infcx.instantiate_binder_with_fresh_vars(
2640 obligation.cause.span,
2641 HigherRankedType,
2642 hr_source_principal,
2643 );
2644 self.infcx.at(&obligation.cause, obligation.param_env).eq_trace(
2645 DefineOpaqueTypes::Yes,
2646 ToTrace::to_trace(
2647 &obligation.cause,
2648 hr_target_principal,
2649 hr_source_principal,
2650 ),
2651 target_principal,
2652 source_principal,
2653 )
2654 })
2655 .map_err(|_| SelectionError::Unimplemented)?
2656 .into_obligations(),
2657 );
2658 }
2659 ty::ExistentialPredicate::Projection(target_projection) => {
2665 let hr_target_projection = bound.rebind(target_projection);
2666
2667 let mut matching_projections =
2668 a_data.projection_bounds().filter(|&hr_source_projection| {
2669 hr_source_projection.item_def_id() == hr_target_projection.item_def_id()
2672 && self.infcx.probe(|_| {
2673 self.infcx
2674 .enter_forall(hr_target_projection, |target_projection| {
2675 let source_projection =
2676 self.infcx.instantiate_binder_with_fresh_vars(
2677 obligation.cause.span,
2678 HigherRankedType,
2679 hr_source_projection,
2680 );
2681 self.infcx
2682 .at(&obligation.cause, obligation.param_env)
2683 .eq_trace(
2684 DefineOpaqueTypes::Yes,
2685 ToTrace::to_trace(
2686 &obligation.cause,
2687 hr_target_projection,
2688 hr_source_projection,
2689 ),
2690 target_projection,
2691 source_projection,
2692 )
2693 })
2694 .is_ok()
2695 })
2696 });
2697
2698 let Some(hr_source_projection) = matching_projections.next() else {
2699 return Err(SelectionError::Unimplemented);
2700 };
2701 if matching_projections.next().is_some() {
2702 return Ok(None);
2703 }
2704 nested.extend(
2705 self.infcx
2706 .enter_forall(hr_target_projection, |target_projection| {
2707 let source_projection =
2708 self.infcx.instantiate_binder_with_fresh_vars(
2709 obligation.cause.span,
2710 HigherRankedType,
2711 hr_source_projection,
2712 );
2713 self.infcx.at(&obligation.cause, obligation.param_env).eq_trace(
2714 DefineOpaqueTypes::Yes,
2715 ToTrace::to_trace(
2716 &obligation.cause,
2717 hr_target_projection,
2718 hr_source_projection,
2719 ),
2720 target_projection,
2721 source_projection,
2722 )
2723 })
2724 .map_err(|_| SelectionError::Unimplemented)?
2725 .into_obligations(),
2726 );
2727 }
2728 ty::ExistentialPredicate::AutoTrait(def_id) => {
2730 if !a_auto_traits.contains(&def_id) {
2731 return Err(SelectionError::Unimplemented);
2732 }
2733 }
2734 }
2735 }
2736
2737 nested.push(Obligation::with_depth(
2738 tcx,
2739 obligation.cause.clone(),
2740 obligation.recursion_depth + 1,
2741 obligation.param_env,
2742 ty::Binder::dummy(ty::OutlivesClause(a_region, b_region)),
2743 ));
2744
2745 Ok(Some(nested))
2746 }
2747
2748 fn match_where_clause_trait_ref(
2752 &mut self,
2753 obligation: &PolyTraitObligation<'tcx>,
2754 where_clause_trait_ref: ty::PolyTraitRef<'tcx>,
2755 ) -> Result<PredicateObligations<'tcx>, ()> {
2756 self.match_poly_trait_ref(obligation, where_clause_trait_ref)
2757 }
2758
2759 #[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(2761u32),
::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")]
2762 fn match_poly_trait_ref(
2763 &mut self,
2764 obligation: &PolyTraitObligation<'tcx>,
2765 poly_trait_ref: ty::PolyTraitRef<'tcx>,
2766 ) -> Result<PredicateObligations<'tcx>, ()> {
2767 let predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
2768 let trait_ref = self.infcx.instantiate_binder_with_fresh_vars(
2769 obligation.cause.span,
2770 HigherRankedType,
2771 poly_trait_ref,
2772 );
2773 self.infcx
2774 .at(&obligation.cause, obligation.param_env)
2775 .eq(DefineOpaqueTypes::No, predicate.trait_ref, trait_ref)
2776 .map(|InferOk { obligations, .. }| obligations)
2777 .map_err(|_| ())
2778 }
2779
2780 fn match_fresh_trait_preds(
2784 &self,
2785 previous: ty::PolyTraitClause<'tcx>,
2786 current: ty::PolyTraitClause<'tcx>,
2787 ) -> bool {
2788 let mut matcher = _match::MatchAgainstFreshVars::new(self.tcx());
2789 matcher.relate(previous, current).is_ok()
2790 }
2791
2792 fn push_stack<'o>(
2793 &mut self,
2794 previous_stack: TraitObligationStackList<'o, 'tcx>,
2795 obligation: &'o PolyTraitObligation<'tcx>,
2796 ) -> TraitObligationStack<'o, 'tcx> {
2797 let fresh_trait_pred = obligation.predicate.fold_with(&mut self.freshener);
2798
2799 let dfn = previous_stack.cache.next_dfn();
2800 let depth = previous_stack.depth() + 1;
2801 TraitObligationStack {
2802 obligation,
2803 fresh_trait_pred,
2804 reached_depth: Cell::new(depth),
2805 previous: previous_stack,
2806 dfn,
2807 depth,
2808 }
2809 }
2810
2811 #[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(2811u32),
::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")]
2812 fn closure_trait_ref_unnormalized(
2813 &mut self,
2814 self_ty: Ty<'tcx>,
2815 fn_trait_def_id: DefId,
2816 ) -> ty::PolyTraitRef<'tcx> {
2817 let ty::Closure(_, args) = *self_ty.kind() else {
2818 bug!("expected closure, found {self_ty}");
2819 };
2820 let closure_sig = args.as_closure().sig();
2821
2822 closure_trait_ref_and_return_type(
2823 self.tcx(),
2824 fn_trait_def_id,
2825 self_ty,
2826 closure_sig,
2827 util::TupleArgumentsFlag::No,
2828 )
2829 .map_bound(|(trait_ref, _)| trait_ref)
2830 }
2831
2832 #[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(2836u32),
::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 clauses = tcx.clauses_of(def_id);
{
match (&clauses.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 clauses = clauses.instantiate_own(tcx, args);
let mut obligations =
PredicateObligations::with_capacity(clauses.len());
for (index, (clause, span)) in clauses.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_clause_index: Some(index),
span,
}))
})
};
let clause =
normalize_with_depth_to(self, param_env, cause.clone(),
recursion_depth, clause, &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))]
2837 fn impl_or_trait_obligations(
2838 &mut self,
2839 cause: &ObligationCause<'tcx>,
2840 recursion_depth: usize,
2841 param_env: ty::ParamEnv<'tcx>,
2842 def_id: DefId, args: GenericArgsRef<'tcx>, parent_trait_pred: ty::Binder<'tcx, ty::TraitClause<'tcx>>,
2845 ) -> PredicateObligations<'tcx> {
2846 let tcx = self.tcx();
2847
2848 let clauses = tcx.clauses_of(def_id);
2863 assert_eq!(clauses.parent, None);
2864 let clauses = clauses.instantiate_own(tcx, args);
2865 let mut obligations = PredicateObligations::with_capacity(clauses.len());
2866 for (index, (clause, span)) in clauses.into_iter().enumerate() {
2867 let cause = if tcx.is_lang_item(parent_trait_pred.def_id(), LangItem::CoerceUnsized) {
2868 cause.clone()
2869 } else {
2870 cause.clone().derived_cause(parent_trait_pred, |derived| {
2871 ObligationCauseCode::ImplDerived(Box::new(ImplDerivedCause {
2872 derived,
2873 impl_or_alias_def_id: def_id,
2874 impl_def_clause_index: Some(index),
2875 span,
2876 }))
2877 })
2878 };
2879 let clause = normalize_with_depth_to(
2880 self,
2881 param_env,
2882 cause.clone(),
2883 recursion_depth,
2884 clause,
2885 &mut obligations,
2886 );
2887 obligations.push(Obligation {
2888 cause,
2889 recursion_depth,
2890 param_env,
2891 predicate: clause.as_predicate(),
2892 });
2893 }
2894
2895 if tcx.def_kind(def_id) == (DefKind::Impl { of_trait: true }) {
2897 for clause in tcx.impl_super_outlives(def_id).iter_instantiated(tcx, args) {
2898 let clause = normalize_with_depth_to(
2899 self,
2900 param_env,
2901 cause.clone(),
2902 recursion_depth,
2903 clause,
2904 &mut obligations,
2905 );
2906 obligations.push(Obligation {
2907 cause: cause.clone(),
2908 recursion_depth,
2909 param_env,
2910 predicate: clause.as_predicate(),
2911 });
2912 }
2913 }
2914
2915 obligations
2916 }
2917
2918 pub(super) fn should_stall_coroutine(&self, def_id: DefId) -> bool {
2919 match self.typing_mode() {
2920 TypingMode::Typeck { defining_opaque_types_and_generators: stalled_generators } => {
2921 def_id.as_local().is_some_and(|def_id| stalled_generators.contains(&def_id))
2922 }
2923 TypingMode::Coherence
2924 | TypingMode::PostAnalysis
2925 | TypingMode::Reflection
2926 | TypingMode::Codegen
2927 | TypingMode::PostTypeckUntilBorrowck { defining_opaque_types: _ }
2928 | TypingMode::PostBorrowck { defined_opaque_types: _ } => false,
2929 }
2930 }
2931}
2932
2933impl<'o, 'tcx> TraitObligationStack<'o, 'tcx> {
2934 fn list(&'o self) -> TraitObligationStackList<'o, 'tcx> {
2935 TraitObligationStackList::with(self)
2936 }
2937
2938 fn cache(&self) -> &'o ProvisionalEvaluationCache<'tcx> {
2939 self.previous.cache
2940 }
2941
2942 fn iter(&'o self) -> TraitObligationStackList<'o, 'tcx> {
2943 self.list()
2944 }
2945
2946 fn update_reached_depth(&self, reached_depth: usize) {
2949 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!(
2950 self.depth >= reached_depth,
2951 "invoked `update_reached_depth` with something under this stack: \
2952 self.depth={} reached_depth={}",
2953 self.depth,
2954 reached_depth,
2955 );
2956 {
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:2956",
"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(2956u32),
::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");
2957 let mut p = self;
2958 while reached_depth < p.depth {
2959 {
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:2959",
"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(2959u32),
::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");
2960 p.reached_depth.set(p.reached_depth.get().min(reached_depth));
2961 p = p.previous.head.unwrap();
2962 }
2963 }
2964}
2965
2966struct ProvisionalEvaluationCache<'tcx> {
3020 dfn: Cell<usize>,
3022
3023 map: RefCell<FxIndexMap<ty::PolyTraitClause<'tcx>, ProvisionalEvaluation>>,
3039
3040 wf_args: RefCell<Vec<(ty::Term<'tcx>, usize)>>,
3048}
3049
3050#[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)]
3053struct ProvisionalEvaluation {
3054 from_dfn: usize,
3055 reached_depth: usize,
3056 result: EvaluationResult,
3057}
3058
3059impl<'tcx> Default for ProvisionalEvaluationCache<'tcx> {
3060 fn default() -> Self {
3061 Self { dfn: Cell::new(0), map: Default::default(), wf_args: Default::default() }
3062 }
3063}
3064
3065impl<'tcx> ProvisionalEvaluationCache<'tcx> {
3066 fn next_dfn(&self) -> usize {
3068 let result = self.dfn.get();
3069 self.dfn.set(result + 1);
3070 result
3071 }
3072
3073 fn get_provisional(
3078 &self,
3079 fresh_trait_pred: ty::PolyTraitClause<'tcx>,
3080 ) -> Option<ProvisionalEvaluation> {
3081 {
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:3081",
"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(3081u32),
::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!(
3082 ?fresh_trait_pred,
3083 "get_provisional = {:#?}",
3084 self.map.borrow().get(&fresh_trait_pred),
3085 );
3086 Some(*self.map.borrow().get(&fresh_trait_pred)?)
3087 }
3088
3089 fn insert_provisional(
3094 &self,
3095 from_dfn: usize,
3096 reached_depth: usize,
3097 fresh_trait_pred: ty::PolyTraitClause<'tcx>,
3098 result: EvaluationResult,
3099 ) {
3100 {
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:3100",
"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(3100u32),
::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");
3101
3102 let mut map = self.map.borrow_mut();
3103
3104 for (_k, v) in &mut *map {
3119 if v.from_dfn >= from_dfn {
3120 v.reached_depth = reached_depth.min(v.reached_depth);
3121 }
3122 }
3123
3124 map.insert(fresh_trait_pred, ProvisionalEvaluation { from_dfn, reached_depth, result });
3125 }
3126
3127 fn on_failure(&self, dfn: usize) {
3136 {
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:3136",
"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(3136u32),
::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");
3137 self.map.borrow_mut().retain(|key, eval| {
3138 if !eval.from_dfn >= dfn {
3139 {
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:3139",
"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(3139u32),
::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);
3140 false
3141 } else {
3142 true
3143 }
3144 });
3145 }
3146
3147 fn on_completion(&self, dfn: usize) {
3185 {
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:3185",
"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(3185u32),
::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");
3186 self.map.borrow_mut().retain(|fresh_trait_pred, eval| {
3187 if eval.from_dfn >= dfn {
3188 {
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:3188",
"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(3188u32),
::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");
3189 return false;
3190 }
3191 true
3192 });
3193 }
3194}
3195
3196#[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)]
3197struct TraitObligationStackList<'o, 'tcx> {
3198 cache: &'o ProvisionalEvaluationCache<'tcx>,
3199 head: Option<&'o TraitObligationStack<'o, 'tcx>>,
3200}
3201
3202impl<'o, 'tcx> TraitObligationStackList<'o, 'tcx> {
3203 fn empty(cache: &'o ProvisionalEvaluationCache<'tcx>) -> TraitObligationStackList<'o, 'tcx> {
3204 TraitObligationStackList { cache, head: None }
3205 }
3206
3207 fn with(r: &'o TraitObligationStack<'o, 'tcx>) -> TraitObligationStackList<'o, 'tcx> {
3208 TraitObligationStackList { cache: r.cache(), head: Some(r) }
3209 }
3210
3211 fn head(&self) -> Option<&'o TraitObligationStack<'o, 'tcx>> {
3212 self.head
3213 }
3214
3215 fn depth(&self) -> usize {
3216 if let Some(head) = self.head { head.depth } else { 0 }
3217 }
3218}
3219
3220impl<'o, 'tcx> Iterator for TraitObligationStackList<'o, 'tcx> {
3221 type Item = &'o TraitObligationStack<'o, 'tcx>;
3222
3223 fn next(&mut self) -> Option<&'o TraitObligationStack<'o, 'tcx>> {
3224 let o = self.head?;
3225 *self = o.previous;
3226 Some(o)
3227 }
3228}
3229
3230impl<'o, 'tcx> fmt::Debug for TraitObligationStack<'o, 'tcx> {
3231 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3232 f.write_fmt(format_args!("TraitObligationStack({0:?})", self.obligation))write!(f, "TraitObligationStack({:?})", self.obligation)
3233 }
3234}
3235
3236pub(crate) enum ProjectionMatchesProjection {
3237 Yes,
3238 Ambiguous,
3239 No,
3240}
3241
3242#[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)]
3243pub(crate) struct AutoImplConstituents<'tcx> {
3244 pub types: Vec<Ty<'tcx>>,
3245 pub assumptions: Vec<ty::ArgOutlivesClause<'tcx>>,
3246}