1pub(super) mod structural_traits;
4
5use std::cell::Cell;
6use std::ops::ControlFlow;
7
8use derive_where::derive_where;
9use rustc_type_ir::inherent::*;
10use rustc_type_ir::lang_items::SolverTraitLangItem;
11use rustc_type_ir::search_graph::CandidateHeadUsages;
12use rustc_type_ir::solve::{
13 AliasBoundKind, MaybeInfo, NoSolutionOrOpaquesAccessed, RerunReason, SizedTraitKind,
14 StalledOnCoroutines,
15};
16use rustc_type_ir::{
17 self as ty, AliasTy, Interner, MayBeErased, TypeFlags, TypeFoldable, TypeFolder,
18 TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
19 TypingMode, Unnormalized, Upcast, elaborate,
20};
21use tracing::{debug, instrument};
22
23use super::trait_goals::TraitGoalProvenVia;
24use super::{has_only_region_constraints, inspect};
25use crate::delegate::SolverDelegate;
26use crate::solve::inspect::ProbeKind;
27use crate::solve::{
28 BuiltinImplSource, CandidateSource, CanonicalResponse, Certainty, EvalCtxt, Goal, GoalSource,
29 MaybeCause, NoSolution, OpaqueTypesJank, ParamEnvSource, QueryResult,
30 has_no_inference_or_external_constraints,
31};
32
33#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for Candidate<I> where I: Interner {
fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
-> ::core::fmt::Result {
match self {
Candidate {
source: ref __field_source,
result: ref __field_result,
head_usages: ref __field_head_usages } => {
let mut __builder =
::core::fmt::Formatter::debug_struct(__f, "Candidate");
::core::fmt::DebugStruct::field(&mut __builder, "source",
__field_source);
::core::fmt::DebugStruct::field(&mut __builder, "result",
__field_result);
::core::fmt::DebugStruct::field(&mut __builder, "head_usages",
__field_head_usages);
::core::fmt::DebugStruct::finish(&mut __builder)
}
}
}
}#[derive_where(Debug; I: Interner)]
38pub(super) struct Candidate<I: Interner> {
39 pub(super) source: CandidateSource<I>,
40 pub(super) result: CanonicalResponse<I>,
41 pub(super) head_usages: CandidateHeadUsages,
42}
43
44pub(super) trait GoalKind<D, I = <D as SolverDelegate>::Interner>:
46 TypeFoldable<I> + Copy + Eq + std::fmt::Display
47where
48 D: SolverDelegate<Interner = I>,
49 I: Interner,
50{
51 fn self_ty(self) -> I::Ty;
52
53 fn trait_ref(self, cx: I) -> ty::TraitRef<I>;
54
55 fn with_replaced_self_ty(self, cx: I, self_ty: I::Ty) -> Self;
56
57 fn trait_def_id(self, cx: I) -> I::TraitId;
58
59 fn probe_and_consider_implied_clause(
63 ecx: &mut EvalCtxt<'_, D>,
64 parent_source: CandidateSource<I>,
65 goal: Goal<I, Self>,
66 assumption: I::Clause,
67 requirements: impl IntoIterator<Item = (GoalSource, Goal<I, I::Predicate>)>,
68 ) -> Result<Candidate<I>, NoSolution> {
69 Self::probe_and_match_goal_against_assumption(ecx, parent_source, goal, assumption, |ecx| {
70 for (nested_source, goal) in requirements {
71 ecx.add_goal(nested_source, goal);
72 }
73 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
74 })
75 }
76
77 fn probe_and_consider_object_bound_candidate(
83 ecx: &mut EvalCtxt<'_, D>,
84 source: CandidateSource<I>,
85 goal: Goal<I, Self>,
86 assumption: I::Clause,
87 ) -> Result<Candidate<I>, NoSolution> {
88 Self::probe_and_match_goal_against_assumption(ecx, source, goal, assumption, |ecx| {
89 let cx = ecx.cx();
90 let ty::Dynamic(bounds, _) = goal.predicate.self_ty().kind() else {
91 {
::core::panicking::panic_fmt(format_args!("expected object type in `probe_and_consider_object_bound_candidate`"));
};panic!("expected object type in `probe_and_consider_object_bound_candidate`");
92 };
93
94 let trait_ref = assumption.kind().map_bound(|clause| match clause {
95 ty::ClauseKind::Trait(pred) => pred.trait_ref,
96 ty::ClauseKind::Projection(proj) => proj.projection_term.trait_ref(cx),
97
98 ty::ClauseKind::RegionOutlives(..)
99 | ty::ClauseKind::TypeOutlives(..)
100 | ty::ClauseKind::ConstArgHasType(..)
101 | ty::ClauseKind::WellFormed(..)
102 | ty::ClauseKind::ConstEvaluatable(..)
103 | ty::ClauseKind::HostEffect(..)
104 | ty::ClauseKind::UnstableFeature(..) => {
105 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("expected trait or projection predicate as an assumption")));
}unreachable!("expected trait or projection predicate as an assumption")
106 }
107 });
108
109 match structural_traits::predicates_for_object_candidate(
110 ecx,
111 goal.param_env,
112 trait_ref,
113 bounds,
114 ) {
115 Ok(requirements) => {
116 ecx.add_goals(GoalSource::ImplWhereBound, requirements);
117 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
118 }
119 Err(_) => {
120 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
121 }
122 }
123 })
124 }
125
126 fn consider_additional_alias_assumptions(
130 ecx: &mut EvalCtxt<'_, D>,
131 goal: Goal<I, Self>,
132 alias_ty: ty::AliasTy<I>,
133 ) -> Vec<Candidate<I>>;
134
135 fn probe_and_consider_param_env_candidate(
136 ecx: &mut EvalCtxt<'_, D>,
137 goal: Goal<I, Self>,
138 assumption: I::Clause,
139 ) -> Result<Candidate<I>, CandidateHeadUsages> {
140 match Self::fast_reject_assumption(ecx, goal, assumption) {
141 Ok(()) => {}
142 Err(NoSolution) => return Err(CandidateHeadUsages::default()),
143 }
144
145 let source = Cell::new(CandidateSource::ParamEnv(ParamEnvSource::Global));
152 let (result, head_usages) = ecx
153 .probe(|result: &QueryResult<I>| inspect::ProbeKind::TraitCandidate {
154 source: source.get(),
155 result: *result,
156 })
157 .enter_single_candidate(|ecx| {
158 Self::match_assumption(ecx, goal, assumption, |ecx| {
159 ecx.try_evaluate_added_goals()?;
160 let (src, certainty) =
161 ecx.characterize_param_env_assumption(goal.param_env, assumption)?;
162 source.set(src);
163 ecx.evaluate_added_goals_and_make_canonical_response(certainty)
164 })
165 });
166
167 match result.map_err(Into::into) {
168 Ok(result) => Ok(Candidate { source: source.get(), result, head_usages }),
169 Err(NoSolution) => Err(head_usages),
170 }
171 }
172
173 fn probe_and_match_goal_against_assumption(
178 ecx: &mut EvalCtxt<'_, D>,
179 source: CandidateSource<I>,
180 goal: Goal<I, Self>,
181 assumption: I::Clause,
182 then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResult<I>,
183 ) -> Result<Candidate<I>, NoSolution> {
184 Self::fast_reject_assumption(ecx, goal, assumption)?;
185
186 ecx.probe_trait_candidate(source)
187 .enter(|ecx| Self::match_assumption(ecx, goal, assumption, then))
188 }
189
190 fn fast_reject_assumption(
193 ecx: &mut EvalCtxt<'_, D>,
194 goal: Goal<I, Self>,
195 assumption: I::Clause,
196 ) -> Result<(), NoSolution>;
197
198 fn match_assumption(
200 ecx: &mut EvalCtxt<'_, D>,
201 goal: Goal<I, Self>,
202 assumption: I::Clause,
203 then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResult<I>,
204 ) -> QueryResult<I>;
205
206 fn consider_impl_candidate(
207 ecx: &mut EvalCtxt<'_, D>,
208 goal: Goal<I, Self>,
209 impl_def_id: I::ImplId,
210 then: impl FnOnce(&mut EvalCtxt<'_, D>, Certainty) -> QueryResult<I>,
211 ) -> Result<Candidate<I>, NoSolution>;
212
213 fn consider_error_guaranteed_candidate(
220 ecx: &mut EvalCtxt<'_, D>,
221 guar: I::ErrorGuaranteed,
222 ) -> Result<Candidate<I>, NoSolution>;
223
224 fn consider_auto_trait_candidate(
229 ecx: &mut EvalCtxt<'_, D>,
230 goal: Goal<I, Self>,
231 ) -> Result<Candidate<I>, NoSolution>;
232
233 fn consider_trait_alias_candidate(
235 ecx: &mut EvalCtxt<'_, D>,
236 goal: Goal<I, Self>,
237 ) -> Result<Candidate<I>, NoSolution>;
238
239 fn consider_builtin_sizedness_candidates(
245 ecx: &mut EvalCtxt<'_, D>,
246 goal: Goal<I, Self>,
247 sizedness: SizedTraitKind,
248 ) -> Result<Candidate<I>, NoSolution>;
249
250 fn consider_builtin_copy_clone_candidate(
255 ecx: &mut EvalCtxt<'_, D>,
256 goal: Goal<I, Self>,
257 ) -> Result<Candidate<I>, NoSolution>;
258
259 fn consider_builtin_fn_ptr_trait_candidate(
261 ecx: &mut EvalCtxt<'_, D>,
262 goal: Goal<I, Self>,
263 ) -> Result<Candidate<I>, NoSolution>;
264
265 fn consider_builtin_fn_trait_candidates(
268 ecx: &mut EvalCtxt<'_, D>,
269 goal: Goal<I, Self>,
270 kind: ty::ClosureKind,
271 ) -> Result<Candidate<I>, NoSolution>;
272
273 fn consider_builtin_async_fn_trait_candidates(
276 ecx: &mut EvalCtxt<'_, D>,
277 goal: Goal<I, Self>,
278 kind: ty::ClosureKind,
279 ) -> Result<Candidate<I>, NoSolution>;
280
281 fn consider_builtin_async_fn_kind_helper_candidate(
285 ecx: &mut EvalCtxt<'_, D>,
286 goal: Goal<I, Self>,
287 ) -> Result<Candidate<I>, NoSolution>;
288
289 fn consider_builtin_tuple_candidate(
291 ecx: &mut EvalCtxt<'_, D>,
292 goal: Goal<I, Self>,
293 ) -> Result<Candidate<I>, NoSolution>;
294
295 fn consider_builtin_pointee_candidate(
301 ecx: &mut EvalCtxt<'_, D>,
302 goal: Goal<I, Self>,
303 ) -> Result<Candidate<I>, NoSolution>;
304
305 fn consider_builtin_future_candidate(
309 ecx: &mut EvalCtxt<'_, D>,
310 goal: Goal<I, Self>,
311 ) -> Result<Candidate<I>, NoSolution>;
312
313 fn consider_builtin_iterator_candidate(
317 ecx: &mut EvalCtxt<'_, D>,
318 goal: Goal<I, Self>,
319 ) -> Result<Candidate<I>, NoSolution>;
320
321 fn consider_builtin_fused_iterator_candidate(
324 ecx: &mut EvalCtxt<'_, D>,
325 goal: Goal<I, Self>,
326 ) -> Result<Candidate<I>, NoSolution>;
327
328 fn consider_builtin_async_iterator_candidate(
329 ecx: &mut EvalCtxt<'_, D>,
330 goal: Goal<I, Self>,
331 ) -> Result<Candidate<I>, NoSolution>;
332
333 fn consider_builtin_coroutine_candidate(
337 ecx: &mut EvalCtxt<'_, D>,
338 goal: Goal<I, Self>,
339 ) -> Result<Candidate<I>, NoSolution>;
340
341 fn consider_builtin_discriminant_kind_candidate(
342 ecx: &mut EvalCtxt<'_, D>,
343 goal: Goal<I, Self>,
344 ) -> Result<Candidate<I>, NoSolution>;
345
346 fn consider_builtin_destruct_candidate(
347 ecx: &mut EvalCtxt<'_, D>,
348 goal: Goal<I, Self>,
349 ) -> Result<Candidate<I>, NoSolution>;
350
351 fn consider_builtin_transmute_candidate(
352 ecx: &mut EvalCtxt<'_, D>,
353 goal: Goal<I, Self>,
354 ) -> Result<Candidate<I>, NoSolution>;
355
356 fn consider_builtin_bikeshed_guaranteed_no_drop_candidate(
357 ecx: &mut EvalCtxt<'_, D>,
358 goal: Goal<I, Self>,
359 ) -> Result<Candidate<I>, NoSolution>;
360
361 fn consider_structural_builtin_unsize_candidates(
369 ecx: &mut EvalCtxt<'_, D>,
370 goal: Goal<I, Self>,
371 ) -> Vec<Candidate<I>>;
372
373 fn consider_builtin_field_candidate(
374 ecx: &mut EvalCtxt<'_, D>,
375 goal: Goal<I, Self>,
376 ) -> Result<Candidate<I>, NoSolution>;
377}
378
379pub(super) enum AssembleCandidatesFrom {
387 All,
388 EnvAndBounds,
392}
393
394impl AssembleCandidatesFrom {
395 fn should_assemble_impl_candidates(&self) -> bool {
396 match self {
397 AssembleCandidatesFrom::All => true,
398 AssembleCandidatesFrom::EnvAndBounds => false,
399 }
400 }
401}
402
403#[derive(#[automatically_derived]
impl ::core::fmt::Debug for FailedCandidateInfo {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f,
"FailedCandidateInfo", "param_env_head_usages",
&&self.param_env_head_usages)
}
}Debug)]
412pub(super) struct FailedCandidateInfo {
413 pub param_env_head_usages: CandidateHeadUsages,
414}
415
416impl<D, I> EvalCtxt<'_, D>
417where
418 D: SolverDelegate<Interner = I>,
419 I: Interner,
420{
421 pub(super) fn assemble_and_evaluate_candidates<G: GoalKind<D>>(
425 &mut self,
426 goal: Goal<I, G>,
427 assemble_from: AssembleCandidatesFrom,
428 ) -> (Vec<Candidate<I>>, FailedCandidateInfo) {
429 let mut candidates = ::alloc::vec::Vec::new()vec![];
430 let mut failed_candidate_info =
431 FailedCandidateInfo { param_env_head_usages: CandidateHeadUsages::default() };
432 let Ok(normalized_self_ty) =
433 self.structurally_normalize_ty(goal.param_env, goal.predicate.self_ty())
434 else {
435 return (candidates, failed_candidate_info);
436 };
437
438 let goal: Goal<I, G> = goal
439 .with(self.cx(), goal.predicate.with_replaced_self_ty(self.cx(), normalized_self_ty));
440
441 if normalized_self_ty.is_ty_var() {
442 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs:442",
"rustc_next_trait_solver::solve::assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs"),
::tracing_core::__macro_support::Option::Some(442u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::assembly"),
::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!("self type has been normalized to infer")
as &dyn Value))])
});
} else { ; }
};debug!("self type has been normalized to infer");
443 self.try_assemble_bounds_via_registered_opaques(goal, assemble_from, &mut candidates);
444 return (candidates, failed_candidate_info);
445 }
446
447 let goal = self.resolve_vars_if_possible(goal);
450
451 if self.typing_mode().is_coherence()
452 && let Ok(candidate) = self.consider_coherence_unknowable_candidate(goal)
453 {
454 candidates.push(candidate);
455 return (candidates, failed_candidate_info);
456 }
457
458 self.assemble_alias_bound_candidates(goal, &mut candidates);
459 self.assemble_param_env_candidates(goal, &mut candidates, &mut failed_candidate_info);
460
461 match assemble_from {
462 AssembleCandidatesFrom::All => {
463 self.assemble_builtin_impl_candidates(goal, &mut candidates);
464 let assemble_impls = match self.typing_mode() {
476 TypingMode::Coherence => true,
477 TypingMode::Analysis { .. }
478 | TypingMode::Borrowck { .. }
479 | TypingMode::PostBorrowckAnalysis { .. }
480 | TypingMode::PostAnalysis
481 | TypingMode::ErasedNotCoherence(MayBeErased) => !candidates.iter().any(|c| {
482 #[allow(non_exhaustive_omitted_patterns)] match c.source {
CandidateSource::ParamEnv(ParamEnvSource::NonGlobal) |
CandidateSource::AliasBound(_) => true,
_ => false,
}matches!(
483 c.source,
484 CandidateSource::ParamEnv(ParamEnvSource::NonGlobal)
485 | CandidateSource::AliasBound(_)
486 ) && has_no_inference_or_external_constraints(c.result)
487 }),
488 };
489 if assemble_impls {
490 self.assemble_impl_candidates(goal, &mut candidates);
491 self.assemble_object_bound_candidates(goal, &mut candidates);
492 }
493 }
494 AssembleCandidatesFrom::EnvAndBounds => {
495 if #[allow(non_exhaustive_omitted_patterns)] match normalized_self_ty.kind() {
ty::Dynamic(..) => true,
_ => false,
}matches!(normalized_self_ty.kind(), ty::Dynamic(..))
499 && !candidates.iter().any(|c| #[allow(non_exhaustive_omitted_patterns)] match c.source {
CandidateSource::ParamEnv(_) => true,
_ => false,
}matches!(c.source, CandidateSource::ParamEnv(_)))
500 {
501 self.assemble_object_bound_candidates(goal, &mut candidates);
502 }
503 }
504 }
505
506 (candidates, failed_candidate_info)
507 }
508
509 pub(super) fn forced_ambiguity(
510 &mut self,
511 maybe: MaybeInfo,
512 ) -> Result<Candidate<I>, NoSolution> {
513 let source = CandidateSource::BuiltinImpl(BuiltinImplSource::Misc);
522 let certainty = Certainty::Maybe(maybe);
523 self.probe_trait_candidate(source)
524 .enter(|this| this.evaluate_added_goals_and_make_canonical_response(certainty))
525 }
526
527 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::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("assemble_impl_candidates",
"rustc_next_trait_solver::solve::assembly",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs"),
::tracing_core::__macro_support::Option::Some(527u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::assembly"),
::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::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::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: () = loop {};
return __tracing_attr_fake_return;
}
{
let cx = self.cx();
cx.for_each_relevant_impl(goal.predicate.trait_def_id(cx),
goal.predicate.self_ty(),
|impl_def_id|
{
if cx.impl_is_default(impl_def_id) { return; }
match G::consider_impl_candidate(self, goal, impl_def_id,
|ecx, certainty|
{
ecx.evaluate_added_goals_and_make_canonical_response(certainty)
}) {
Ok(candidate) => candidates.push(candidate),
Err(NoSolution) => (),
}
});
}
}
}#[instrument(level = "trace", skip_all)]
528 fn assemble_impl_candidates<G: GoalKind<D>>(
529 &mut self,
530 goal: Goal<I, G>,
531 candidates: &mut Vec<Candidate<I>>,
532 ) {
533 let cx = self.cx();
534 cx.for_each_relevant_impl(
535 goal.predicate.trait_def_id(cx),
536 goal.predicate.self_ty(),
537 |impl_def_id| {
538 if cx.impl_is_default(impl_def_id) {
542 return;
543 }
544 match G::consider_impl_candidate(self, goal, impl_def_id, |ecx, certainty| {
545 ecx.evaluate_added_goals_and_make_canonical_response(certainty)
546 }) {
547 Ok(candidate) => candidates.push(candidate),
548 Err(NoSolution) => (),
549 }
550 },
551 );
552 }
553
554 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::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("assemble_builtin_impl_candidates",
"rustc_next_trait_solver::solve::assembly",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs"),
::tracing_core::__macro_support::Option::Some(554u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::assembly"),
::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::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::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: () = loop {};
return __tracing_attr_fake_return;
}
{
let cx = self.cx();
let trait_def_id = goal.predicate.trait_def_id(cx);
let result =
if let Err(guar) = goal.predicate.error_reported() {
G::consider_error_guaranteed_candidate(self, guar)
} else if cx.trait_is_auto(trait_def_id) {
G::consider_auto_trait_candidate(self, goal)
} else if cx.trait_is_alias(trait_def_id) {
G::consider_trait_alias_candidate(self, goal)
} else {
match cx.as_trait_lang_item(trait_def_id) {
Some(SolverTraitLangItem::Sized) => {
G::consider_builtin_sizedness_candidates(self, goal,
SizedTraitKind::Sized)
}
Some(SolverTraitLangItem::MetaSized) => {
G::consider_builtin_sizedness_candidates(self, goal,
SizedTraitKind::MetaSized)
}
Some(SolverTraitLangItem::PointeeSized) => {
{
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("`PointeeSized` is removed during lowering")));
};
}
Some(SolverTraitLangItem::Copy | SolverTraitLangItem::Clone
| SolverTraitLangItem::TrivialClone) =>
G::consider_builtin_copy_clone_candidate(self, goal),
Some(SolverTraitLangItem::Fn) => {
G::consider_builtin_fn_trait_candidates(self, goal,
ty::ClosureKind::Fn)
}
Some(SolverTraitLangItem::FnMut) => {
G::consider_builtin_fn_trait_candidates(self, goal,
ty::ClosureKind::FnMut)
}
Some(SolverTraitLangItem::FnOnce) => {
G::consider_builtin_fn_trait_candidates(self, goal,
ty::ClosureKind::FnOnce)
}
Some(SolverTraitLangItem::AsyncFn) => {
G::consider_builtin_async_fn_trait_candidates(self, goal,
ty::ClosureKind::Fn)
}
Some(SolverTraitLangItem::AsyncFnMut) => {
G::consider_builtin_async_fn_trait_candidates(self, goal,
ty::ClosureKind::FnMut)
}
Some(SolverTraitLangItem::AsyncFnOnce) => {
G::consider_builtin_async_fn_trait_candidates(self, goal,
ty::ClosureKind::FnOnce)
}
Some(SolverTraitLangItem::FnPtrTrait) => {
G::consider_builtin_fn_ptr_trait_candidate(self, goal)
}
Some(SolverTraitLangItem::AsyncFnKindHelper) => {
G::consider_builtin_async_fn_kind_helper_candidate(self,
goal)
}
Some(SolverTraitLangItem::Tuple) =>
G::consider_builtin_tuple_candidate(self, goal),
Some(SolverTraitLangItem::PointeeTrait) => {
G::consider_builtin_pointee_candidate(self, goal)
}
Some(SolverTraitLangItem::Future) => {
G::consider_builtin_future_candidate(self, goal)
}
Some(SolverTraitLangItem::Iterator) => {
G::consider_builtin_iterator_candidate(self, goal)
}
Some(SolverTraitLangItem::FusedIterator) => {
G::consider_builtin_fused_iterator_candidate(self, goal)
}
Some(SolverTraitLangItem::AsyncIterator) => {
G::consider_builtin_async_iterator_candidate(self, goal)
}
Some(SolverTraitLangItem::Coroutine) => {
G::consider_builtin_coroutine_candidate(self, goal)
}
Some(SolverTraitLangItem::DiscriminantKind) => {
G::consider_builtin_discriminant_kind_candidate(self, goal)
}
Some(SolverTraitLangItem::Destruct) => {
G::consider_builtin_destruct_candidate(self, goal)
}
Some(SolverTraitLangItem::TransmuteTrait) => {
G::consider_builtin_transmute_candidate(self, goal)
}
Some(SolverTraitLangItem::BikeshedGuaranteedNoDrop) => {
G::consider_builtin_bikeshed_guaranteed_no_drop_candidate(self,
goal)
}
Some(SolverTraitLangItem::Field) =>
G::consider_builtin_field_candidate(self, goal),
_ => Err(NoSolution),
}
};
candidates.extend(result);
if cx.is_trait_lang_item(trait_def_id,
SolverTraitLangItem::Unsize) {
candidates.extend(G::consider_structural_builtin_unsize_candidates(self,
goal));
}
}
}
}#[instrument(level = "trace", skip_all)]
555 fn assemble_builtin_impl_candidates<G: GoalKind<D>>(
556 &mut self,
557 goal: Goal<I, G>,
558 candidates: &mut Vec<Candidate<I>>,
559 ) {
560 let cx = self.cx();
561 let trait_def_id = goal.predicate.trait_def_id(cx);
562
563 let result = if let Err(guar) = goal.predicate.error_reported() {
571 G::consider_error_guaranteed_candidate(self, guar)
572 } else if cx.trait_is_auto(trait_def_id) {
573 G::consider_auto_trait_candidate(self, goal)
574 } else if cx.trait_is_alias(trait_def_id) {
575 G::consider_trait_alias_candidate(self, goal)
576 } else {
577 match cx.as_trait_lang_item(trait_def_id) {
578 Some(SolverTraitLangItem::Sized) => {
579 G::consider_builtin_sizedness_candidates(self, goal, SizedTraitKind::Sized)
580 }
581 Some(SolverTraitLangItem::MetaSized) => {
582 G::consider_builtin_sizedness_candidates(self, goal, SizedTraitKind::MetaSized)
583 }
584 Some(SolverTraitLangItem::PointeeSized) => {
585 unreachable!("`PointeeSized` is removed during lowering");
586 }
587 Some(
588 SolverTraitLangItem::Copy
589 | SolverTraitLangItem::Clone
590 | SolverTraitLangItem::TrivialClone,
591 ) => G::consider_builtin_copy_clone_candidate(self, goal),
592 Some(SolverTraitLangItem::Fn) => {
593 G::consider_builtin_fn_trait_candidates(self, goal, ty::ClosureKind::Fn)
594 }
595 Some(SolverTraitLangItem::FnMut) => {
596 G::consider_builtin_fn_trait_candidates(self, goal, ty::ClosureKind::FnMut)
597 }
598 Some(SolverTraitLangItem::FnOnce) => {
599 G::consider_builtin_fn_trait_candidates(self, goal, ty::ClosureKind::FnOnce)
600 }
601 Some(SolverTraitLangItem::AsyncFn) => {
602 G::consider_builtin_async_fn_trait_candidates(self, goal, ty::ClosureKind::Fn)
603 }
604 Some(SolverTraitLangItem::AsyncFnMut) => {
605 G::consider_builtin_async_fn_trait_candidates(
606 self,
607 goal,
608 ty::ClosureKind::FnMut,
609 )
610 }
611 Some(SolverTraitLangItem::AsyncFnOnce) => {
612 G::consider_builtin_async_fn_trait_candidates(
613 self,
614 goal,
615 ty::ClosureKind::FnOnce,
616 )
617 }
618 Some(SolverTraitLangItem::FnPtrTrait) => {
619 G::consider_builtin_fn_ptr_trait_candidate(self, goal)
620 }
621 Some(SolverTraitLangItem::AsyncFnKindHelper) => {
622 G::consider_builtin_async_fn_kind_helper_candidate(self, goal)
623 }
624 Some(SolverTraitLangItem::Tuple) => G::consider_builtin_tuple_candidate(self, goal),
625 Some(SolverTraitLangItem::PointeeTrait) => {
626 G::consider_builtin_pointee_candidate(self, goal)
627 }
628 Some(SolverTraitLangItem::Future) => {
629 G::consider_builtin_future_candidate(self, goal)
630 }
631 Some(SolverTraitLangItem::Iterator) => {
632 G::consider_builtin_iterator_candidate(self, goal)
633 }
634 Some(SolverTraitLangItem::FusedIterator) => {
635 G::consider_builtin_fused_iterator_candidate(self, goal)
636 }
637 Some(SolverTraitLangItem::AsyncIterator) => {
638 G::consider_builtin_async_iterator_candidate(self, goal)
639 }
640 Some(SolverTraitLangItem::Coroutine) => {
641 G::consider_builtin_coroutine_candidate(self, goal)
642 }
643 Some(SolverTraitLangItem::DiscriminantKind) => {
644 G::consider_builtin_discriminant_kind_candidate(self, goal)
645 }
646 Some(SolverTraitLangItem::Destruct) => {
647 G::consider_builtin_destruct_candidate(self, goal)
648 }
649 Some(SolverTraitLangItem::TransmuteTrait) => {
650 G::consider_builtin_transmute_candidate(self, goal)
651 }
652 Some(SolverTraitLangItem::BikeshedGuaranteedNoDrop) => {
653 G::consider_builtin_bikeshed_guaranteed_no_drop_candidate(self, goal)
654 }
655 Some(SolverTraitLangItem::Field) => G::consider_builtin_field_candidate(self, goal),
656 _ => Err(NoSolution),
657 }
658 };
659
660 candidates.extend(result);
661
662 if cx.is_trait_lang_item(trait_def_id, SolverTraitLangItem::Unsize) {
665 candidates.extend(G::consider_structural_builtin_unsize_candidates(self, goal));
666 }
667 }
668
669 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::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("assemble_param_env_candidates",
"rustc_next_trait_solver::solve::assembly",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs"),
::tracing_core::__macro_support::Option::Some(669u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::assembly"),
::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::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::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: () = loop {};
return __tracing_attr_fake_return;
}
{
for assumption in goal.param_env.caller_bounds().iter() {
match G::probe_and_consider_param_env_candidate(self, goal,
assumption) {
Ok(candidate) => candidates.push(candidate),
Err(head_usages) => {
failed_candidate_info.param_env_head_usages.merge_usages(head_usages)
}
}
}
}
}
}#[instrument(level = "trace", skip_all)]
670 fn assemble_param_env_candidates<G: GoalKind<D>>(
671 &mut self,
672 goal: Goal<I, G>,
673 candidates: &mut Vec<Candidate<I>>,
674 failed_candidate_info: &mut FailedCandidateInfo,
675 ) {
676 for assumption in goal.param_env.caller_bounds().iter() {
677 match G::probe_and_consider_param_env_candidate(self, goal, assumption) {
678 Ok(candidate) => candidates.push(candidate),
679 Err(head_usages) => {
680 failed_candidate_info.param_env_head_usages.merge_usages(head_usages)
681 }
682 }
683 }
684 }
685
686 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::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("assemble_alias_bound_candidates",
"rustc_next_trait_solver::solve::assembly",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs"),
::tracing_core::__macro_support::Option::Some(686u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::assembly"),
::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::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::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: () = loop {};
return __tracing_attr_fake_return;
}
{
let res =
self.probe(|_|
ProbeKind::NormalizedSelfTyAssembly).enter(|ecx|
{
ecx.assemble_alias_bound_candidates_recur(goal.predicate.self_ty(),
goal, candidates, AliasBoundKind::SelfBounds);
Ok(())
});
match res {
Ok(_) | Err(NoSolutionOrOpaquesAccessed::OpaquesAccessed) =>
{}
Err(NoSolutionOrOpaquesAccessed::NoSolution(NoSolution)) => {
::core::panicking::panic("internal error: entered unreachable code")
}
}
}
}
}#[instrument(level = "trace", skip_all)]
687 fn assemble_alias_bound_candidates<G: GoalKind<D>>(
688 &mut self,
689 goal: Goal<I, G>,
690 candidates: &mut Vec<Candidate<I>>,
691 ) {
692 let res = self.probe(|_| ProbeKind::NormalizedSelfTyAssembly).enter(|ecx| {
693 ecx.assemble_alias_bound_candidates_recur(
694 goal.predicate.self_ty(),
695 goal,
696 candidates,
697 AliasBoundKind::SelfBounds,
698 );
699 Ok(())
700 });
701
702 match res {
704 Ok(_) | Err(NoSolutionOrOpaquesAccessed::OpaquesAccessed) => {}
705 Err(NoSolutionOrOpaquesAccessed::NoSolution(NoSolution)) => {
706 unreachable!()
707 }
708 }
709 }
710
711 fn assemble_alias_bound_candidates_recur<G: GoalKind<D>>(
721 &mut self,
722 self_ty: I::Ty,
723 goal: Goal<I, G>,
724 candidates: &mut Vec<Candidate<I>>,
725 consider_self_bounds: AliasBoundKind,
726 ) {
727 let alias_ty = match self_ty.kind() {
728 ty::Bool
729 | ty::Char
730 | ty::Int(_)
731 | ty::Uint(_)
732 | ty::Float(_)
733 | ty::Adt(_, _)
734 | ty::Foreign(_)
735 | ty::Str
736 | ty::Array(_, _)
737 | ty::Pat(_, _)
738 | ty::Slice(_)
739 | ty::RawPtr(_, _)
740 | ty::Ref(_, _, _)
741 | ty::FnDef(_, _)
742 | ty::FnPtr(..)
743 | ty::UnsafeBinder(_)
744 | ty::Dynamic(..)
745 | ty::Closure(..)
746 | ty::CoroutineClosure(..)
747 | ty::Coroutine(..)
748 | ty::CoroutineWitness(..)
749 | ty::Never
750 | ty::Tuple(_)
751 | ty::Param(_)
752 | ty::Placeholder(..)
753 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
754 | ty::Error(_) => return,
755 ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) | ty::Bound(..) => {
756 {
::core::panicking::panic_fmt(format_args!("unexpected self type for `{0:?}`",
goal));
}panic!("unexpected self type for `{goal:?}`")
757 }
758
759 ty::Infer(ty::TyVar(_)) => {
760 if let Ok(result) =
764 self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
765 {
766 candidates.push(Candidate {
767 source: CandidateSource::AliasBound(consider_self_bounds),
768 result,
769 head_usages: CandidateHeadUsages::default(),
770 });
771 }
772 return;
773 }
774
775 ty::Alias(
776 alias_ty @ AliasTy { kind: ty::Projection { .. } | ty::Opaque { .. }, .. },
777 ) => alias_ty,
778 ty::Alias(AliasTy { kind: ty::Inherent { .. } | ty::Free { .. }, .. }) => {
779 self.cx().delay_bug(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("could not normalize {0:?}, it is not WF",
self_ty))
})format!("could not normalize {self_ty:?}, it is not WF"));
780 return;
781 }
782 };
783
784 match consider_self_bounds {
785 AliasBoundKind::SelfBounds => {
786 for assumption in self
787 .cx()
788 .item_self_bounds(alias_ty.kind.def_id())
789 .iter_instantiated(self.cx(), alias_ty.args)
790 .map(Unnormalized::skip_norm_wip)
791 {
792 candidates.extend(G::probe_and_consider_implied_clause(
793 self,
794 CandidateSource::AliasBound(consider_self_bounds),
795 goal,
796 assumption,
797 [],
798 ));
799 }
800 }
801 AliasBoundKind::NonSelfBounds => {
802 for assumption in self
803 .cx()
804 .item_non_self_bounds(alias_ty.kind.def_id())
805 .iter_instantiated(self.cx(), alias_ty.args)
806 .map(Unnormalized::skip_norm_wip)
807 {
808 candidates.extend(G::probe_and_consider_implied_clause(
809 self,
810 CandidateSource::AliasBound(consider_self_bounds),
811 goal,
812 assumption,
813 [],
814 ));
815 }
816 }
817 }
818
819 candidates.extend(G::consider_additional_alias_assumptions(self, goal, alias_ty));
820
821 if !#[allow(non_exhaustive_omitted_patterns)] match alias_ty.kind {
ty::Projection { .. } => true,
_ => false,
}matches!(alias_ty.kind, ty::Projection { .. }) {
822 return;
823 }
824
825 match self.structurally_normalize_ty(goal.param_env, alias_ty.self_ty()) {
827 Ok(next_self_ty) => self.assemble_alias_bound_candidates_recur(
828 next_self_ty,
829 goal,
830 candidates,
831 AliasBoundKind::NonSelfBounds,
832 ),
833 Err(NoSolution) => {}
834 }
835 }
836
837 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::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("assemble_object_bound_candidates",
"rustc_next_trait_solver::solve::assembly",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs"),
::tracing_core::__macro_support::Option::Some(837u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::assembly"),
::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::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::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: () = loop {};
return __tracing_attr_fake_return;
}
{
let cx = self.cx();
if cx.is_sizedness_trait(goal.predicate.trait_def_id(cx)) {
return;
}
let self_ty = goal.predicate.self_ty();
let bounds =
match self_ty.kind() {
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) |
ty::Float(_) | ty::Adt(_, _) | ty::Foreign(_) | ty::Str |
ty::Array(_, _) | ty::Pat(_, _) | ty::Slice(_) |
ty::RawPtr(_, _) | ty::Ref(_, _, _) | ty::FnDef(_, _) |
ty::FnPtr(..) | ty::UnsafeBinder(_) | ty::Alias(..) |
ty::Closure(..) | ty::CoroutineClosure(..) |
ty::Coroutine(..) | ty::CoroutineWitness(..) | ty::Never |
ty::Tuple(_) | ty::Param(_) | ty::Placeholder(..) |
ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) | ty::Error(_) =>
return,
ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_)
| ty::FreshFloatTy(_)) | ty::Bound(..) => {
::core::panicking::panic_fmt(format_args!("unexpected self type for `{0:?}`",
goal));
}
ty::Dynamic(bounds, ..) => bounds,
};
if bounds.principal_def_id().is_some_and(|def_id|
!cx.trait_is_dyn_compatible(def_id)) {
return;
}
for bound in bounds.iter() {
match bound.skip_binder() {
ty::ExistentialPredicate::Trait(_) => {}
ty::ExistentialPredicate::Projection(_) |
ty::ExistentialPredicate::AutoTrait(_) => {
candidates.extend(G::probe_and_consider_object_bound_candidate(self,
CandidateSource::BuiltinImpl(BuiltinImplSource::Misc), goal,
bound.with_self_ty(cx, self_ty)));
}
}
}
if let Some(principal) = bounds.principal() {
let principal_trait_ref = principal.with_self_ty(cx, self_ty);
for (idx, assumption) in
elaborate::supertraits(cx, principal_trait_ref).enumerate()
{
candidates.extend(G::probe_and_consider_object_bound_candidate(self,
CandidateSource::BuiltinImpl(BuiltinImplSource::Object(idx)),
goal, assumption.upcast(cx)));
}
}
}
}
}#[instrument(level = "trace", skip_all)]
838 fn assemble_object_bound_candidates<G: GoalKind<D>>(
839 &mut self,
840 goal: Goal<I, G>,
841 candidates: &mut Vec<Candidate<I>>,
842 ) {
843 let cx = self.cx();
844 if cx.is_sizedness_trait(goal.predicate.trait_def_id(cx)) {
845 return;
848 }
849
850 let self_ty = goal.predicate.self_ty();
851 let bounds = match self_ty.kind() {
852 ty::Bool
853 | ty::Char
854 | ty::Int(_)
855 | ty::Uint(_)
856 | ty::Float(_)
857 | ty::Adt(_, _)
858 | ty::Foreign(_)
859 | ty::Str
860 | ty::Array(_, _)
861 | ty::Pat(_, _)
862 | ty::Slice(_)
863 | ty::RawPtr(_, _)
864 | ty::Ref(_, _, _)
865 | ty::FnDef(_, _)
866 | ty::FnPtr(..)
867 | ty::UnsafeBinder(_)
868 | ty::Alias(..)
869 | ty::Closure(..)
870 | ty::CoroutineClosure(..)
871 | ty::Coroutine(..)
872 | ty::CoroutineWitness(..)
873 | ty::Never
874 | ty::Tuple(_)
875 | ty::Param(_)
876 | ty::Placeholder(..)
877 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
878 | ty::Error(_) => return,
879 ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_))
880 | ty::Bound(..) => panic!("unexpected self type for `{goal:?}`"),
881 ty::Dynamic(bounds, ..) => bounds,
882 };
883
884 if bounds.principal_def_id().is_some_and(|def_id| !cx.trait_is_dyn_compatible(def_id)) {
886 return;
887 }
888
889 for bound in bounds.iter() {
893 match bound.skip_binder() {
894 ty::ExistentialPredicate::Trait(_) => {
895 }
897 ty::ExistentialPredicate::Projection(_)
898 | ty::ExistentialPredicate::AutoTrait(_) => {
899 candidates.extend(G::probe_and_consider_object_bound_candidate(
900 self,
901 CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
902 goal,
903 bound.with_self_ty(cx, self_ty),
904 ));
905 }
906 }
907 }
908
909 if let Some(principal) = bounds.principal() {
913 let principal_trait_ref = principal.with_self_ty(cx, self_ty);
914 for (idx, assumption) in elaborate::supertraits(cx, principal_trait_ref).enumerate() {
915 candidates.extend(G::probe_and_consider_object_bound_candidate(
916 self,
917 CandidateSource::BuiltinImpl(BuiltinImplSource::Object(idx)),
918 goal,
919 assumption.upcast(cx),
920 ));
921 }
922 }
923 }
924
925 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::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("consider_coherence_unknowable_candidate",
"rustc_next_trait_solver::solve::assembly",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs"),
::tracing_core::__macro_support::Option::Some(931u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::assembly"),
::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::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::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: Result<Candidate<I>, NoSolution> =
loop {};
return __tracing_attr_fake_return;
}
{
self.probe_trait_candidate(CandidateSource::CoherenceUnknowable).enter(|ecx|
{
let cx = ecx.cx();
let trait_ref = goal.predicate.trait_ref(cx);
if ecx.trait_ref_is_knowable(goal.param_env, trait_ref)? {
Err(NoSolution)
} else {
let predicate: I::Predicate = trait_ref.upcast(cx);
ecx.add_goals(GoalSource::Misc,
elaborate::elaborate(cx,
[predicate]).skip(1).map(|predicate|
goal.with(cx, predicate)));
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
}
})
}
}
}#[instrument(level = "trace", skip_all)]
932 fn consider_coherence_unknowable_candidate<G: GoalKind<D>>(
933 &mut self,
934 goal: Goal<I, G>,
935 ) -> Result<Candidate<I>, NoSolution> {
936 self.probe_trait_candidate(CandidateSource::CoherenceUnknowable).enter(|ecx| {
937 let cx = ecx.cx();
938 let trait_ref = goal.predicate.trait_ref(cx);
939 if ecx.trait_ref_is_knowable(goal.param_env, trait_ref)? {
940 Err(NoSolution)
941 } else {
942 let predicate: I::Predicate = trait_ref.upcast(cx);
948 ecx.add_goals(
949 GoalSource::Misc,
950 elaborate::elaborate(cx, [predicate])
951 .skip(1)
952 .map(|predicate| goal.with(cx, predicate)),
953 );
954 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
955 }
956 })
957 }
958}
959
960pub(super) enum AllowInferenceConstraints {
961 Yes,
962 No,
963}
964
965impl<D, I> EvalCtxt<'_, D>
966where
967 D: SolverDelegate<Interner = I>,
968 I: Interner,
969{
970 pub(super) fn filter_specialized_impls(
974 &mut self,
975 allow_inference_constraints: AllowInferenceConstraints,
976 candidates: &mut Vec<Candidate<I>>,
977 ) {
978 if self.typing_mode().is_coherence() {
979 return;
980 }
981
982 let mut i = 0;
983 'outer: while i < candidates.len() {
984 let CandidateSource::Impl(victim_def_id) = candidates[i].source else {
985 i += 1;
986 continue;
987 };
988
989 for (j, c) in candidates.iter().enumerate() {
990 if i == j {
991 continue;
992 }
993
994 let CandidateSource::Impl(other_def_id) = c.source else {
995 continue;
996 };
997
998 if #[allow(non_exhaustive_omitted_patterns)] match allow_inference_constraints {
AllowInferenceConstraints::Yes => true,
_ => false,
}matches!(allow_inference_constraints, AllowInferenceConstraints::Yes)
1005 || has_only_region_constraints(c.result)
1006 {
1007 if self.cx().impl_specializes(other_def_id, victim_def_id) {
1008 candidates.remove(i);
1009 continue 'outer;
1010 }
1011 }
1012 }
1013
1014 i += 1;
1015 }
1016 }
1017
1018 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::INFO <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::INFO <=
::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("try_assemble_bounds_via_registered_opaques",
"rustc_next_trait_solver::solve::assembly",
::tracing::Level::INFO,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs"),
::tracing_core::__macro_support::Option::Some(1029u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::assembly"),
::tracing_core::field::FieldSet::new(&["goal",
"candidates"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::INFO <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::INFO <=
::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(&goal)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidates)
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: () = loop {};
return __tracing_attr_fake_return;
}
{
let self_ty = goal.predicate.self_ty();
let opaque_types =
match self.typing_mode() {
TypingMode::Analysis { .. } =>
self.opaques_with_sub_unified_hidden_type(self_ty),
TypingMode::Coherence | TypingMode::Borrowck { .. } |
TypingMode::PostBorrowckAnalysis { .. } |
TypingMode::PostAnalysis => ::alloc::vec::Vec::new(),
TypingMode::ErasedNotCoherence(MayBeErased) => {
self.opaque_accesses.rerun_if_any_opaque_has_infer_as_hidden_type(RerunReason::SelfTyInfer);
Vec::new()
}
};
if opaque_types.is_empty() {
candidates.extend(self.forced_ambiguity(MaybeInfo::AMBIGUOUS));
return;
}
for &alias_ty in &opaque_types {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs:1057",
"rustc_next_trait_solver::solve::assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs"),
::tracing_core::__macro_support::Option::Some(1057u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::assembly"),
::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!("self ty is sub unified with {0:?}",
alias_ty) as &dyn Value))])
});
} else { ; }
};
struct ReplaceOpaque<I: Interner> {
cx: I,
alias_ty: ty::AliasTy<I>,
self_ty: I::Ty,
}
impl<I: Interner> TypeFolder<I> for ReplaceOpaque<I> {
fn cx(&self) -> I { self.cx }
fn fold_ty(&mut self, ty: I::Ty) -> I::Ty {
if let ty::Alias(alias_ty) = ty.kind() {
if alias_ty == self.alias_ty { return self.self_ty; }
}
ty.super_fold_with(self)
}
}
for item_bound in
self.cx().item_self_bounds(alias_ty.kind.def_id()).iter_instantiated(self.cx(),
alias_ty.args).map(Unnormalized::skip_norm_wip) {
let assumption =
item_bound.fold_with(&mut ReplaceOpaque {
cx: self.cx(),
alias_ty,
self_ty,
});
candidates.extend(G::probe_and_match_goal_against_assumption(self,
CandidateSource::AliasBound(AliasBoundKind::SelfBounds),
goal, assumption,
|ecx|
{
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
}));
}
}
if assemble_from.should_assemble_impl_candidates() {
let cx = self.cx();
cx.for_each_blanket_impl(goal.predicate.trait_def_id(cx),
|impl_def_id|
{
if cx.impl_is_default(impl_def_id) { return; }
match G::consider_impl_candidate(self, goal, impl_def_id,
|ecx, certainty|
{
if ecx.shallow_resolve(self_ty).is_ty_var() {
let certainty = certainty.and(Certainty::AMBIGUOUS);
ecx.evaluate_added_goals_and_make_canonical_response(certainty)
} else { Err(NoSolution) }
}) {
Ok(candidate) => candidates.push(candidate),
Err(NoSolution) => (),
}
});
}
if candidates.is_empty() {
let source =
CandidateSource::BuiltinImpl(BuiltinImplSource::Misc);
let certainty =
Certainty::Maybe(MaybeInfo {
cause: MaybeCause::Ambiguity,
opaque_types_jank: OpaqueTypesJank::ErrorIfRigidSelfTy,
stalled_on_coroutines: StalledOnCoroutines::No,
});
candidates.extend(self.probe_trait_candidate(source).enter(|this|
{
this.evaluate_added_goals_and_make_canonical_response(certainty)
}));
}
}
}
}#[tracing::instrument(skip(self, assemble_from))]
1030 fn try_assemble_bounds_via_registered_opaques<G: GoalKind<D>>(
1031 &mut self,
1032 goal: Goal<I, G>,
1033 assemble_from: AssembleCandidatesFrom,
1034 candidates: &mut Vec<Candidate<I>>,
1035 ) {
1036 let self_ty = goal.predicate.self_ty();
1037 let opaque_types = match self.typing_mode() {
1039 TypingMode::Analysis { .. } => self.opaques_with_sub_unified_hidden_type(self_ty),
1040 TypingMode::Coherence
1041 | TypingMode::Borrowck { .. }
1042 | TypingMode::PostBorrowckAnalysis { .. }
1043 | TypingMode::PostAnalysis => vec![],
1044 TypingMode::ErasedNotCoherence(MayBeErased) => {
1045 self.opaque_accesses
1046 .rerun_if_any_opaque_has_infer_as_hidden_type(RerunReason::SelfTyInfer);
1047 Vec::new()
1048 }
1049 };
1050
1051 if opaque_types.is_empty() {
1052 candidates.extend(self.forced_ambiguity(MaybeInfo::AMBIGUOUS));
1053 return;
1054 }
1055
1056 for &alias_ty in &opaque_types {
1057 debug!("self ty is sub unified with {alias_ty:?}");
1058
1059 struct ReplaceOpaque<I: Interner> {
1060 cx: I,
1061 alias_ty: ty::AliasTy<I>,
1062 self_ty: I::Ty,
1063 }
1064 impl<I: Interner> TypeFolder<I> for ReplaceOpaque<I> {
1065 fn cx(&self) -> I {
1066 self.cx
1067 }
1068 fn fold_ty(&mut self, ty: I::Ty) -> I::Ty {
1069 if let ty::Alias(alias_ty) = ty.kind() {
1070 if alias_ty == self.alias_ty {
1071 return self.self_ty;
1072 }
1073 }
1074 ty.super_fold_with(self)
1075 }
1076 }
1077
1078 for item_bound in self
1086 .cx()
1087 .item_self_bounds(alias_ty.kind.def_id())
1088 .iter_instantiated(self.cx(), alias_ty.args)
1089 .map(Unnormalized::skip_norm_wip)
1090 {
1091 let assumption =
1092 item_bound.fold_with(&mut ReplaceOpaque { cx: self.cx(), alias_ty, self_ty });
1093 candidates.extend(G::probe_and_match_goal_against_assumption(
1094 self,
1095 CandidateSource::AliasBound(AliasBoundKind::SelfBounds),
1096 goal,
1097 assumption,
1098 |ecx| {
1099 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
1102 },
1103 ));
1104 }
1105 }
1106
1107 if assemble_from.should_assemble_impl_candidates() {
1112 let cx = self.cx();
1113 cx.for_each_blanket_impl(goal.predicate.trait_def_id(cx), |impl_def_id| {
1114 if cx.impl_is_default(impl_def_id) {
1118 return;
1119 }
1120
1121 match G::consider_impl_candidate(self, goal, impl_def_id, |ecx, certainty| {
1122 if ecx.shallow_resolve(self_ty).is_ty_var() {
1123 let certainty = certainty.and(Certainty::AMBIGUOUS);
1125 ecx.evaluate_added_goals_and_make_canonical_response(certainty)
1126 } else {
1127 Err(NoSolution)
1133 }
1134 }) {
1135 Ok(candidate) => candidates.push(candidate),
1136 Err(NoSolution) => (),
1137 }
1138 });
1139 }
1140
1141 if candidates.is_empty() {
1142 let source = CandidateSource::BuiltinImpl(BuiltinImplSource::Misc);
1143 let certainty = Certainty::Maybe(MaybeInfo {
1144 cause: MaybeCause::Ambiguity,
1145 opaque_types_jank: OpaqueTypesJank::ErrorIfRigidSelfTy,
1146 stalled_on_coroutines: StalledOnCoroutines::No,
1147 });
1148 candidates
1149 .extend(self.probe_trait_candidate(source).enter(|this| {
1150 this.evaluate_added_goals_and_make_canonical_response(certainty)
1151 }));
1152 }
1153 }
1154
1155 x;#[instrument(level = "debug", skip_all, fields(proven_via, goal), ret)]
1186 pub(super) fn assemble_and_merge_candidates<G: GoalKind<D>>(
1187 &mut self,
1188 proven_via: Option<TraitGoalProvenVia>,
1189 goal: Goal<I, G>,
1190 inject_forced_ambiguity_candidate: impl FnOnce(&mut EvalCtxt<'_, D>) -> Option<QueryResult<I>>,
1191 inject_normalize_to_rigid_candidate: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResult<I>,
1192 ) -> QueryResult<I> {
1193 let Some(proven_via) = proven_via else {
1194 return self.forced_ambiguity(MaybeInfo::AMBIGUOUS).map(|cand| cand.result);
1201 };
1202
1203 match proven_via {
1204 TraitGoalProvenVia::ParamEnv | TraitGoalProvenVia::AliasBound => {
1205 let (mut candidates, _) = self
1209 .assemble_and_evaluate_candidates(goal, AssembleCandidatesFrom::EnvAndBounds);
1210 debug!(?candidates);
1211
1212 if candidates.is_empty() {
1215 return inject_normalize_to_rigid_candidate(self);
1216 }
1217
1218 if let Some(result) = inject_forced_ambiguity_candidate(self) {
1221 return result;
1222 }
1223
1224 if candidates.iter().any(|c| matches!(c.source, CandidateSource::ParamEnv(_))) {
1227 candidates.retain(|c| matches!(c.source, CandidateSource::ParamEnv(_)));
1228 }
1229
1230 if let Some((response, _)) = self.try_merge_candidates(&candidates) {
1231 Ok(response)
1232 } else {
1233 self.flounder(&candidates)
1234 }
1235 }
1236 TraitGoalProvenVia::Misc => {
1237 let (mut candidates, _) =
1238 self.assemble_and_evaluate_candidates(goal, AssembleCandidatesFrom::All);
1239
1240 if candidates.iter().any(|c| matches!(c.source, CandidateSource::ParamEnv(_))) {
1243 candidates.retain(|c| matches!(c.source, CandidateSource::ParamEnv(_)));
1244 }
1245
1246 self.filter_specialized_impls(AllowInferenceConstraints::Yes, &mut candidates);
1252 if let Some((response, _)) = self.try_merge_candidates(&candidates) {
1253 Ok(response)
1254 } else {
1255 self.flounder(&candidates)
1256 }
1257 }
1258 }
1259 }
1260
1261 fn characterize_param_env_assumption(
1275 &mut self,
1276 param_env: I::ParamEnv,
1277 assumption: I::Clause,
1278 ) -> Result<(CandidateSource<I>, Certainty), NoSolution> {
1279 if assumption.has_bound_vars() {
1282 return Ok((CandidateSource::ParamEnv(ParamEnvSource::NonGlobal), Certainty::Yes));
1283 }
1284
1285 match assumption.visit_with(&mut FindParamInClause {
1286 ecx: self,
1287 param_env,
1288 universes: ::alloc::vec::Vec::new()vec![],
1289 recursion_depth: 0,
1290 }) {
1291 ControlFlow::Break(Err(NoSolution)) => Err(NoSolution),
1292 ControlFlow::Break(Ok(certainty)) => {
1293 Ok((CandidateSource::ParamEnv(ParamEnvSource::NonGlobal), certainty))
1294 }
1295 ControlFlow::Continue(()) => {
1296 Ok((CandidateSource::ParamEnv(ParamEnvSource::Global), Certainty::Yes))
1297 }
1298 }
1299 }
1300}
1301
1302struct FindParamInClause<'a, 'b, D: SolverDelegate<Interner = I>, I: Interner> {
1303 ecx: &'a mut EvalCtxt<'b, D>,
1304 param_env: I::ParamEnv,
1305 universes: Vec<Option<ty::UniverseIndex>>,
1306 recursion_depth: usize,
1307}
1308
1309impl<D, I> TypeVisitor<I> for FindParamInClause<'_, '_, D, I>
1310where
1311 D: SolverDelegate<Interner = I>,
1312 I: Interner,
1313{
1314 type Result = ControlFlow<Result<Certainty, NoSolution>>;
1319
1320 fn visit_binder<T: TypeVisitable<I>>(&mut self, t: &ty::Binder<I, T>) -> Self::Result {
1321 self.universes.push(None);
1322 t.super_visit_with(self)?;
1323 self.universes.pop();
1324 ControlFlow::Continue(())
1325 }
1326
1327 fn visit_ty(&mut self, ty: I::Ty) -> Self::Result {
1328 let ty = self.ecx.replace_bound_vars(ty, &mut self.universes);
1329 let Ok(ty) = self.ecx.structurally_normalize_ty(self.param_env, ty) else {
1330 return ControlFlow::Break(Err(NoSolution));
1331 };
1332
1333 match ty.kind() {
1334 ty::Placeholder(p) => {
1335 if p.universe() == ty::UniverseIndex::ROOT {
1336 ControlFlow::Break(Ok(Certainty::Yes))
1337 } else {
1338 ControlFlow::Continue(())
1339 }
1340 }
1341 ty::Infer(_) => ControlFlow::Break(Ok(Certainty::AMBIGUOUS)),
1342 _ if ty.has_type_flags(
1343 TypeFlags::HAS_PLACEHOLDER | TypeFlags::HAS_INFER | TypeFlags::HAS_ALIAS,
1344 ) =>
1345 {
1346 self.recursion_depth += 1;
1347 if self.recursion_depth > self.ecx.cx().recursion_limit() {
1348 return ControlFlow::Break(Ok(Certainty::Maybe(MaybeInfo {
1349 cause: MaybeCause::Overflow {
1350 suggest_increasing_limit: true,
1351 keep_constraints: false,
1352 },
1353 opaque_types_jank: OpaqueTypesJank::AllGood,
1354 stalled_on_coroutines: StalledOnCoroutines::No,
1355 })));
1356 }
1357 let result = ty.super_visit_with(self);
1358 self.recursion_depth -= 1;
1359 result
1360 }
1361 _ => ControlFlow::Continue(()),
1362 }
1363 }
1364
1365 fn visit_const(&mut self, ct: I::Const) -> Self::Result {
1366 let ct = self.ecx.replace_bound_vars(ct, &mut self.universes);
1367 let Ok(ct) = self.ecx.structurally_normalize_const(self.param_env, ct) else {
1368 return ControlFlow::Break(Err(NoSolution));
1369 };
1370
1371 match ct.kind() {
1372 ty::ConstKind::Placeholder(p) => {
1373 if p.universe() == ty::UniverseIndex::ROOT {
1374 ControlFlow::Break(Ok(Certainty::Yes))
1375 } else {
1376 ControlFlow::Continue(())
1377 }
1378 }
1379 ty::ConstKind::Infer(_) => ControlFlow::Break(Ok(Certainty::AMBIGUOUS)),
1380 _ if ct.has_type_flags(
1381 TypeFlags::HAS_PLACEHOLDER | TypeFlags::HAS_INFER | TypeFlags::HAS_ALIAS,
1382 ) =>
1383 {
1384 ct.super_visit_with(self)
1386 }
1387 _ => ControlFlow::Continue(()),
1388 }
1389 }
1390
1391 fn visit_region(&mut self, r: I::Region) -> Self::Result {
1392 match self.ecx.eager_resolve_region(r).kind() {
1393 ty::ReStatic | ty::ReError(_) | ty::ReBound(..) => ControlFlow::Continue(()),
1394 ty::RePlaceholder(p) => {
1395 if p.universe() == ty::UniverseIndex::ROOT {
1396 ControlFlow::Break(Ok(Certainty::Yes))
1397 } else {
1398 ControlFlow::Continue(())
1399 }
1400 }
1401 ty::ReVar(_) => ControlFlow::Break(Ok(Certainty::Yes)),
1402 ty::ReErased | ty::ReEarlyParam(_) | ty::ReLateParam(_) => {
1403 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("unexpected region in param-env clause")));
}unreachable!("unexpected region in param-env clause")
1404 }
1405 }
1406 }
1407}