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