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::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 rustc_next_trait_solver::solve::TyOrConstInferVar;
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/cea272fa356e94bd2ee2cadf376630aa0683867a/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/cea272fa356e94bd2ee2cadf376630aa0683867a/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/cea272fa356e94bd2ee2cadf376630aa0683867a/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.resolve_vars_if_possible(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/cea272fa356e94bd2ee2cadf376630aa0683867a/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/cea272fa356e94bd2ee2cadf376630aa0683867a/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 .resolve_vars_if_possible(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/cea272fa356e94bd2ee2cadf376630aa0683867a/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/cea272fa356e94bd2ee2cadf376630aa0683867a/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/cea272fa356e94bd2ee2cadf376630aa0683867a/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.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,
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(..) => {
::rustc_middle::util::bug::bug_fmt(format_args!("NormalizesTo 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::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(..) => {
::rustc_middle::util::bug::bug_fmt(format_args!("NormalizesTo 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_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/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_trait_selection/src/traits/fulfill.rs:715",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(715u32),
::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 = self.selcx.infcx.resolve_vars_if_possible(obligation.predicate);
391 }
392
393 let obligation = &pending_obligation.obligation;
394
395 let infcx = self.selcx.infcx;
396
397 if !infcx.disable_trait_solver_fast_paths()
398 && sizedness_fast_path(infcx.tcx, obligation.predicate, obligation.param_env)
399 {
400 return ProcessResult::Changed(thin_vec![]);
401 }
402
403 if obligation.predicate.has_aliases() {
404 let mut obligations = PredicateObligations::new();
405 let predicate = normalize_with_depth_to(
406 &mut self.selcx,
407 obligation.param_env,
408 obligation.cause.clone(),
409 obligation.recursion_depth + 1,
410 ty::Unnormalized::new_wip(obligation.predicate),
411 &mut obligations,
412 );
413 if predicate != obligation.predicate {
414 obligations.push(obligation.with(infcx.tcx, predicate));
415 return ProcessResult::Changed(mk_pending(obligation, obligations));
416 }
417 }
418 let binder = obligation.predicate.kind();
419 match binder.no_bound_vars() {
420 None => match binder.skip_binder() {
421 ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_ref)) => {
425 let trait_obligation = obligation.with(infcx.tcx, binder.rebind(trait_ref));
426
427 self.process_trait_obligation(
428 obligation,
429 trait_obligation,
430 &mut pending_obligation.stalled_on,
431 )
432 }
433 ty::PredicateKind::Clause(ty::ClauseKind::Projection(data)) => {
434 let project_obligation = obligation.with(infcx.tcx, binder.rebind(data));
435
436 self.process_projection_obligation(
437 obligation,
438 project_obligation,
439 &mut pending_obligation.stalled_on,
440 )
441 }
442 ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(_))
443 | ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(_))
444 | ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))
445 | ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_))
446 | ty::PredicateKind::DynCompatible(_)
447 | ty::PredicateKind::Subtype(_)
448 | ty::PredicateKind::Coerce(_)
449 | ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
450 | ty::PredicateKind::ConstEquate(..)
451 | ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(..)) => {
455 let pred = ty::Binder::dummy(infcx.enter_forall_and_leak_universe(binder));
456 let mut obligations = PredicateObligations::with_capacity(1);
457 obligations.push(obligation.with(infcx.tcx, pred));
458
459 ProcessResult::Changed(mk_pending(obligation, obligations))
460 }
461 ty::PredicateKind::Ambiguous => ProcessResult::Unchanged,
462 ty::PredicateKind::NormalizesTo(..) => {
463 bug!("NormalizesTo is only used by the new solver")
464 }
465 ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(_)) => {
466 unreachable!("unexpected higher ranked `UnstableFeature` goal")
467 }
468 },
469 Some(pred) => match pred {
470 ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => {
471 let trait_obligation = obligation.with(infcx.tcx, Binder::dummy(data));
472
473 self.process_trait_obligation(
474 obligation,
475 trait_obligation,
476 &mut pending_obligation.stalled_on,
477 )
478 }
479
480 ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(data)) => {
481 let host_obligation = obligation.with(infcx.tcx, data);
482
483 self.process_host_obligation(
484 obligation,
485 host_obligation,
486 &mut pending_obligation.stalled_on,
487 )
488 }
489
490 ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(data)) => {
491 if infcx.considering_regions {
492 infcx.register_region_outlives_constraint(
493 data,
494 ty::VisibleForLeakCheck::Yes,
495 &obligation.cause,
496 );
497 }
498
499 ProcessResult::Changed(Default::default())
500 }
501
502 ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(ty::OutlivesClause(
503 t_a,
504 r_b,
505 ))) => {
506 if infcx.considering_regions {
507 infcx.register_type_outlives_constraint(t_a, r_b, &obligation.cause);
508 }
509 ProcessResult::Changed(Default::default())
510 }
511
512 ty::PredicateKind::Clause(ty::ClauseKind::Projection(ref data)) => {
513 let project_obligation = obligation.with(infcx.tcx, Binder::dummy(*data));
514
515 self.process_projection_obligation(
516 obligation,
517 project_obligation,
518 &mut pending_obligation.stalled_on,
519 )
520 }
521
522 ty::PredicateKind::DynCompatible(trait_def_id) => {
523 if !self.selcx.tcx().is_dyn_compatible(trait_def_id) {
524 ProcessResult::Error(FulfillmentErrorCode::Select(
525 SelectionError::Unimplemented,
526 ))
527 } else {
528 ProcessResult::Changed(Default::default())
529 }
530 }
531
532 ty::PredicateKind::Ambiguous => ProcessResult::Unchanged,
533 ty::PredicateKind::NormalizesTo(..) => {
534 bug!("NormalizesTo is only used by the new solver")
535 }
536 ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
540 let ct = infcx.shallow_resolve_const(ct);
541 let ct_ty = match ct.kind() {
542 ty::ConstKind::Infer(var) => {
543 let var = match var {
544 ty::InferConst::Var(vid) => TyOrConstInferVar::Const(vid),
545 ty::InferConst::Fresh(_) => {
546 bug!("encountered fresh const in fulfill")
547 }
548 };
549 pending_obligation.stalled_on.clear();
550 pending_obligation.stalled_on.extend([var]);
551 return ProcessResult::Unchanged;
552 }
553 ty::ConstKind::Error(_) => {
554 return ProcessResult::Changed(PendingPredicateObligations::new());
555 }
556 ty::ConstKind::Value(cv) => cv.ty,
557 ty::ConstKind::Alias(_, alias_const) => {
558 alias_const.type_of(infcx.tcx).skip_norm_wip()
559 }
560 ty::ConstKind::Expr(_) => {
564 return ProcessResult::Changed(mk_pending(
565 obligation,
566 PredicateObligations::new(),
567 ));
568 }
569 ty::ConstKind::Placeholder(_) => {
570 bug!("placeholder const {:?} in old solver", ct)
571 }
572 ty::ConstKind::Bound(_, _) => bug!("escaping bound vars in {:?}", ct),
573 ty::ConstKind::Param(param_ct) => {
574 param_ct.find_const_ty_from_env(obligation.param_env)
575 }
576 };
577
578 match infcx.at(&obligation.cause, obligation.param_env).eq(
579 DefineOpaqueTypes::Yes,
581 ct_ty,
582 ty,
583 ) {
584 Ok(inf_ok) => ProcessResult::Changed(mk_pending(
585 obligation,
586 inf_ok.into_obligations(),
587 )),
588 Err(_) => ProcessResult::Error(FulfillmentErrorCode::Select(
589 SelectionError::ConstArgHasWrongType { ct, ct_ty, expected_ty: ty },
590 )),
591 }
592 }
593
594 _ if !self
599 .selcx
600 .tcx()
601 .recursion_limit()
602 .value_within_limit(obligation.recursion_depth) =>
603 {
604 self.selcx.infcx.err_ctxt().report_overflow_obligation(&obligation, false);
605 }
606
607 ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(term)) => {
608 if term.is_trivially_wf(self.selcx.tcx()) {
609 return ProcessResult::Changed(thin_vec![]);
610 }
611
612 match wf::obligations(
613 self.selcx.infcx,
614 obligation.param_env,
615 obligation.cause.body_def_id,
616 obligation.recursion_depth + 1,
617 term,
618 obligation.cause.span,
619 ) {
620 None => {
621 pending_obligation.stalled_on = vec![
622 TyOrConstInferVar::maybe_from_term::<TyCtxt<'tcx>>(term).unwrap(),
623 ];
624 ProcessResult::Unchanged
625 }
626 Some(os) => ProcessResult::Changed(mk_pending(obligation, os)),
627 }
628 }
629
630 ty::PredicateKind::Subtype(subtype) => {
631 match self.selcx.infcx.subtype_predicate(
632 &obligation.cause,
633 obligation.param_env,
634 Binder::dummy(subtype),
635 ) {
636 Err((a, b)) => {
637 pending_obligation.stalled_on =
639 vec![TyOrConstInferVar::Ty(a), TyOrConstInferVar::Ty(b)];
640 ProcessResult::Unchanged
641 }
642 Ok(Ok(ok)) => {
643 ProcessResult::Changed(mk_pending(obligation, ok.obligations))
644 }
645 Ok(Err(err)) => {
646 let expected_found = if subtype.a_is_expected {
647 ExpectedFound::new(subtype.a, subtype.b)
648 } else {
649 ExpectedFound::new(subtype.b, subtype.a)
650 };
651 ProcessResult::Error(FulfillmentErrorCode::Subtype(expected_found, err))
652 }
653 }
654 }
655
656 ty::PredicateKind::Coerce(coerce) => {
657 match self.selcx.infcx.coerce_predicate(
658 &obligation.cause,
659 obligation.param_env,
660 Binder::dummy(coerce),
661 ) {
662 Err((a, b)) => {
663 pending_obligation.stalled_on =
665 vec![TyOrConstInferVar::Ty(a), TyOrConstInferVar::Ty(b)];
666 ProcessResult::Unchanged
667 }
668 Ok(Ok(ok)) => {
669 ProcessResult::Changed(mk_pending(obligation, ok.obligations))
670 }
671 Ok(Err(err)) => {
672 let expected_found = ExpectedFound::new(coerce.b, coerce.a);
673 ProcessResult::Error(FulfillmentErrorCode::Subtype(expected_found, err))
674 }
675 }
676 }
677
678 ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(alias_const)) => {
679 match const_evaluatable::is_const_evaluatable(
680 self.selcx.infcx,
681 alias_const,
682 obligation.param_env,
683 obligation.cause.span,
684 ) {
685 Ok(()) => ProcessResult::Changed(Default::default()),
686 Err(NotConstEvaluatable::MentionsInfer) => {
687 pending_obligation.stalled_on.clear();
688 pending_obligation.stalled_on.extend(alias_const.walk().filter_map(
689 TyOrConstInferVar::maybe_from_generic_arg::<TyCtxt<'tcx>>,
690 ));
691 ProcessResult::Unchanged
692 }
693 Err(
694 e @ NotConstEvaluatable::MentionsParam
695 | e @ NotConstEvaluatable::Error(_),
696 ) => ProcessResult::Error(FulfillmentErrorCode::Select(
697 SelectionError::NotConstEvaluatable(e),
698 )),
699 }
700 }
701
702 ty::PredicateKind::ConstEquate(c1, c2) => {
703 let tcx = self.selcx.tcx();
704 assert!(
705 tcx.features().generic_const_exprs(),
706 "`ConstEquate` without a feature gate: {c1:?} {c2:?}",
707 );
708 {
713 let c1 = tcx.expand_abstract_consts(c1);
714 let c2 = tcx.expand_abstract_consts(c2);
715 debug!("equating consts:\nc1= {:?}\nc2= {:?}", c1, c2);
716
717 match (c1.kind(), c2.kind()) {
718 (ty::ConstKind::Alias(_, a), ty::ConstKind::Alias(_, b))
719 if a.kind == b.kind
720 && matches!(
721 a.kind,
722 ty::AliasConstKind::Projection { .. }
723 | ty::AliasConstKind::InherentSelf { .. }
724 | ty::AliasConstKind::InherentImpl { .. }
725 ) =>
726 {
727 if let Ok(new_obligations) = infcx
728 .at(&obligation.cause, obligation.param_env)
729 .eq(
732 DefineOpaqueTypes::Yes,
733 ty::AliasTerm::from(a),
734 ty::AliasTerm::from(b),
735 )
736 {
737 return ProcessResult::Changed(mk_pending(
738 obligation,
739 new_obligations.into_obligations(),
740 ));
741 }
742 }
743 (_, ty::ConstKind::Alias(_, _)) | (ty::ConstKind::Alias(_, _), _) => (),
744 (_, _) => {
745 if let Ok(new_obligations) = infcx
746 .at(&obligation.cause, obligation.param_env)
747 .eq(DefineOpaqueTypes::Yes, c1, c2)
750 {
751 return ProcessResult::Changed(mk_pending(
752 obligation,
753 new_obligations.into_obligations(),
754 ));
755 }
756 }
757 }
758 }
759
760 let stalled_on = &mut pending_obligation.stalled_on;
761
762 let mut evaluate = |c: Const<'tcx>| {
763 if let ty::ConstKind::Alias(_, alias_const) = c.kind() {
764 match super::try_evaluate_const(
765 self.selcx.infcx,
766 c,
767 obligation.param_env,
768 |ty| Ok::<_, !>(ty.skip_norm_wip()),
769 ) {
770 Ok(val) => Ok(val),
771 e @ Err(EvaluateConstErr::HasGenericsOrInfers) => {
772 stalled_on.extend(alias_const.args.iter().filter_map(
773 TyOrConstInferVar::maybe_from_generic_arg::<TyCtxt<'tcx>>,
774 ));
775 e
776 }
777 e @ Err(
778 EvaluateConstErr::EvaluationFailure(_)
779 | EvaluateConstErr::InvalidConstParamTy(_),
780 ) => e,
781 }
782 } else {
783 Ok(c)
784 }
785 };
786
787 match (evaluate(c1), evaluate(c2)) {
788 (Ok(c1), Ok(c2)) => {
789 match self.selcx.infcx.at(&obligation.cause, obligation.param_env).eq(
790 DefineOpaqueTypes::Yes,
793 c1,
794 c2,
795 ) {
796 Ok(inf_ok) => ProcessResult::Changed(mk_pending(
797 obligation,
798 inf_ok.into_obligations(),
799 )),
800 Err(err) => {
801 ProcessResult::Error(FulfillmentErrorCode::ConstEquate(
802 ExpectedFound::new(c1, c2),
803 err,
804 ))
805 }
806 }
807 }
808 (Err(EvaluateConstErr::InvalidConstParamTy(e)), _)
809 | (_, Err(EvaluateConstErr::InvalidConstParamTy(e))) => {
810 ProcessResult::Error(FulfillmentErrorCode::Select(
811 SelectionError::NotConstEvaluatable(NotConstEvaluatable::Error(e)),
812 ))
813 }
814 (Err(EvaluateConstErr::EvaluationFailure(e)), _)
815 | (_, Err(EvaluateConstErr::EvaluationFailure(e))) => {
816 ProcessResult::Error(FulfillmentErrorCode::Select(
817 SelectionError::NotConstEvaluatable(NotConstEvaluatable::Error(e)),
818 ))
819 }
820 (Err(EvaluateConstErr::HasGenericsOrInfers), _)
821 | (_, Err(EvaluateConstErr::HasGenericsOrInfers)) => {
822 if c1.has_non_region_infer() || c2.has_non_region_infer() {
823 ProcessResult::Unchanged
824 } else {
825 let expected_found = ExpectedFound::new(c1, c2);
827 ProcessResult::Error(FulfillmentErrorCode::ConstEquate(
828 expected_found,
829 TypeError::ConstMismatch(expected_found),
830 ))
831 }
832 }
833 }
834 }
835 ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(symbol)) => {
836 if may_use_unstable_feature(self.selcx.infcx, obligation.param_env, symbol) {
837 ProcessResult::Changed(Default::default())
838 } else {
839 ProcessResult::Unchanged
840 }
841 }
842 },
843 }
844 }
845
846 #[inline(never)]
847 fn process_backedge<'c, I>(
848 &mut self,
849 cycle: I,
850 _marker: PhantomData<&'c PendingPredicateObligation<'tcx>>,
851 ) -> Result<(), FulfillmentErrorCode<'tcx>>
852 where
853 I: Clone + Iterator<Item = &'c PendingPredicateObligation<'tcx>>,
854 {
855 if self.selcx.coinductive_match(cycle.clone().map(|s| s.obligation.predicate)) {
856 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_trait_selection/src/traits/fulfill.rs:856",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(856u32),
::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");
857 Ok(())
858 } else {
859 let cycle = cycle.map(|c| c.obligation.clone()).collect();
860 Err(FulfillmentErrorCode::Cycle(cycle))
861 }
862 }
863}
864
865impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
866 {}
#[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/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(866u32),
::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/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_trait_selection/src/traits/fulfill.rs:878",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(878u32),
::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/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_trait_selection/src/traits/fulfill.rs:888",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(888u32),
::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/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_trait_selection/src/traits/fulfill.rs:892",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(892u32),
::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/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_trait_selection/src/traits/fulfill.rs:904",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(904u32),
::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.resolve_vars_if_possible(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/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_trait_selection/src/traits/fulfill.rs:913",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(913u32),
::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))]
867 fn process_trait_obligation(
868 &mut self,
869 obligation: &PredicateObligation<'tcx>,
870 trait_obligation: PolyTraitObligation<'tcx>,
871 stalled_on: &mut Vec<TyOrConstInferVar>,
872 ) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
873 let infcx = self.selcx.infcx;
874 if obligation.predicate.is_global() && !self.selcx.typing_mode().is_coherence() {
875 if infcx.predicate_must_hold_considering_regions(obligation) {
878 debug!(
879 "selecting trait at depth {} evaluated to holds",
880 obligation.recursion_depth
881 );
882 return ProcessResult::Changed(Default::default());
883 }
884 }
885
886 match self.selcx.poly_select(&trait_obligation) {
887 Ok(Some(impl_source)) => {
888 debug!("selecting trait at depth {} yielded Ok(Some)", obligation.recursion_depth);
889 ProcessResult::Changed(mk_pending(obligation, impl_source.nested_obligations()))
890 }
891 Ok(None) => {
892 debug!("selecting trait at depth {} yielded Ok(None)", obligation.recursion_depth);
893
894 stalled_on.clear();
899 stalled_on.extend(args_infer_vars(
900 &self.selcx,
901 trait_obligation.predicate.map_bound(|pred| pred.trait_ref.args),
902 ));
903
904 debug!(
905 "process_predicate: pending obligation {:?} now stalled on {:?}",
906 infcx.resolve_vars_if_possible(obligation.clone()),
907 stalled_on
908 );
909
910 ProcessResult::Unchanged
911 }
912 Err(selection_err) => {
913 debug!("selecting trait at depth {} yielded Err", obligation.recursion_depth);
914
915 ProcessResult::Error(FulfillmentErrorCode::Select(selection_err))
916 }
917 }
918 }
919
920 fn process_projection_obligation(
921 &mut self,
922 obligation: &PredicateObligation<'tcx>,
923 project_obligation: PolyProjectionObligation<'tcx>,
924 stalled_on: &mut Vec<TyOrConstInferVar>,
925 ) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
926 let tcx = self.selcx.tcx();
927 let infcx = self.selcx.infcx;
928 if obligation.predicate.is_global() && !self.selcx.typing_mode().is_coherence() {
929 if infcx.predicate_must_hold_considering_regions(obligation) {
932 if let Some(key) = ProjectionCacheKey::from_poly_projection_obligation(
933 &mut self.selcx,
934 &project_obligation,
935 ) {
936 infcx
940 .inner
941 .borrow_mut()
942 .projection_cache()
943 .complete(key, EvaluationResult::EvaluatedToOk);
944 }
945 return ProcessResult::Changed(Default::default());
946 } else {
947 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_trait_selection/src/traits/fulfill.rs:947",
"rustc_trait_selection::traits::fulfill",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_trait_selection/src/traits/fulfill.rs"),
::tracing_core::__macro_support::Option::Some(947u32),
::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);
948 }
949 }
950
951 match project::poly_project_and_unify_term(&mut self.selcx, &project_obligation) {
952 ProjectAndUnifyResult::Holds(os) if os.is_empty() => {
953 ProcessResult::Changed(mk_pending(obligation, os))
954 }
955 ProjectAndUnifyResult::Holds(os) => {
956 let input_projection_term = infcx
957 .resolve_vars_if_possible(project_obligation.predicate)
958 .map_bound(|p| p.projection_term);
959 let all_same_projection_term = os.iter().all(|o| {
960 let Some(proj_clause) = o.predicate.as_projection_clause() else {
961 return false;
962 };
963 infcx.resolve_vars_if_possible(proj_clause).map_bound(|p| p.projection_term)
964 == input_projection_term
965 });
966 if all_same_projection_term {
967 ProcessResult::Error(FulfillmentErrorCode::Ambiguity { overflow: None })
977 } else {
978 ProcessResult::Changed(mk_pending(obligation, os))
979 }
980 }
981 ProjectAndUnifyResult::FailedNormalization => {
982 stalled_on.clear();
983 stalled_on.extend(args_infer_vars(
984 &self.selcx,
985 project_obligation.predicate.map_bound(|pred| pred.projection_term.args),
986 ));
987 ProcessResult::Unchanged
988 }
989 ProjectAndUnifyResult::Recursive => {
991 let mut obligations = PredicateObligations::with_capacity(1);
992 obligations.push(project_obligation.with(tcx, project_obligation.predicate));
993
994 ProcessResult::Changed(mk_pending(obligation, obligations))
995 }
996 ProjectAndUnifyResult::MismatchedProjectionTypes(e) => {
997 ProcessResult::Error(FulfillmentErrorCode::Project(e))
998 }
999 }
1000 }
1001
1002 fn process_host_obligation(
1003 &mut self,
1004 obligation: &PredicateObligation<'tcx>,
1005 host_obligation: HostEffectObligation<'tcx>,
1006 stalled_on: &mut Vec<TyOrConstInferVar>,
1007 ) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
1008 match effects::evaluate_host_effect_obligation(&mut self.selcx, &host_obligation) {
1009 Ok(nested) => ProcessResult::Changed(mk_pending(obligation, nested)),
1010 Err(effects::EvaluationFailure::Ambiguous) => {
1011 stalled_on.clear();
1012 stalled_on.extend(args_infer_vars(
1013 &self.selcx,
1014 ty::Binder::dummy(host_obligation.predicate.trait_ref.args),
1015 ));
1016 ProcessResult::Unchanged
1017 }
1018 Err(effects::EvaluationFailure::NoSolution) => {
1019 ProcessResult::Error(FulfillmentErrorCode::Select(SelectionError::Unimplemented))
1020 }
1021 }
1022 }
1023}
1024
1025fn args_infer_vars<'tcx>(
1027 selcx: &SelectionContext<'_, 'tcx>,
1028 args: ty::Binder<'tcx, GenericArgsRef<'tcx>>,
1029) -> impl Iterator<Item = TyOrConstInferVar> {
1030 selcx
1031 .infcx
1032 .resolve_vars_if_possible(args)
1033 .skip_binder() .iter()
1035 .filter(|arg| arg.has_non_region_infer())
1036 .flat_map(|arg| {
1037 let mut walker = arg.walk();
1038 while let Some(c) = walker.next() {
1039 if !c.has_non_region_infer() {
1040 walker.visited.remove(&c);
1041 walker.skip_current_subtree();
1042 }
1043 }
1044 walker.visited.into_iter()
1045 })
1046 .filter_map(TyOrConstInferVar::maybe_from_generic_arg::<TyCtxt<'tcx>>)
1047}
1048
1049#[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)]
1050pub struct OldSolverError<'tcx>(
1051 Error<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>>,
1052);
1053
1054impl<'tcx> FromSolverError<'tcx, OldSolverError<'tcx>> for FulfillmentError<'tcx> {
1055 fn from_solver_error(_infcx: &InferCtxt<'tcx>, error: OldSolverError<'tcx>) -> Self {
1056 let mut iter = error.0.backtrace.into_iter();
1057 let obligation = iter.next().unwrap().obligation;
1058 let root_obligation = iter.next_back().map_or_else(|| obligation.clone(), |e| e.obligation);
1061 FulfillmentError::new(obligation, error.0.error, root_obligation)
1062 }
1063}
1064
1065impl<'tcx> FromSolverError<'tcx, OldSolverError<'tcx>> for ScrubbedTraitError<'tcx> {
1066 fn from_solver_error(_infcx: &InferCtxt<'tcx>, error: OldSolverError<'tcx>) -> Self {
1067 match error.0.error {
1068 FulfillmentErrorCode::Select(_)
1069 | FulfillmentErrorCode::Project(_)
1070 | FulfillmentErrorCode::Outlives
1071 | FulfillmentErrorCode::Subtype(_, _)
1072 | FulfillmentErrorCode::ConstEquate(_, _) => ScrubbedTraitError::TrueError,
1073 FulfillmentErrorCode::Ambiguity { overflow: _ } => ScrubbedTraitError::Ambiguity,
1074 FulfillmentErrorCode::Cycle(cycle) => ScrubbedTraitError::Cycle(cycle),
1075 }
1076 }
1077}