1use std::marker::PhantomData;
2use std::ops::ControlFlow;
3
4use rustc_data_structures::obligation_forest::{
5 Error, ForestObligation, ObligationForest, ObligationProcessor, Outcome, ProcessResult,
6};
7use rustc_hir::def_id::LocalDefId;
8use rustc_infer::infer::DefineOpaqueTypes;
9use rustc_infer::traits::{
10 FromSolverError, PolyTraitObligation, PredicateObligations, ProjectionCacheKey, SelectionError,
11 TraitEngine, TraitErrors,
12};
13use rustc_middle::ty::abstract_const::NotConstEvaluatable;
14use rustc_middle::ty::error::{ExpectedFound, TypeError};
15use rustc_middle::ty::{
16 self, Binder, Const, DelayedSet, GenericArgsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
17 TypeVisitableExt, TypeVisitor, TypingMode, may_use_unstable_feature,
18};
19use rustc_next_trait_solver::solve::TyOrConstInferVar;
20use rustc_span::bug;
21use thin_vec::{ThinVec, thin_vec};
22use tracing::{debug, debug_span, instrument};
23
24use super::effects::{self, HostEffectObligation};
25use super::project::{self, ProjectAndUnifyResult};
26use super::select::SelectionContext;
27use super::{
28 EvaluationResult, FulfillmentError, FulfillmentErrorCode, PredicateObligation,
29 ScrubbedTraitError, const_evaluatable, wf,
30};
31use crate::error_reporting::InferCtxtErrorExt;
32use crate::infer::InferCtxt;
33use crate::traits::normalize::normalize_with_depth_to;
34use crate::traits::project::{PolyProjectionObligation, ProjectionCacheKeyExt as _};
35use crate::traits::query::evaluate_obligation::InferCtxtExt;
36use crate::traits::{EvaluateConstErr, sizedness_fast_path};
37
38pub(crate) type PendingPredicateObligations<'tcx> = ThinVec<PendingPredicateObligation<'tcx>>;
39
40impl<'tcx> ForestObligation for PendingPredicateObligation<'tcx> {
41 type CacheKey = ty::ParamEnvAnd<'tcx, ty::Predicate<'tcx>>;
45
46 fn as_cache_key(&self) -> Self::CacheKey {
47 self.obligation.param_env.and(self.obligation.predicate)
48 }
49}
50
51pub struct FulfillmentContext<'tcx, E: 'tcx> {
62 predicates: ObligationForest<PendingPredicateObligation<'tcx>>,
65
66 usable_in_snapshot: usize,
71
72 _errors: PhantomData<E>,
73}
74
75#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for PendingPredicateObligation<'tcx> {
#[inline]
fn clone(&self) -> PendingPredicateObligation<'tcx> {
PendingPredicateObligation {
obligation: ::core::clone::Clone::clone(&self.obligation),
stalled_on: ::core::clone::Clone::clone(&self.stalled_on),
}
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for PendingPredicateObligation<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"PendingPredicateObligation", "obligation", &self.obligation,
"stalled_on", &&self.stalled_on)
}
}Debug)]
76pub struct PendingPredicateObligation<'tcx> {
77 pub obligation: PredicateObligation<'tcx>,
78 pub stalled_on: Vec<TyOrConstInferVar>,
83}
84
85#[cfg(target_pointer_width = "64")]
87const _: [(); 72] =
[(); ::std::mem::size_of::<PendingPredicateObligation<'_>>()];rustc_data_structures::static_assert_size!(PendingPredicateObligation<'_>, 72);
88
89impl<'tcx, E> FulfillmentContext<'tcx, E>
90where
91 E: FromSolverError<'tcx, OldSolverError<'tcx>>,
92{
93 pub(super) fn new(infcx: &InferCtxt<'tcx>) -> FulfillmentContext<'tcx, E> {
95 if !!infcx.next_trait_solver() {
{
::core::panicking::panic_fmt(format_args!("old trait solver fulfillment context created when infcx is set up for new trait solver"));
}
};assert!(
96 !infcx.next_trait_solver(),
97 "old trait solver fulfillment context created when \
98 infcx is set up for new trait solver"
99 );
100 FulfillmentContext {
101 predicates: ObligationForest::new(),
102 usable_in_snapshot: infcx.num_open_snapshots(),
103 _errors: PhantomData,
104 }
105 }
106
107 fn select(&mut self, selcx: SelectionContext<'_, 'tcx>) -> TraitErrors<E> {
109 let span = {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("select",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(109u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligation_forest_size")
}> =
::tracing::__macro_support::FieldName::new("obligation_forest_size");
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.predicates.len())
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
}debug_span!("select", obligation_forest_size = ?self.predicates.len());
110 let _enter = span.enter();
111 let infcx = selcx.infcx;
112
113 let outcome: Outcome<_, _> =
115 self.predicates.process_obligations(&mut FulfillProcessor { selcx });
116
117 let errors = TraitErrors::from_iter(
121 outcome.errors.into_iter().map(|err| E::from_solver_error(infcx, OldSolverError(err))),
122 );
123
124 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs:124",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(124u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
::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!("select({0} predicates remaining, {1} errors) done",
self.predicates.len(), errors.len()) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
125 "select({} predicates remaining, {} errors) done",
126 self.predicates.len(),
127 errors.len()
128 );
129
130 errors
131 }
132}
133
134impl<'tcx, E> TraitEngine<'tcx, E> for FulfillmentContext<'tcx, E>
135where
136 E: FromSolverError<'tcx, OldSolverError<'tcx>>,
137{
138 #[inline]
139 fn register_predicate_obligation(
140 &mut self,
141 infcx: &InferCtxt<'tcx>,
142 mut obligation: PredicateObligation<'tcx>,
143 ) {
144 {
match (&self.usable_in_snapshot, &infcx.num_open_snapshots()) {
(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);
}
}
}
};assert_eq!(self.usable_in_snapshot, infcx.num_open_snapshots());
145 if true {
if !!obligation.param_env.has_non_region_infer() {
::core::panicking::panic("assertion failed: !obligation.param_env.has_non_region_infer()")
};
};debug_assert!(!obligation.param_env.has_non_region_infer());
148 obligation.predicate = infcx.deeply_resolve_ignoring_regions(obligation.predicate);
149
150 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs:150",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(150u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
::tracing_core::field::FieldSet::new(&["message",
{
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::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!("register_predicate_obligation")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?obligation, "register_predicate_obligation");
151
152 self.predicates
153 .register_obligation(PendingPredicateObligation { obligation, stalled_on: ::alloc::vec::Vec::new()vec![] });
154 }
155
156 fn collect_remaining_errors(&mut self, infcx: &InferCtxt<'tcx>) -> TraitErrors<E> {
157 TraitErrors::from_iter(
158 self.predicates
159 .to_errors(FulfillmentErrorCode::Ambiguity { overflow: None })
160 .into_iter()
161 .map(|err| E::from_solver_error(infcx, OldSolverError(err))),
162 )
163 }
164
165 fn try_evaluate_obligations(&mut self, infcx: &InferCtxt<'tcx>) -> TraitErrors<E> {
166 let selcx = SelectionContext::new(infcx);
167 self.select(selcx)
168 }
169
170 fn drain_stalled_obligations_for_coroutines(
171 &mut self,
172 infcx: &InferCtxt<'tcx>,
173 ) -> PredicateObligations<'tcx> {
174 let stalled_coroutines = match infcx.typing_mode_raw().assert_not_erased() {
175 TypingMode::Typeck { defining_opaque_types_and_generators } => {
176 defining_opaque_types_and_generators
177 }
178 TypingMode::Coherence
179 | TypingMode::PostTypeckUntilBorrowck { defining_opaque_types: _ }
180 | TypingMode::PostBorrowck { defined_opaque_types: _ }
181 | TypingMode::Reflection
182 | TypingMode::PostAnalysis
183 | TypingMode::Codegen => return Default::default(),
184 };
185
186 if stalled_coroutines.is_empty() {
187 return Default::default();
188 }
189
190 let mut processor = DrainProcessor {
191 infcx,
192 removed_predicates: PredicateObligations::new(),
193 stalled_coroutines,
194 };
195 let outcome: Outcome<_, _> = self.predicates.process_obligations(&mut processor);
196 if !outcome.errors.is_empty() {
::core::panicking::panic("assertion failed: outcome.errors.is_empty()")
};assert!(outcome.errors.is_empty());
197 return processor.removed_predicates;
198
199 struct DrainProcessor<'a, 'tcx> {
200 infcx: &'a InferCtxt<'tcx>,
201 removed_predicates: PredicateObligations<'tcx>,
202 stalled_coroutines: &'tcx ty::List<LocalDefId>,
203 }
204
205 impl<'tcx> ObligationProcessor for DrainProcessor<'_, 'tcx> {
206 type Obligation = PendingPredicateObligation<'tcx>;
207 type Error = !;
208 type OUT = Outcome<Self::Obligation, Self::Error>;
209
210 fn needs_process_obligation(&self, pending_obligation: &Self::Obligation) -> bool {
211 struct StalledOnCoroutines<'tcx> {
212 pub stalled_coroutines: &'tcx ty::List<LocalDefId>,
213 pub cache: DelayedSet<Ty<'tcx>>,
214 }
215
216 impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for StalledOnCoroutines<'tcx> {
217 type Result = ControlFlow<()>;
218
219 fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
220 if !self.cache.insert(ty) {
221 return ControlFlow::Continue(());
222 }
223
224 if let ty::Coroutine(def_id, _) = ty.kind()
225 && def_id
226 .as_local()
227 .is_some_and(|def_id| self.stalled_coroutines.contains(&def_id))
228 {
229 ControlFlow::Break(())
230 } else if ty.has_coroutines() {
231 ty.super_visit_with(self)
232 } else {
233 ControlFlow::Continue(())
234 }
235 }
236 }
237
238 self.infcx
239 .deeply_resolve_ignoring_regions(pending_obligation.obligation.predicate)
240 .visit_with(&mut StalledOnCoroutines {
241 stalled_coroutines: self.stalled_coroutines,
242 cache: Default::default(),
243 })
244 .is_break()
245 }
246
247 fn process_obligation(
248 &mut self,
249 pending_obligation: &mut PendingPredicateObligation<'tcx>,
250 ) -> ProcessResult<PendingPredicateObligation<'tcx>, !> {
251 if !self.needs_process_obligation(pending_obligation) {
::core::panicking::panic("assertion failed: self.needs_process_obligation(pending_obligation)")
};assert!(self.needs_process_obligation(pending_obligation));
252 self.removed_predicates.push(pending_obligation.obligation.clone());
253 ProcessResult::Changed(Default::default())
254 }
255
256 fn process_backedge<'c, I>(
257 &mut self,
258 cycle: I,
259 _marker: PhantomData<&'c PendingPredicateObligation<'tcx>>,
260 ) -> Result<(), !>
261 where
262 I: Clone + Iterator<Item = &'c PendingPredicateObligation<'tcx>>,
263 {
264 self.removed_predicates.extend(cycle.map(|c| c.obligation.clone()));
265 Ok(())
266 }
267 }
268 }
269
270 fn has_pending_obligations(&self) -> bool {
271 self.predicates.has_pending_obligations()
272 }
273
274 fn pending_obligations(&self) -> PredicateObligations<'tcx> {
275 self.predicates.map_pending_obligations(|o| o.obligation.clone())
276 }
277}
278
279struct FulfillProcessor<'a, 'tcx> {
280 selcx: SelectionContext<'a, 'tcx>,
281}
282
283fn mk_pending<'tcx>(
284 parent: &PredicateObligation<'tcx>,
285 os: PredicateObligations<'tcx>,
286) -> PendingPredicateObligations<'tcx> {
287 os.into_iter()
288 .map(|mut o| {
289 o.set_depth_from_parent(parent.recursion_depth);
290 PendingPredicateObligation { obligation: o, stalled_on: ::alloc::vec::Vec::new()vec![] }
291 })
292 .collect()
293}
294
295impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
296 type Obligation = PendingPredicateObligation<'tcx>;
297 type Error = FulfillmentErrorCode<'tcx>;
298 type OUT = Outcome<Self::Obligation, Self::Error>;
299
300 #[inline]
310 fn skippable_obligations<'b>(
311 &'b self,
312 it: impl Iterator<Item = &'b Self::Obligation>,
313 ) -> usize {
314 let is_unchanged = self.selcx.infcx.is_ty_infer_var_definitely_unchanged();
315
316 it.take_while(|o| match o.stalled_on.as_slice() {
317 [o] => is_unchanged(*o),
318 _ => false,
319 })
320 .count()
321 }
322
323 #[inline(always)]
329 fn needs_process_obligation(&self, pending_obligation: &Self::Obligation) -> bool {
330 if self.selcx.infcx.disable_trait_solver_fast_paths() {
331 return true;
332 }
333
334 let stalled_on = &pending_obligation.stalled_on;
338 match stalled_on.len() {
339 1 => self.selcx.infcx.ty_or_const_infer_var_changed(stalled_on[0]),
343
344 0 => true,
352
353 _ => (|| {
360 for &infer_var in stalled_on {
361 if self.selcx.infcx.ty_or_const_infer_var_changed(infer_var) {
362 return true;
363 }
364 }
365 false
366 })(),
367 }
368 }
369
370 #[inline(never)]
378 {}
#[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("process_obligation",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(378u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
::tracing_core::field::FieldSet::new(&[],
::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,
&{ meta.fields().value_set_all(&[]) })
} 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:
ProcessResult<PendingPredicateObligation<'tcx>,
FulfillmentErrorCode<'tcx>> = loop {};
return __tracing_attr_fake_return;
}
{
pending_obligation.stalled_on.clear();
let obligation = &mut pending_obligation.obligation;
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs:387",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(387u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
::tracing_core::field::FieldSet::new(&["message",
{
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::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!("pre-resolve")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
if obligation.predicate.has_non_region_infer() {
obligation.predicate =
self.selcx.infcx.deeply_resolve_ignoring_regions(obligation.predicate);
}
let obligation = &pending_obligation.obligation;
let infcx = self.selcx.infcx;
if !infcx.disable_trait_solver_fast_paths() &&
sizedness_fast_path(infcx.tcx, obligation.predicate,
obligation.param_env) {
return ProcessResult::Changed(::thin_vec::ThinVec::new());
}
if obligation.predicate.has_aliases() {
let mut obligations = PredicateObligations::new();
let predicate =
normalize_with_depth_to(&mut self.selcx,
obligation.param_env, obligation.cause.clone(),
obligation.recursion_depth + 1,
ty::Unnormalized::new_wip(obligation.predicate),
&mut obligations);
if predicate != obligation.predicate {
obligations.push(obligation.with(infcx.tcx, predicate));
return ProcessResult::Changed(mk_pending(obligation,
obligations));
}
}
let binder = obligation.predicate.kind();
match binder.no_bound_vars() {
None =>
match binder.skip_binder() {
ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_ref))
=> {
let trait_obligation =
obligation.with(infcx.tcx, binder.rebind(trait_ref));
self.process_trait_obligation(obligation, trait_obligation,
&mut pending_obligation.stalled_on)
}
ty::PredicateKind::Clause(ty::ClauseKind::Projection(data))
=> {
let project_obligation =
obligation.with(infcx.tcx, binder.rebind(data));
self.process_projection_obligation(obligation,
project_obligation, &mut pending_obligation.stalled_on)
}
ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(_))
| ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(_))
|
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))
| ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) |
ty::PredicateKind::DynCompatible(_) |
ty::PredicateKind::Subtype(_) | ty::PredicateKind::Coerce(_)
|
ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
| ty::PredicateKind::ConstEquate(..) |
ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(..)) =>
{
let pred =
ty::Binder::dummy(infcx.enter_forall_and_leak_universe(binder));
let mut obligations =
PredicateObligations::with_capacity(1);
obligations.push(obligation.with(infcx.tcx, pred));
ProcessResult::Changed(mk_pending(obligation, obligations))
}
ty::PredicateKind::Ambiguous => ProcessResult::Unchanged,
ty::PredicateKind::NormalizesTo(..) => {
bug_impl(None,
format_args!("NormalizesTo is only used by the new solver"),
Location::caller())
}
ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(_))
=> {
{
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("unexpected higher ranked `UnstableFeature` goal")));
}
}
},
Some(pred) =>
match pred {
ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => {
let trait_obligation =
obligation.with(infcx.tcx, Binder::dummy(data));
self.process_trait_obligation(obligation, trait_obligation,
&mut pending_obligation.stalled_on)
}
ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(data))
=> {
let host_obligation = obligation.with(infcx.tcx, data);
self.process_host_obligation(obligation, host_obligation,
&mut pending_obligation.stalled_on)
}
ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(data))
=> {
if infcx.considering_regions {
infcx.register_region_outlives_constraint(data,
ty::VisibleForLeakCheck::Yes, &obligation.cause);
}
ProcessResult::Changed(Default::default())
}
ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(ty::OutlivesClause(t_a,
r_b))) => {
if infcx.considering_regions {
infcx.register_type_outlives_constraint(t_a, r_b,
&obligation.cause);
}
ProcessResult::Changed(Default::default())
}
ty::PredicateKind::Clause(ty::ClauseKind::Projection(ref data))
=> {
let project_obligation =
obligation.with(infcx.tcx, Binder::dummy(*data));
self.process_projection_obligation(obligation,
project_obligation, &mut pending_obligation.stalled_on)
}
ty::PredicateKind::DynCompatible(trait_def_id) => {
if !self.selcx.tcx().is_dyn_compatible(trait_def_id) {
ProcessResult::Error(FulfillmentErrorCode::Select(SelectionError::Unimplemented))
} else { ProcessResult::Changed(Default::default()) }
}
ty::PredicateKind::Ambiguous => ProcessResult::Unchanged,
ty::PredicateKind::NormalizesTo(..) => {
bug_impl(None,
format_args!("NormalizesTo is only used by the new solver"),
Location::caller())
}
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct,
ty)) => {
let ct = infcx.shallow_resolve_const(ct);
let ct_ty =
match ct.kind() {
ty::ConstKind::Infer(var) => {
let var =
match var {
ty::InferConst::Var(vid) => TyOrConstInferVar::Const(vid),
ty::InferConst::Fresh(_) => {
bug_impl(None,
format_args!("encountered fresh const in fulfill"),
Location::caller())
}
};
pending_obligation.stalled_on.clear();
pending_obligation.stalled_on.extend([var]);
return ProcessResult::Unchanged;
}
ty::ConstKind::Error(_) => {
return ProcessResult::Changed(PendingPredicateObligations::new());
}
ty::ConstKind::Value(cv) => cv.ty,
ty::ConstKind::Alias(_, alias_const) => {
alias_const.type_of(infcx.tcx).skip_norm_wip()
}
ty::ConstKind::Expr(_) => {
return ProcessResult::Changed(mk_pending(obligation,
PredicateObligations::new()));
}
ty::ConstKind::Placeholder(_) => {
bug_impl(None,
format_args!("placeholder const {0:?} in old solver", ct),
Location::caller())
}
ty::ConstKind::Bound(_, _) =>
bug_impl(None,
format_args!("escaping bound vars in {0:?}", ct),
Location::caller()),
ty::ConstKind::Param(param_ct) => {
param_ct.find_const_ty_from_env(obligation.param_env)
}
};
match infcx.at(&obligation.cause,
obligation.param_env).eq(DefineOpaqueTypes::Yes, ct_ty, ty)
{
Ok(inf_ok) =>
ProcessResult::Changed(mk_pending(obligation,
inf_ok.into_obligations())),
Err(_) =>
ProcessResult::Error(FulfillmentErrorCode::Select(SelectionError::ConstArgHasWrongType {
ct,
ct_ty,
expected_ty: ty,
})),
}
}
_ if
!self.selcx.tcx().recursion_limit().value_within_limit(obligation.recursion_depth)
=> {
self.selcx.infcx.err_ctxt().report_overflow_obligation(&obligation,
false);
}
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(term))
=> {
if term.is_trivially_wf(self.selcx.tcx()) {
return ProcessResult::Changed(::thin_vec::ThinVec::new());
}
match wf::obligations(self.selcx.infcx,
obligation.param_env, obligation.cause.body_def_id,
obligation.recursion_depth + 1, term, obligation.cause.span)
{
None => {
pending_obligation.stalled_on =
::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[TyOrConstInferVar::maybe_from_term::<TyCtxt<'tcx>>(term).unwrap()]));
ProcessResult::Unchanged
}
Some(os) =>
ProcessResult::Changed(mk_pending(obligation, os)),
}
}
ty::PredicateKind::Subtype(subtype) => {
match self.selcx.infcx.subtype_predicate(&obligation.cause,
obligation.param_env, Binder::dummy(subtype)) {
Err((a, b)) => {
pending_obligation.stalled_on =
::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[TyOrConstInferVar::Ty(a), TyOrConstInferVar::Ty(b)]));
ProcessResult::Unchanged
}
Ok(Ok(ok)) => {
ProcessResult::Changed(mk_pending(obligation,
ok.obligations))
}
Ok(Err(err)) => {
let expected_found =
if subtype.a_is_expected {
ExpectedFound::new(subtype.a, subtype.b)
} else { ExpectedFound::new(subtype.b, subtype.a) };
ProcessResult::Error(FulfillmentErrorCode::Subtype(expected_found,
err))
}
}
}
ty::PredicateKind::Coerce(coerce) => {
match self.selcx.infcx.coerce_predicate(&obligation.cause,
obligation.param_env, Binder::dummy(coerce)) {
Err((a, b)) => {
pending_obligation.stalled_on =
::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[TyOrConstInferVar::Ty(a), TyOrConstInferVar::Ty(b)]));
ProcessResult::Unchanged
}
Ok(Ok(ok)) => {
ProcessResult::Changed(mk_pending(obligation,
ok.obligations))
}
Ok(Err(err)) => {
let expected_found = ExpectedFound::new(coerce.b, coerce.a);
ProcessResult::Error(FulfillmentErrorCode::Subtype(expected_found,
err))
}
}
}
ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(alias_const))
=> {
match const_evaluatable::is_const_evaluatable(self.selcx.infcx,
alias_const, obligation.param_env, obligation.cause.span) {
Ok(()) => ProcessResult::Changed(Default::default()),
Err(NotConstEvaluatable::MentionsInfer) => {
pending_obligation.stalled_on.clear();
pending_obligation.stalled_on.extend(alias_const.walk().filter_map(TyOrConstInferVar::maybe_from_generic_arg::<TyCtxt<'tcx>>));
ProcessResult::Unchanged
}
Err(e @ NotConstEvaluatable::MentionsParam | e @
NotConstEvaluatable::Error(_)) =>
ProcessResult::Error(FulfillmentErrorCode::Select(SelectionError::NotConstEvaluatable(e))),
}
}
ty::PredicateKind::ConstEquate(c1, c2) => {
let tcx = self.selcx.tcx();
if !tcx.features().generic_const_exprs() {
{
::core::panicking::panic_fmt(format_args!("`ConstEquate` without a feature gate: {0:?} {1:?}",
c1, c2));
}
};
{
let c1 = tcx.expand_abstract_consts(c1);
let c2 = tcx.expand_abstract_consts(c2);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs:716",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(716u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
::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!("equating consts:\nc1= {0:?}\nc2= {1:?}",
c1, c2) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
match (c1.kind(), c2.kind()) {
(ty::ConstKind::Alias(_, a), ty::ConstKind::Alias(_, b)) if
a.kind == b.kind &&
#[allow(non_exhaustive_omitted_patterns)] match a.kind {
ty::AliasConstKind::Projection { .. } |
ty::AliasConstKind::InherentSelf { .. } |
ty::AliasConstKind::InherentImpl { .. } => true,
_ => false,
} => {
if let Ok(new_obligations) =
infcx.at(&obligation.cause,
obligation.param_env).eq(DefineOpaqueTypes::Yes,
ty::AliasTerm::from(a), ty::AliasTerm::from(b)) {
return ProcessResult::Changed(mk_pending(obligation,
new_obligations.into_obligations()));
}
}
(_, ty::ConstKind::Alias(_, _)) |
(ty::ConstKind::Alias(_, _), _) => (),
(_, _) => {
if let Ok(new_obligations) =
infcx.at(&obligation.cause,
obligation.param_env).eq(DefineOpaqueTypes::Yes, c1, c2) {
return ProcessResult::Changed(mk_pending(obligation,
new_obligations.into_obligations()));
}
}
}
}
let stalled_on = &mut pending_obligation.stalled_on;
let mut evaluate =
|c: Const<'tcx>|
{
if let ty::ConstKind::Alias(_, alias_const) = c.kind() {
match super::try_evaluate_const(self.selcx.infcx, c,
obligation.param_env, |ty| Ok::<_, !>(ty.skip_norm_wip())) {
Ok(val) => Ok(val),
e @ Err(EvaluateConstErr::HasGenericsOrInfers) => {
stalled_on.extend(alias_const.args.iter().filter_map(TyOrConstInferVar::maybe_from_generic_arg::<TyCtxt<'tcx>>));
e
}
e @
Err(EvaluateConstErr::EvaluationFailure(_) |
EvaluateConstErr::InvalidConstParamTy(_)) => e,
}
} else { Ok(c) }
};
match (evaluate(c1), evaluate(c2)) {
(Ok(c1), Ok(c2)) => {
match self.selcx.infcx.at(&obligation.cause,
obligation.param_env).eq(DefineOpaqueTypes::Yes, c1, c2) {
Ok(inf_ok) =>
ProcessResult::Changed(mk_pending(obligation,
inf_ok.into_obligations())),
Err(err) => {
ProcessResult::Error(FulfillmentErrorCode::ConstEquate(ExpectedFound::new(c1,
c2), err))
}
}
}
(Err(EvaluateConstErr::InvalidConstParamTy(e)), _) |
(_, Err(EvaluateConstErr::InvalidConstParamTy(e))) => {
ProcessResult::Error(FulfillmentErrorCode::Select(SelectionError::NotConstEvaluatable(NotConstEvaluatable::Error(e))))
}
(Err(EvaluateConstErr::EvaluationFailure(e)), _) |
(_, Err(EvaluateConstErr::EvaluationFailure(e))) => {
ProcessResult::Error(FulfillmentErrorCode::Select(SelectionError::NotConstEvaluatable(NotConstEvaluatable::Error(e))))
}
(Err(EvaluateConstErr::HasGenericsOrInfers), _) |
(_, Err(EvaluateConstErr::HasGenericsOrInfers)) => {
if c1.has_non_region_infer() || c2.has_non_region_infer() {
ProcessResult::Unchanged
} else {
let expected_found = ExpectedFound::new(c1, c2);
ProcessResult::Error(FulfillmentErrorCode::ConstEquate(expected_found,
TypeError::ConstMismatch(expected_found)))
}
}
}
}
ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(symbol))
=> {
if may_use_unstable_feature(self.selcx.infcx,
obligation.param_env, symbol) {
ProcessResult::Changed(Default::default())
} else { ProcessResult::Unchanged }
}
},
}
}
}
}#[instrument(level = "debug", skip(self, pending_obligation))]
379 fn process_obligation(
380 &mut self,
381 pending_obligation: &mut PendingPredicateObligation<'tcx>,
382 ) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
383 pending_obligation.stalled_on.clear();
384
385 let obligation = &mut pending_obligation.obligation;
386
387 debug!(?obligation, "pre-resolve");
388
389 if obligation.predicate.has_non_region_infer() {
390 obligation.predicate =
391 self.selcx.infcx.deeply_resolve_ignoring_regions(obligation.predicate);
392 }
393
394 let obligation = &pending_obligation.obligation;
395
396 let infcx = self.selcx.infcx;
397
398 if !infcx.disable_trait_solver_fast_paths()
399 && sizedness_fast_path(infcx.tcx, obligation.predicate, obligation.param_env)
400 {
401 return ProcessResult::Changed(thin_vec![]);
402 }
403
404 if obligation.predicate.has_aliases() {
405 let mut obligations = PredicateObligations::new();
406 let predicate = normalize_with_depth_to(
407 &mut self.selcx,
408 obligation.param_env,
409 obligation.cause.clone(),
410 obligation.recursion_depth + 1,
411 ty::Unnormalized::new_wip(obligation.predicate),
412 &mut obligations,
413 );
414 if predicate != obligation.predicate {
415 obligations.push(obligation.with(infcx.tcx, predicate));
416 return ProcessResult::Changed(mk_pending(obligation, obligations));
417 }
418 }
419 let binder = obligation.predicate.kind();
420 match binder.no_bound_vars() {
421 None => match binder.skip_binder() {
422 ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_ref)) => {
426 let trait_obligation = obligation.with(infcx.tcx, binder.rebind(trait_ref));
427
428 self.process_trait_obligation(
429 obligation,
430 trait_obligation,
431 &mut pending_obligation.stalled_on,
432 )
433 }
434 ty::PredicateKind::Clause(ty::ClauseKind::Projection(data)) => {
435 let project_obligation = obligation.with(infcx.tcx, binder.rebind(data));
436
437 self.process_projection_obligation(
438 obligation,
439 project_obligation,
440 &mut pending_obligation.stalled_on,
441 )
442 }
443 ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(_))
444 | ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(_))
445 | ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))
446 | ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_))
447 | ty::PredicateKind::DynCompatible(_)
448 | ty::PredicateKind::Subtype(_)
449 | ty::PredicateKind::Coerce(_)
450 | ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
451 | ty::PredicateKind::ConstEquate(..)
452 | ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(..)) => {
456 let pred = ty::Binder::dummy(infcx.enter_forall_and_leak_universe(binder));
457 let mut obligations = PredicateObligations::with_capacity(1);
458 obligations.push(obligation.with(infcx.tcx, pred));
459
460 ProcessResult::Changed(mk_pending(obligation, obligations))
461 }
462 ty::PredicateKind::Ambiguous => ProcessResult::Unchanged,
463 ty::PredicateKind::NormalizesTo(..) => {
464 bug!("NormalizesTo is only used by the new solver")
465 }
466 ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(_)) => {
467 unreachable!("unexpected higher ranked `UnstableFeature` goal")
468 }
469 },
470 Some(pred) => match pred {
471 ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => {
472 let trait_obligation = obligation.with(infcx.tcx, Binder::dummy(data));
473
474 self.process_trait_obligation(
475 obligation,
476 trait_obligation,
477 &mut pending_obligation.stalled_on,
478 )
479 }
480
481 ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(data)) => {
482 let host_obligation = obligation.with(infcx.tcx, data);
483
484 self.process_host_obligation(
485 obligation,
486 host_obligation,
487 &mut pending_obligation.stalled_on,
488 )
489 }
490
491 ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(data)) => {
492 if infcx.considering_regions {
493 infcx.register_region_outlives_constraint(
494 data,
495 ty::VisibleForLeakCheck::Yes,
496 &obligation.cause,
497 );
498 }
499
500 ProcessResult::Changed(Default::default())
501 }
502
503 ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(ty::OutlivesClause(
504 t_a,
505 r_b,
506 ))) => {
507 if infcx.considering_regions {
508 infcx.register_type_outlives_constraint(t_a, r_b, &obligation.cause);
509 }
510 ProcessResult::Changed(Default::default())
511 }
512
513 ty::PredicateKind::Clause(ty::ClauseKind::Projection(ref data)) => {
514 let project_obligation = obligation.with(infcx.tcx, Binder::dummy(*data));
515
516 self.process_projection_obligation(
517 obligation,
518 project_obligation,
519 &mut pending_obligation.stalled_on,
520 )
521 }
522
523 ty::PredicateKind::DynCompatible(trait_def_id) => {
524 if !self.selcx.tcx().is_dyn_compatible(trait_def_id) {
525 ProcessResult::Error(FulfillmentErrorCode::Select(
526 SelectionError::Unimplemented,
527 ))
528 } else {
529 ProcessResult::Changed(Default::default())
530 }
531 }
532
533 ty::PredicateKind::Ambiguous => ProcessResult::Unchanged,
534 ty::PredicateKind::NormalizesTo(..) => {
535 bug!("NormalizesTo is only used by the new solver")
536 }
537 ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
541 let ct = infcx.shallow_resolve_const(ct);
542 let ct_ty = match ct.kind() {
543 ty::ConstKind::Infer(var) => {
544 let var = match var {
545 ty::InferConst::Var(vid) => TyOrConstInferVar::Const(vid),
546 ty::InferConst::Fresh(_) => {
547 bug!("encountered fresh const in fulfill")
548 }
549 };
550 pending_obligation.stalled_on.clear();
551 pending_obligation.stalled_on.extend([var]);
552 return ProcessResult::Unchanged;
553 }
554 ty::ConstKind::Error(_) => {
555 return ProcessResult::Changed(PendingPredicateObligations::new());
556 }
557 ty::ConstKind::Value(cv) => cv.ty,
558 ty::ConstKind::Alias(_, alias_const) => {
559 alias_const.type_of(infcx.tcx).skip_norm_wip()
560 }
561 ty::ConstKind::Expr(_) => {
565 return ProcessResult::Changed(mk_pending(
566 obligation,
567 PredicateObligations::new(),
568 ));
569 }
570 ty::ConstKind::Placeholder(_) => {
571 bug!("placeholder const {:?} in old solver", ct)
572 }
573 ty::ConstKind::Bound(_, _) => bug!("escaping bound vars in {:?}", ct),
574 ty::ConstKind::Param(param_ct) => {
575 param_ct.find_const_ty_from_env(obligation.param_env)
576 }
577 };
578
579 match infcx.at(&obligation.cause, obligation.param_env).eq(
580 DefineOpaqueTypes::Yes,
582 ct_ty,
583 ty,
584 ) {
585 Ok(inf_ok) => ProcessResult::Changed(mk_pending(
586 obligation,
587 inf_ok.into_obligations(),
588 )),
589 Err(_) => ProcessResult::Error(FulfillmentErrorCode::Select(
590 SelectionError::ConstArgHasWrongType { ct, ct_ty, expected_ty: ty },
591 )),
592 }
593 }
594
595 _ if !self
600 .selcx
601 .tcx()
602 .recursion_limit()
603 .value_within_limit(obligation.recursion_depth) =>
604 {
605 self.selcx.infcx.err_ctxt().report_overflow_obligation(&obligation, false);
606 }
607
608 ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(term)) => {
609 if term.is_trivially_wf(self.selcx.tcx()) {
610 return ProcessResult::Changed(thin_vec![]);
611 }
612
613 match wf::obligations(
614 self.selcx.infcx,
615 obligation.param_env,
616 obligation.cause.body_def_id,
617 obligation.recursion_depth + 1,
618 term,
619 obligation.cause.span,
620 ) {
621 None => {
622 pending_obligation.stalled_on = vec![
623 TyOrConstInferVar::maybe_from_term::<TyCtxt<'tcx>>(term).unwrap(),
624 ];
625 ProcessResult::Unchanged
626 }
627 Some(os) => ProcessResult::Changed(mk_pending(obligation, os)),
628 }
629 }
630
631 ty::PredicateKind::Subtype(subtype) => {
632 match self.selcx.infcx.subtype_predicate(
633 &obligation.cause,
634 obligation.param_env,
635 Binder::dummy(subtype),
636 ) {
637 Err((a, b)) => {
638 pending_obligation.stalled_on =
640 vec![TyOrConstInferVar::Ty(a), TyOrConstInferVar::Ty(b)];
641 ProcessResult::Unchanged
642 }
643 Ok(Ok(ok)) => {
644 ProcessResult::Changed(mk_pending(obligation, ok.obligations))
645 }
646 Ok(Err(err)) => {
647 let expected_found = if subtype.a_is_expected {
648 ExpectedFound::new(subtype.a, subtype.b)
649 } else {
650 ExpectedFound::new(subtype.b, subtype.a)
651 };
652 ProcessResult::Error(FulfillmentErrorCode::Subtype(expected_found, err))
653 }
654 }
655 }
656
657 ty::PredicateKind::Coerce(coerce) => {
658 match self.selcx.infcx.coerce_predicate(
659 &obligation.cause,
660 obligation.param_env,
661 Binder::dummy(coerce),
662 ) {
663 Err((a, b)) => {
664 pending_obligation.stalled_on =
666 vec![TyOrConstInferVar::Ty(a), TyOrConstInferVar::Ty(b)];
667 ProcessResult::Unchanged
668 }
669 Ok(Ok(ok)) => {
670 ProcessResult::Changed(mk_pending(obligation, ok.obligations))
671 }
672 Ok(Err(err)) => {
673 let expected_found = ExpectedFound::new(coerce.b, coerce.a);
674 ProcessResult::Error(FulfillmentErrorCode::Subtype(expected_found, err))
675 }
676 }
677 }
678
679 ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(alias_const)) => {
680 match const_evaluatable::is_const_evaluatable(
681 self.selcx.infcx,
682 alias_const,
683 obligation.param_env,
684 obligation.cause.span,
685 ) {
686 Ok(()) => ProcessResult::Changed(Default::default()),
687 Err(NotConstEvaluatable::MentionsInfer) => {
688 pending_obligation.stalled_on.clear();
689 pending_obligation.stalled_on.extend(alias_const.walk().filter_map(
690 TyOrConstInferVar::maybe_from_generic_arg::<TyCtxt<'tcx>>,
691 ));
692 ProcessResult::Unchanged
693 }
694 Err(
695 e @ NotConstEvaluatable::MentionsParam
696 | e @ NotConstEvaluatable::Error(_),
697 ) => ProcessResult::Error(FulfillmentErrorCode::Select(
698 SelectionError::NotConstEvaluatable(e),
699 )),
700 }
701 }
702
703 ty::PredicateKind::ConstEquate(c1, c2) => {
704 let tcx = self.selcx.tcx();
705 assert!(
706 tcx.features().generic_const_exprs(),
707 "`ConstEquate` without a feature gate: {c1:?} {c2:?}",
708 );
709 {
714 let c1 = tcx.expand_abstract_consts(c1);
715 let c2 = tcx.expand_abstract_consts(c2);
716 debug!("equating consts:\nc1= {:?}\nc2= {:?}", c1, c2);
717
718 match (c1.kind(), c2.kind()) {
719 (ty::ConstKind::Alias(_, a), ty::ConstKind::Alias(_, b))
720 if a.kind == b.kind
721 && matches!(
722 a.kind,
723 ty::AliasConstKind::Projection { .. }
724 | ty::AliasConstKind::InherentSelf { .. }
725 | ty::AliasConstKind::InherentImpl { .. }
726 ) =>
727 {
728 if let Ok(new_obligations) = infcx
729 .at(&obligation.cause, obligation.param_env)
730 .eq(
733 DefineOpaqueTypes::Yes,
734 ty::AliasTerm::from(a),
735 ty::AliasTerm::from(b),
736 )
737 {
738 return ProcessResult::Changed(mk_pending(
739 obligation,
740 new_obligations.into_obligations(),
741 ));
742 }
743 }
744 (_, ty::ConstKind::Alias(_, _)) | (ty::ConstKind::Alias(_, _), _) => (),
745 (_, _) => {
746 if let Ok(new_obligations) = infcx
747 .at(&obligation.cause, obligation.param_env)
748 .eq(DefineOpaqueTypes::Yes, c1, c2)
751 {
752 return ProcessResult::Changed(mk_pending(
753 obligation,
754 new_obligations.into_obligations(),
755 ));
756 }
757 }
758 }
759 }
760
761 let stalled_on = &mut pending_obligation.stalled_on;
762
763 let mut evaluate = |c: Const<'tcx>| {
764 if let ty::ConstKind::Alias(_, alias_const) = c.kind() {
765 match super::try_evaluate_const(
766 self.selcx.infcx,
767 c,
768 obligation.param_env,
769 |ty| Ok::<_, !>(ty.skip_norm_wip()),
770 ) {
771 Ok(val) => Ok(val),
772 e @ Err(EvaluateConstErr::HasGenericsOrInfers) => {
773 stalled_on.extend(alias_const.args.iter().filter_map(
774 TyOrConstInferVar::maybe_from_generic_arg::<TyCtxt<'tcx>>,
775 ));
776 e
777 }
778 e @ Err(
779 EvaluateConstErr::EvaluationFailure(_)
780 | EvaluateConstErr::InvalidConstParamTy(_),
781 ) => e,
782 }
783 } else {
784 Ok(c)
785 }
786 };
787
788 match (evaluate(c1), evaluate(c2)) {
789 (Ok(c1), Ok(c2)) => {
790 match self.selcx.infcx.at(&obligation.cause, obligation.param_env).eq(
791 DefineOpaqueTypes::Yes,
794 c1,
795 c2,
796 ) {
797 Ok(inf_ok) => ProcessResult::Changed(mk_pending(
798 obligation,
799 inf_ok.into_obligations(),
800 )),
801 Err(err) => {
802 ProcessResult::Error(FulfillmentErrorCode::ConstEquate(
803 ExpectedFound::new(c1, c2),
804 err,
805 ))
806 }
807 }
808 }
809 (Err(EvaluateConstErr::InvalidConstParamTy(e)), _)
810 | (_, Err(EvaluateConstErr::InvalidConstParamTy(e))) => {
811 ProcessResult::Error(FulfillmentErrorCode::Select(
812 SelectionError::NotConstEvaluatable(NotConstEvaluatable::Error(e)),
813 ))
814 }
815 (Err(EvaluateConstErr::EvaluationFailure(e)), _)
816 | (_, Err(EvaluateConstErr::EvaluationFailure(e))) => {
817 ProcessResult::Error(FulfillmentErrorCode::Select(
818 SelectionError::NotConstEvaluatable(NotConstEvaluatable::Error(e)),
819 ))
820 }
821 (Err(EvaluateConstErr::HasGenericsOrInfers), _)
822 | (_, Err(EvaluateConstErr::HasGenericsOrInfers)) => {
823 if c1.has_non_region_infer() || c2.has_non_region_infer() {
824 ProcessResult::Unchanged
825 } else {
826 let expected_found = ExpectedFound::new(c1, c2);
828 ProcessResult::Error(FulfillmentErrorCode::ConstEquate(
829 expected_found,
830 TypeError::ConstMismatch(expected_found),
831 ))
832 }
833 }
834 }
835 }
836 ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(symbol)) => {
837 if may_use_unstable_feature(self.selcx.infcx, obligation.param_env, symbol) {
838 ProcessResult::Changed(Default::default())
839 } else {
840 ProcessResult::Unchanged
841 }
842 }
843 },
844 }
845 }
846
847 #[inline(never)]
848 fn process_backedge<'c, I>(
849 &mut self,
850 cycle: I,
851 _marker: PhantomData<&'c PendingPredicateObligation<'tcx>>,
852 ) -> Result<(), FulfillmentErrorCode<'tcx>>
853 where
854 I: Clone + Iterator<Item = &'c PendingPredicateObligation<'tcx>>,
855 {
856 if self.selcx.coinductive_match(cycle.clone().map(|s| s.obligation.predicate)) {
857 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs:857",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(857u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
::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!("process_child_obligations: coinductive match")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("process_child_obligations: coinductive match");
858 Ok(())
859 } else {
860 let cycle = cycle.map(|c| c.obligation.clone()).collect();
861 Err(FulfillmentErrorCode::Cycle(cycle))
862 }
863 }
864}
865
866impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
867 {}
#[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("process_trait_obligation",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(867u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("trait_obligation")
}> =
::tracing::__macro_support::FieldName::new("trait_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(&trait_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:
ProcessResult<PendingPredicateObligation<'tcx>,
FulfillmentErrorCode<'tcx>> = loop {};
return __tracing_attr_fake_return;
}
{
let infcx = self.selcx.infcx;
if obligation.predicate.is_global() &&
!self.selcx.typing_mode().is_coherence() {
if infcx.predicate_must_hold_considering_regions(obligation) {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs:879",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(879u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
::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!("selecting trait at depth {0} evaluated to holds",
obligation.recursion_depth) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};
return ProcessResult::Changed(Default::default());
}
}
match self.selcx.poly_select(&trait_obligation) {
Ok(Some(impl_source)) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs:889",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(889u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
::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!("selecting trait at depth {0} yielded Ok(Some)",
obligation.recursion_depth) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};
ProcessResult::Changed(mk_pending(obligation,
impl_source.nested_obligations()))
}
Ok(None) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs:893",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(893u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
::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!("selecting trait at depth {0} yielded Ok(None)",
obligation.recursion_depth) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};
stalled_on.clear();
stalled_on.extend(args_infer_vars(&self.selcx,
trait_obligation.predicate.map_bound(|pred|
pred.trait_ref.args)));
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs:905",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(905u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
::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!("process_predicate: pending obligation {0:?} now stalled on {1:?}",
infcx.deeply_resolve_ignoring_regions(obligation.clone()),
stalled_on) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
ProcessResult::Unchanged
}
Err(selection_err) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs:914",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(914u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
::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!("selecting trait at depth {0} yielded Err",
obligation.recursion_depth) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};
ProcessResult::Error(FulfillmentErrorCode::Select(selection_err))
}
}
}
}
}#[instrument(level = "debug", skip(self, obligation, stalled_on))]
868 fn process_trait_obligation(
869 &mut self,
870 obligation: &PredicateObligation<'tcx>,
871 trait_obligation: PolyTraitObligation<'tcx>,
872 stalled_on: &mut Vec<TyOrConstInferVar>,
873 ) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
874 let infcx = self.selcx.infcx;
875 if obligation.predicate.is_global() && !self.selcx.typing_mode().is_coherence() {
876 if infcx.predicate_must_hold_considering_regions(obligation) {
879 debug!(
880 "selecting trait at depth {} evaluated to holds",
881 obligation.recursion_depth
882 );
883 return ProcessResult::Changed(Default::default());
884 }
885 }
886
887 match self.selcx.poly_select(&trait_obligation) {
888 Ok(Some(impl_source)) => {
889 debug!("selecting trait at depth {} yielded Ok(Some)", obligation.recursion_depth);
890 ProcessResult::Changed(mk_pending(obligation, impl_source.nested_obligations()))
891 }
892 Ok(None) => {
893 debug!("selecting trait at depth {} yielded Ok(None)", obligation.recursion_depth);
894
895 stalled_on.clear();
900 stalled_on.extend(args_infer_vars(
901 &self.selcx,
902 trait_obligation.predicate.map_bound(|pred| pred.trait_ref.args),
903 ));
904
905 debug!(
906 "process_predicate: pending obligation {:?} now stalled on {:?}",
907 infcx.deeply_resolve_ignoring_regions(obligation.clone()),
908 stalled_on
909 );
910
911 ProcessResult::Unchanged
912 }
913 Err(selection_err) => {
914 debug!("selecting trait at depth {} yielded Err", obligation.recursion_depth);
915
916 ProcessResult::Error(FulfillmentErrorCode::Select(selection_err))
917 }
918 }
919 }
920
921 fn process_projection_obligation(
922 &mut self,
923 obligation: &PredicateObligation<'tcx>,
924 project_obligation: PolyProjectionObligation<'tcx>,
925 stalled_on: &mut Vec<TyOrConstInferVar>,
926 ) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
927 let tcx = self.selcx.tcx();
928 let infcx = self.selcx.infcx;
929 if obligation.predicate.is_global() && !self.selcx.typing_mode().is_coherence() {
930 if infcx.predicate_must_hold_considering_regions(obligation) {
933 if let Some(key) = ProjectionCacheKey::from_poly_projection_obligation(
934 &mut self.selcx,
935 &project_obligation,
936 ) {
937 infcx
941 .inner
942 .borrow_mut()
943 .projection_cache()
944 .complete(key, EvaluationResult::EvaluatedToOk);
945 }
946 return ProcessResult::Changed(Default::default());
947 } else {
948 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs:948",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(948u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::fulfill"),
::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!("Does NOT hold: {0:?}",
obligation) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("Does NOT hold: {:?}", obligation);
949 }
950 }
951
952 match project::poly_project_and_unify_term(&mut self.selcx, &project_obligation) {
953 ProjectAndUnifyResult::Holds(os) if os.is_empty() => {
954 ProcessResult::Changed(mk_pending(obligation, os))
955 }
956 ProjectAndUnifyResult::Holds(os) => {
957 let input_projection_term = infcx
958 .deeply_resolve_ignoring_regions(project_obligation.predicate)
959 .map_bound(|p| p.projection_term);
960 let all_same_projection_term = os.iter().all(|o| {
961 let Some(proj_clause) = o.predicate.as_projection_clause() else {
962 return false;
963 };
964 infcx
965 .deeply_resolve_ignoring_regions(proj_clause)
966 .map_bound(|p| p.projection_term)
967 == input_projection_term
968 });
969 if all_same_projection_term {
970 ProcessResult::Error(FulfillmentErrorCode::Ambiguity { overflow: None })
980 } else {
981 ProcessResult::Changed(mk_pending(obligation, os))
982 }
983 }
984 ProjectAndUnifyResult::FailedNormalization => {
985 stalled_on.clear();
986 stalled_on.extend(args_infer_vars(
987 &self.selcx,
988 project_obligation.predicate.map_bound(|pred| pred.projection_term.args),
989 ));
990 ProcessResult::Unchanged
991 }
992 ProjectAndUnifyResult::Recursive => {
994 let mut obligations = PredicateObligations::with_capacity(1);
995 obligations.push(project_obligation.with(tcx, project_obligation.predicate));
996
997 ProcessResult::Changed(mk_pending(obligation, obligations))
998 }
999 ProjectAndUnifyResult::MismatchedProjectionTypes(e) => {
1000 ProcessResult::Error(FulfillmentErrorCode::Project(e))
1001 }
1002 }
1003 }
1004
1005 fn process_host_obligation(
1006 &mut self,
1007 obligation: &PredicateObligation<'tcx>,
1008 host_obligation: HostEffectObligation<'tcx>,
1009 stalled_on: &mut Vec<TyOrConstInferVar>,
1010 ) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
1011 match effects::evaluate_host_effect_obligation(&mut self.selcx, &host_obligation) {
1012 Ok(nested) => ProcessResult::Changed(mk_pending(obligation, nested)),
1013 Err(effects::EvaluationFailure::Ambiguous) => {
1014 stalled_on.clear();
1015 stalled_on.extend(args_infer_vars(
1016 &self.selcx,
1017 ty::Binder::dummy(host_obligation.predicate.trait_ref.args),
1018 ));
1019 ProcessResult::Unchanged
1020 }
1021 Err(effects::EvaluationFailure::NoSolution) => {
1022 ProcessResult::Error(FulfillmentErrorCode::Select(SelectionError::Unimplemented))
1023 }
1024 }
1025 }
1026}
1027
1028fn args_infer_vars<'tcx>(
1030 selcx: &SelectionContext<'_, 'tcx>,
1031 args: ty::Binder<'tcx, GenericArgsRef<'tcx>>,
1032) -> impl Iterator<Item = TyOrConstInferVar> {
1033 selcx
1034 .infcx
1035 .deeply_resolve_ignoring_regions(args)
1036 .skip_binder() .iter()
1038 .filter(|arg| arg.has_non_region_infer())
1039 .flat_map(|arg| {
1040 let mut walker = arg.walk();
1041 while let Some(c) = walker.next() {
1042 if !c.has_non_region_infer() {
1043 walker.visited.remove(&c);
1044 walker.skip_current_subtree();
1045 }
1046 }
1047 walker.visited.into_iter()
1048 })
1049 .filter_map(TyOrConstInferVar::maybe_from_generic_arg::<TyCtxt<'tcx>>)
1050}
1051
1052#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for OldSolverError<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "OldSolverError",
&&self.0)
}
}Debug)]
1053pub struct OldSolverError<'tcx>(
1054 Error<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>>,
1055);
1056
1057impl<'tcx> FromSolverError<'tcx, OldSolverError<'tcx>> for FulfillmentError<'tcx> {
1058 fn from_solver_error(_infcx: &InferCtxt<'tcx>, error: OldSolverError<'tcx>) -> Self {
1059 let mut iter = error.0.backtrace.into_iter();
1060 let obligation = iter.next().unwrap().obligation;
1061 let root_obligation = iter.next_back().map_or_else(|| obligation.clone(), |e| e.obligation);
1064 FulfillmentError::new(obligation, error.0.error, root_obligation)
1065 }
1066}
1067
1068impl<'tcx> FromSolverError<'tcx, OldSolverError<'tcx>> for ScrubbedTraitError<'tcx> {
1069 fn from_solver_error(_infcx: &InferCtxt<'tcx>, error: OldSolverError<'tcx>) -> Self {
1070 match error.0.error {
1071 FulfillmentErrorCode::Select(_)
1072 | FulfillmentErrorCode::Project(_)
1073 | FulfillmentErrorCode::Outlives
1074 | FulfillmentErrorCode::Subtype(_, _)
1075 | FulfillmentErrorCode::ConstEquate(_, _) => ScrubbedTraitError::TrueError,
1076 FulfillmentErrorCode::Ambiguity { overflow: _ } => ScrubbedTraitError::Ambiguity,
1077 FulfillmentErrorCode::Cycle(cycle) => ScrubbedTraitError::Cycle(cycle),
1078 }
1079 }
1080}