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::{AliasBoundKind, SizedTraitKind};
13use rustc_type_ir::{
14 self as ty, AliasTy, Interner, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable,
15 TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, Upcast,
16 elaborate,
17};
18use tracing::{debug, instrument};
19
20use super::trait_goals::TraitGoalProvenVia;
21use super::{has_only_region_constraints, inspect};
22use crate::delegate::SolverDelegate;
23use crate::solve::inspect::ProbeKind;
24use crate::solve::{
25 BuiltinImplSource, CandidateSource, CanonicalResponse, Certainty, EvalCtxt, Goal, GoalSource,
26 MaybeCause, NoSolution, OpaqueTypesJank, ParamEnvSource, QueryResult,
27 has_no_inference_or_external_constraints,
28};
29
30#[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)]
35pub(super) struct Candidate<I: Interner> {
36 pub(super) source: CandidateSource<I>,
37 pub(super) result: CanonicalResponse<I>,
38 pub(super) head_usages: CandidateHeadUsages,
39}
40
41pub(super) trait GoalKind<D, I = <D as SolverDelegate>::Interner>:
43 TypeFoldable<I> + Copy + Eq + std::fmt::Display
44where
45 D: SolverDelegate<Interner = I>,
46 I: Interner,
47{
48 fn self_ty(self) -> I::Ty;
49
50 fn trait_ref(self, cx: I) -> ty::TraitRef<I>;
51
52 fn with_replaced_self_ty(self, cx: I, self_ty: I::Ty) -> Self;
53
54 fn trait_def_id(self, cx: I) -> I::TraitId;
55
56 fn probe_and_consider_implied_clause(
60 ecx: &mut EvalCtxt<'_, D>,
61 parent_source: CandidateSource<I>,
62 goal: Goal<I, Self>,
63 assumption: I::Clause,
64 requirements: impl IntoIterator<Item = (GoalSource, Goal<I, I::Predicate>)>,
65 ) -> Result<Candidate<I>, NoSolution> {
66 Self::probe_and_match_goal_against_assumption(ecx, parent_source, goal, assumption, |ecx| {
67 for (nested_source, goal) in requirements {
68 ecx.add_goal(nested_source, goal);
69 }
70 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
71 })
72 }
73
74 fn probe_and_consider_object_bound_candidate(
80 ecx: &mut EvalCtxt<'_, D>,
81 source: CandidateSource<I>,
82 goal: Goal<I, Self>,
83 assumption: I::Clause,
84 ) -> Result<Candidate<I>, NoSolution> {
85 Self::probe_and_match_goal_against_assumption(ecx, source, goal, assumption, |ecx| {
86 let cx = ecx.cx();
87 let ty::Dynamic(bounds, _) = goal.predicate.self_ty().kind() else {
88 {
::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`");
89 };
90
91 let trait_ref = assumption.kind().map_bound(|clause| match clause {
92 ty::ClauseKind::Trait(pred) => pred.trait_ref,
93 ty::ClauseKind::Projection(proj) => proj.projection_term.trait_ref(cx),
94
95 ty::ClauseKind::RegionOutlives(..)
96 | ty::ClauseKind::TypeOutlives(..)
97 | ty::ClauseKind::ConstArgHasType(..)
98 | ty::ClauseKind::WellFormed(..)
99 | ty::ClauseKind::ConstEvaluatable(..)
100 | ty::ClauseKind::HostEffect(..)
101 | ty::ClauseKind::UnstableFeature(..) => {
102 {
::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")
103 }
104 });
105
106 match structural_traits::predicates_for_object_candidate(
107 ecx,
108 goal.param_env,
109 trait_ref,
110 bounds,
111 ) {
112 Ok(requirements) => {
113 ecx.add_goals(GoalSource::ImplWhereBound, requirements);
114 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
115 }
116 Err(_) => {
117 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
118 }
119 }
120 })
121 }
122
123 fn consider_additional_alias_assumptions(
127 ecx: &mut EvalCtxt<'_, D>,
128 goal: Goal<I, Self>,
129 alias_ty: ty::AliasTy<I>,
130 ) -> Vec<Candidate<I>>;
131
132 fn probe_and_consider_param_env_candidate(
133 ecx: &mut EvalCtxt<'_, D>,
134 goal: Goal<I, Self>,
135 assumption: I::Clause,
136 ) -> Result<Candidate<I>, CandidateHeadUsages> {
137 match Self::fast_reject_assumption(ecx, goal, assumption) {
138 Ok(()) => {}
139 Err(NoSolution) => return Err(CandidateHeadUsages::default()),
140 }
141
142 let source = Cell::new(CandidateSource::ParamEnv(ParamEnvSource::Global));
149 let (result, head_usages) = ecx
150 .probe(|result: &QueryResult<I>| inspect::ProbeKind::TraitCandidate {
151 source: source.get(),
152 result: *result,
153 })
154 .enter_single_candidate(|ecx| {
155 Self::match_assumption(ecx, goal, assumption, |ecx| {
156 ecx.try_evaluate_added_goals()?;
157 let (src, certainty) =
158 ecx.characterize_param_env_assumption(goal.param_env, assumption)?;
159 source.set(src);
160 ecx.evaluate_added_goals_and_make_canonical_response(certainty)
161 })
162 });
163
164 match result {
165 Ok(result) => Ok(Candidate { source: source.get(), result, head_usages }),
166 Err(NoSolution) => Err(head_usages),
167 }
168 }
169
170 fn probe_and_match_goal_against_assumption(
175 ecx: &mut EvalCtxt<'_, D>,
176 source: CandidateSource<I>,
177 goal: Goal<I, Self>,
178 assumption: I::Clause,
179 then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResult<I>,
180 ) -> Result<Candidate<I>, NoSolution> {
181 Self::fast_reject_assumption(ecx, goal, assumption)?;
182
183 ecx.probe_trait_candidate(source)
184 .enter(|ecx| Self::match_assumption(ecx, goal, assumption, then))
185 }
186
187 fn fast_reject_assumption(
190 ecx: &mut EvalCtxt<'_, D>,
191 goal: Goal<I, Self>,
192 assumption: I::Clause,
193 ) -> Result<(), NoSolution>;
194
195 fn match_assumption(
197 ecx: &mut EvalCtxt<'_, D>,
198 goal: Goal<I, Self>,
199 assumption: I::Clause,
200 then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResult<I>,
201 ) -> QueryResult<I>;
202
203 fn consider_impl_candidate(
204 ecx: &mut EvalCtxt<'_, D>,
205 goal: Goal<I, Self>,
206 impl_def_id: I::ImplId,
207 then: impl FnOnce(&mut EvalCtxt<'_, D>, Certainty) -> QueryResult<I>,
208 ) -> Result<Candidate<I>, NoSolution>;
209
210 fn consider_error_guaranteed_candidate(
217 ecx: &mut EvalCtxt<'_, D>,
218 guar: I::ErrorGuaranteed,
219 ) -> Result<Candidate<I>, NoSolution>;
220
221 fn consider_auto_trait_candidate(
226 ecx: &mut EvalCtxt<'_, D>,
227 goal: Goal<I, Self>,
228 ) -> Result<Candidate<I>, NoSolution>;
229
230 fn consider_trait_alias_candidate(
232 ecx: &mut EvalCtxt<'_, D>,
233 goal: Goal<I, Self>,
234 ) -> Result<Candidate<I>, NoSolution>;
235
236 fn consider_builtin_sizedness_candidates(
242 ecx: &mut EvalCtxt<'_, D>,
243 goal: Goal<I, Self>,
244 sizedness: SizedTraitKind,
245 ) -> Result<Candidate<I>, NoSolution>;
246
247 fn consider_builtin_copy_clone_candidate(
252 ecx: &mut EvalCtxt<'_, D>,
253 goal: Goal<I, Self>,
254 ) -> Result<Candidate<I>, NoSolution>;
255
256 fn consider_builtin_fn_ptr_trait_candidate(
258 ecx: &mut EvalCtxt<'_, D>,
259 goal: Goal<I, Self>,
260 ) -> Result<Candidate<I>, NoSolution>;
261
262 fn consider_builtin_fn_trait_candidates(
265 ecx: &mut EvalCtxt<'_, D>,
266 goal: Goal<I, Self>,
267 kind: ty::ClosureKind,
268 ) -> Result<Candidate<I>, NoSolution>;
269
270 fn consider_builtin_async_fn_trait_candidates(
273 ecx: &mut EvalCtxt<'_, D>,
274 goal: Goal<I, Self>,
275 kind: ty::ClosureKind,
276 ) -> Result<Candidate<I>, NoSolution>;
277
278 fn consider_builtin_async_fn_kind_helper_candidate(
282 ecx: &mut EvalCtxt<'_, D>,
283 goal: Goal<I, Self>,
284 ) -> Result<Candidate<I>, NoSolution>;
285
286 fn consider_builtin_tuple_candidate(
288 ecx: &mut EvalCtxt<'_, D>,
289 goal: Goal<I, Self>,
290 ) -> Result<Candidate<I>, NoSolution>;
291
292 fn consider_builtin_pointee_candidate(
298 ecx: &mut EvalCtxt<'_, D>,
299 goal: Goal<I, Self>,
300 ) -> Result<Candidate<I>, NoSolution>;
301
302 fn consider_builtin_future_candidate(
306 ecx: &mut EvalCtxt<'_, D>,
307 goal: Goal<I, Self>,
308 ) -> Result<Candidate<I>, NoSolution>;
309
310 fn consider_builtin_iterator_candidate(
314 ecx: &mut EvalCtxt<'_, D>,
315 goal: Goal<I, Self>,
316 ) -> Result<Candidate<I>, NoSolution>;
317
318 fn consider_builtin_fused_iterator_candidate(
321 ecx: &mut EvalCtxt<'_, D>,
322 goal: Goal<I, Self>,
323 ) -> Result<Candidate<I>, NoSolution>;
324
325 fn consider_builtin_async_iterator_candidate(
326 ecx: &mut EvalCtxt<'_, D>,
327 goal: Goal<I, Self>,
328 ) -> Result<Candidate<I>, NoSolution>;
329
330 fn consider_builtin_coroutine_candidate(
334 ecx: &mut EvalCtxt<'_, D>,
335 goal: Goal<I, Self>,
336 ) -> Result<Candidate<I>, NoSolution>;
337
338 fn consider_builtin_discriminant_kind_candidate(
339 ecx: &mut EvalCtxt<'_, D>,
340 goal: Goal<I, Self>,
341 ) -> Result<Candidate<I>, NoSolution>;
342
343 fn consider_builtin_destruct_candidate(
344 ecx: &mut EvalCtxt<'_, D>,
345 goal: Goal<I, Self>,
346 ) -> Result<Candidate<I>, NoSolution>;
347
348 fn consider_builtin_transmute_candidate(
349 ecx: &mut EvalCtxt<'_, D>,
350 goal: Goal<I, Self>,
351 ) -> Result<Candidate<I>, NoSolution>;
352
353 fn consider_builtin_bikeshed_guaranteed_no_drop_candidate(
354 ecx: &mut EvalCtxt<'_, D>,
355 goal: Goal<I, Self>,
356 ) -> Result<Candidate<I>, NoSolution>;
357
358 fn consider_structural_builtin_unsize_candidates(
366 ecx: &mut EvalCtxt<'_, D>,
367 goal: Goal<I, Self>,
368 ) -> Vec<Candidate<I>>;
369
370 fn consider_builtin_field_candidate(
371 ecx: &mut EvalCtxt<'_, D>,
372 goal: Goal<I, Self>,
373 ) -> Result<Candidate<I>, NoSolution>;
374}
375
376pub(super) enum AssembleCandidatesFrom {
384 All,
385 EnvAndBounds,
389}
390
391impl AssembleCandidatesFrom {
392 fn should_assemble_impl_candidates(&self) -> bool {
393 match self {
394 AssembleCandidatesFrom::All => true,
395 AssembleCandidatesFrom::EnvAndBounds => false,
396 }
397 }
398}
399
400#[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)]
409pub(super) struct FailedCandidateInfo {
410 pub param_env_head_usages: CandidateHeadUsages,
411}
412
413impl<D, I> EvalCtxt<'_, D>
414where
415 D: SolverDelegate<Interner = I>,
416 I: Interner,
417{
418 pub(super) fn assemble_and_evaluate_candidates<G: GoalKind<D>>(
419 &mut self,
420 goal: Goal<I, G>,
421 assemble_from: AssembleCandidatesFrom,
422 ) -> (Vec<Candidate<I>>, FailedCandidateInfo) {
423 let mut candidates = ::alloc::vec::Vec::new()vec![];
424 let mut failed_candidate_info =
425 FailedCandidateInfo { param_env_head_usages: CandidateHeadUsages::default() };
426 let Ok(normalized_self_ty) =
427 self.structurally_normalize_ty(goal.param_env, goal.predicate.self_ty())
428 else {
429 return (candidates, failed_candidate_info);
430 };
431
432 let goal: Goal<I, G> = goal
433 .with(self.cx(), goal.predicate.with_replaced_self_ty(self.cx(), normalized_self_ty));
434
435 if normalized_self_ty.is_ty_var() {
436 {
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:436",
"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(436u32),
::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");
437 self.try_assemble_bounds_via_registered_opaques(goal, assemble_from, &mut candidates);
438 return (candidates, failed_candidate_info);
439 }
440
441 let goal = self.resolve_vars_if_possible(goal);
444
445 if let TypingMode::Coherence = self.typing_mode()
446 && let Ok(candidate) = self.consider_coherence_unknowable_candidate(goal)
447 {
448 candidates.push(candidate);
449 return (candidates, failed_candidate_info);
450 }
451
452 self.assemble_alias_bound_candidates(goal, &mut candidates);
453 self.assemble_param_env_candidates(goal, &mut candidates, &mut failed_candidate_info);
454
455 match assemble_from {
456 AssembleCandidatesFrom::All => {
457 self.assemble_builtin_impl_candidates(goal, &mut candidates);
458 if TypingMode::Coherence == self.typing_mode()
470 || !candidates.iter().any(|c| {
471 #[allow(non_exhaustive_omitted_patterns)] match c.source {
CandidateSource::ParamEnv(ParamEnvSource::NonGlobal) |
CandidateSource::AliasBound(_) => true,
_ => false,
}matches!(
472 c.source,
473 CandidateSource::ParamEnv(ParamEnvSource::NonGlobal)
474 | CandidateSource::AliasBound(_)
475 ) && has_no_inference_or_external_constraints(c.result)
476 })
477 {
478 self.assemble_impl_candidates(goal, &mut candidates);
479 self.assemble_object_bound_candidates(goal, &mut candidates);
480 }
481 }
482 AssembleCandidatesFrom::EnvAndBounds => {
483 if #[allow(non_exhaustive_omitted_patterns)] match normalized_self_ty.kind() {
ty::Dynamic(..) => true,
_ => false,
}matches!(normalized_self_ty.kind(), ty::Dynamic(..))
487 && !candidates.iter().any(|c| #[allow(non_exhaustive_omitted_patterns)] match c.source {
CandidateSource::ParamEnv(_) => true,
_ => false,
}matches!(c.source, CandidateSource::ParamEnv(_)))
488 {
489 self.assemble_object_bound_candidates(goal, &mut candidates);
490 }
491 }
492 }
493
494 (candidates, failed_candidate_info)
495 }
496
497 pub(super) fn forced_ambiguity(
498 &mut self,
499 cause: MaybeCause,
500 ) -> Result<Candidate<I>, NoSolution> {
501 let source = CandidateSource::BuiltinImpl(BuiltinImplSource::Misc);
510 let certainty = Certainty::Maybe { cause, opaque_types_jank: OpaqueTypesJank::AllGood };
511 self.probe_trait_candidate(source)
512 .enter(|this| this.evaluate_added_goals_and_make_canonical_response(certainty))
513 }
514
515 #[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(515u32),
::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)]
516 fn assemble_impl_candidates<G: GoalKind<D>>(
517 &mut self,
518 goal: Goal<I, G>,
519 candidates: &mut Vec<Candidate<I>>,
520 ) {
521 let cx = self.cx();
522 cx.for_each_relevant_impl(
523 goal.predicate.trait_def_id(cx),
524 goal.predicate.self_ty(),
525 |impl_def_id| {
526 if cx.impl_is_default(impl_def_id) {
530 return;
531 }
532 match G::consider_impl_candidate(self, goal, impl_def_id, |ecx, certainty| {
533 ecx.evaluate_added_goals_and_make_canonical_response(certainty)
534 }) {
535 Ok(candidate) => candidates.push(candidate),
536 Err(NoSolution) => (),
537 }
538 },
539 );
540 }
541
542 #[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(542u32),
::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)]
543 fn assemble_builtin_impl_candidates<G: GoalKind<D>>(
544 &mut self,
545 goal: Goal<I, G>,
546 candidates: &mut Vec<Candidate<I>>,
547 ) {
548 let cx = self.cx();
549 let trait_def_id = goal.predicate.trait_def_id(cx);
550
551 let result = if let Err(guar) = goal.predicate.error_reported() {
559 G::consider_error_guaranteed_candidate(self, guar)
560 } else if cx.trait_is_auto(trait_def_id) {
561 G::consider_auto_trait_candidate(self, goal)
562 } else if cx.trait_is_alias(trait_def_id) {
563 G::consider_trait_alias_candidate(self, goal)
564 } else {
565 match cx.as_trait_lang_item(trait_def_id) {
566 Some(SolverTraitLangItem::Sized) => {
567 G::consider_builtin_sizedness_candidates(self, goal, SizedTraitKind::Sized)
568 }
569 Some(SolverTraitLangItem::MetaSized) => {
570 G::consider_builtin_sizedness_candidates(self, goal, SizedTraitKind::MetaSized)
571 }
572 Some(SolverTraitLangItem::PointeeSized) => {
573 unreachable!("`PointeeSized` is removed during lowering");
574 }
575 Some(
576 SolverTraitLangItem::Copy
577 | SolverTraitLangItem::Clone
578 | SolverTraitLangItem::TrivialClone,
579 ) => G::consider_builtin_copy_clone_candidate(self, goal),
580 Some(SolverTraitLangItem::Fn) => {
581 G::consider_builtin_fn_trait_candidates(self, goal, ty::ClosureKind::Fn)
582 }
583 Some(SolverTraitLangItem::FnMut) => {
584 G::consider_builtin_fn_trait_candidates(self, goal, ty::ClosureKind::FnMut)
585 }
586 Some(SolverTraitLangItem::FnOnce) => {
587 G::consider_builtin_fn_trait_candidates(self, goal, ty::ClosureKind::FnOnce)
588 }
589 Some(SolverTraitLangItem::AsyncFn) => {
590 G::consider_builtin_async_fn_trait_candidates(self, goal, ty::ClosureKind::Fn)
591 }
592 Some(SolverTraitLangItem::AsyncFnMut) => {
593 G::consider_builtin_async_fn_trait_candidates(
594 self,
595 goal,
596 ty::ClosureKind::FnMut,
597 )
598 }
599 Some(SolverTraitLangItem::AsyncFnOnce) => {
600 G::consider_builtin_async_fn_trait_candidates(
601 self,
602 goal,
603 ty::ClosureKind::FnOnce,
604 )
605 }
606 Some(SolverTraitLangItem::FnPtrTrait) => {
607 G::consider_builtin_fn_ptr_trait_candidate(self, goal)
608 }
609 Some(SolverTraitLangItem::AsyncFnKindHelper) => {
610 G::consider_builtin_async_fn_kind_helper_candidate(self, goal)
611 }
612 Some(SolverTraitLangItem::Tuple) => G::consider_builtin_tuple_candidate(self, goal),
613 Some(SolverTraitLangItem::PointeeTrait) => {
614 G::consider_builtin_pointee_candidate(self, goal)
615 }
616 Some(SolverTraitLangItem::Future) => {
617 G::consider_builtin_future_candidate(self, goal)
618 }
619 Some(SolverTraitLangItem::Iterator) => {
620 G::consider_builtin_iterator_candidate(self, goal)
621 }
622 Some(SolverTraitLangItem::FusedIterator) => {
623 G::consider_builtin_fused_iterator_candidate(self, goal)
624 }
625 Some(SolverTraitLangItem::AsyncIterator) => {
626 G::consider_builtin_async_iterator_candidate(self, goal)
627 }
628 Some(SolverTraitLangItem::Coroutine) => {
629 G::consider_builtin_coroutine_candidate(self, goal)
630 }
631 Some(SolverTraitLangItem::DiscriminantKind) => {
632 G::consider_builtin_discriminant_kind_candidate(self, goal)
633 }
634 Some(SolverTraitLangItem::Destruct) => {
635 G::consider_builtin_destruct_candidate(self, goal)
636 }
637 Some(SolverTraitLangItem::TransmuteTrait) => {
638 G::consider_builtin_transmute_candidate(self, goal)
639 }
640 Some(SolverTraitLangItem::BikeshedGuaranteedNoDrop) => {
641 G::consider_builtin_bikeshed_guaranteed_no_drop_candidate(self, goal)
642 }
643 Some(SolverTraitLangItem::Field) => G::consider_builtin_field_candidate(self, goal),
644 _ => Err(NoSolution),
645 }
646 };
647
648 candidates.extend(result);
649
650 if cx.is_trait_lang_item(trait_def_id, SolverTraitLangItem::Unsize) {
653 candidates.extend(G::consider_structural_builtin_unsize_candidates(self, goal));
654 }
655 }
656
657 #[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(657u32),
::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)]
658 fn assemble_param_env_candidates<G: GoalKind<D>>(
659 &mut self,
660 goal: Goal<I, G>,
661 candidates: &mut Vec<Candidate<I>>,
662 failed_candidate_info: &mut FailedCandidateInfo,
663 ) {
664 for assumption in goal.param_env.caller_bounds().iter() {
665 match G::probe_and_consider_param_env_candidate(self, goal, assumption) {
666 Ok(candidate) => candidates.push(candidate),
667 Err(head_usages) => {
668 failed_candidate_info.param_env_head_usages.merge_usages(head_usages)
669 }
670 }
671 }
672 }
673
674 #[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(674u32),
::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 () =
self.probe(|_|
ProbeKind::NormalizedSelfTyAssembly).enter(|ecx|
{
ecx.assemble_alias_bound_candidates_recur(goal.predicate.self_ty(),
goal, candidates, AliasBoundKind::SelfBounds);
});
}
}
}#[instrument(level = "trace", skip_all)]
675 fn assemble_alias_bound_candidates<G: GoalKind<D>>(
676 &mut self,
677 goal: Goal<I, G>,
678 candidates: &mut Vec<Candidate<I>>,
679 ) {
680 let () = self.probe(|_| ProbeKind::NormalizedSelfTyAssembly).enter(|ecx| {
681 ecx.assemble_alias_bound_candidates_recur(
682 goal.predicate.self_ty(),
683 goal,
684 candidates,
685 AliasBoundKind::SelfBounds,
686 );
687 });
688 }
689
690 fn assemble_alias_bound_candidates_recur<G: GoalKind<D>>(
700 &mut self,
701 self_ty: I::Ty,
702 goal: Goal<I, G>,
703 candidates: &mut Vec<Candidate<I>>,
704 consider_self_bounds: AliasBoundKind,
705 ) {
706 let alias_ty = match self_ty.kind() {
707 ty::Bool
708 | ty::Char
709 | ty::Int(_)
710 | ty::Uint(_)
711 | ty::Float(_)
712 | ty::Adt(_, _)
713 | ty::Foreign(_)
714 | ty::Str
715 | ty::Array(_, _)
716 | ty::Pat(_, _)
717 | ty::Slice(_)
718 | ty::RawPtr(_, _)
719 | ty::Ref(_, _, _)
720 | ty::FnDef(_, _)
721 | ty::FnPtr(..)
722 | ty::UnsafeBinder(_)
723 | ty::Dynamic(..)
724 | ty::Closure(..)
725 | ty::CoroutineClosure(..)
726 | ty::Coroutine(..)
727 | ty::CoroutineWitness(..)
728 | ty::Never
729 | ty::Tuple(_)
730 | ty::Param(_)
731 | ty::Placeholder(..)
732 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
733 | ty::Error(_) => return,
734 ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) | ty::Bound(..) => {
735 {
::core::panicking::panic_fmt(format_args!("unexpected self type for `{0:?}`",
goal));
}panic!("unexpected self type for `{goal:?}`")
736 }
737
738 ty::Infer(ty::TyVar(_)) => {
739 if let Ok(result) =
743 self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
744 {
745 candidates.push(Candidate {
746 source: CandidateSource::AliasBound(consider_self_bounds),
747 result,
748 head_usages: CandidateHeadUsages::default(),
749 });
750 }
751 return;
752 }
753
754 ty::Alias(
755 alias_ty @ AliasTy { kind: ty::Projection { .. } | ty::Opaque { .. }, .. },
756 ) => alias_ty,
757 ty::Alias(AliasTy { kind: ty::Inherent { .. } | ty::Free { .. }, .. }) => {
758 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"));
759 return;
760 }
761 };
762
763 match consider_self_bounds {
764 AliasBoundKind::SelfBounds => {
765 for assumption in self
766 .cx()
767 .item_self_bounds(alias_ty.kind.def_id())
768 .iter_instantiated(self.cx(), alias_ty.args)
769 {
770 candidates.extend(G::probe_and_consider_implied_clause(
771 self,
772 CandidateSource::AliasBound(consider_self_bounds),
773 goal,
774 assumption,
775 [],
776 ));
777 }
778 }
779 AliasBoundKind::NonSelfBounds => {
780 for assumption in self
781 .cx()
782 .item_non_self_bounds(alias_ty.kind.def_id())
783 .iter_instantiated(self.cx(), alias_ty.args)
784 {
785 candidates.extend(G::probe_and_consider_implied_clause(
786 self,
787 CandidateSource::AliasBound(consider_self_bounds),
788 goal,
789 assumption,
790 [],
791 ));
792 }
793 }
794 }
795
796 candidates.extend(G::consider_additional_alias_assumptions(self, goal, alias_ty));
797
798 if !#[allow(non_exhaustive_omitted_patterns)] match alias_ty.kind {
ty::Projection { .. } => true,
_ => false,
}matches!(alias_ty.kind, ty::Projection { .. }) {
799 return;
800 }
801
802 match self.structurally_normalize_ty(goal.param_env, alias_ty.self_ty()) {
804 Ok(next_self_ty) => self.assemble_alias_bound_candidates_recur(
805 next_self_ty,
806 goal,
807 candidates,
808 AliasBoundKind::NonSelfBounds,
809 ),
810 Err(NoSolution) => {}
811 }
812 }
813
814 #[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(814u32),
::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)]
815 fn assemble_object_bound_candidates<G: GoalKind<D>>(
816 &mut self,
817 goal: Goal<I, G>,
818 candidates: &mut Vec<Candidate<I>>,
819 ) {
820 let cx = self.cx();
821 if cx.is_sizedness_trait(goal.predicate.trait_def_id(cx)) {
822 return;
825 }
826
827 let self_ty = goal.predicate.self_ty();
828 let bounds = match self_ty.kind() {
829 ty::Bool
830 | ty::Char
831 | ty::Int(_)
832 | ty::Uint(_)
833 | ty::Float(_)
834 | ty::Adt(_, _)
835 | ty::Foreign(_)
836 | ty::Str
837 | ty::Array(_, _)
838 | ty::Pat(_, _)
839 | ty::Slice(_)
840 | ty::RawPtr(_, _)
841 | ty::Ref(_, _, _)
842 | ty::FnDef(_, _)
843 | ty::FnPtr(..)
844 | ty::UnsafeBinder(_)
845 | ty::Alias(..)
846 | ty::Closure(..)
847 | ty::CoroutineClosure(..)
848 | ty::Coroutine(..)
849 | ty::CoroutineWitness(..)
850 | ty::Never
851 | ty::Tuple(_)
852 | ty::Param(_)
853 | ty::Placeholder(..)
854 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
855 | ty::Error(_) => return,
856 ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_))
857 | ty::Bound(..) => panic!("unexpected self type for `{goal:?}`"),
858 ty::Dynamic(bounds, ..) => bounds,
859 };
860
861 if bounds.principal_def_id().is_some_and(|def_id| !cx.trait_is_dyn_compatible(def_id)) {
863 return;
864 }
865
866 for bound in bounds.iter() {
870 match bound.skip_binder() {
871 ty::ExistentialPredicate::Trait(_) => {
872 }
874 ty::ExistentialPredicate::Projection(_)
875 | ty::ExistentialPredicate::AutoTrait(_) => {
876 candidates.extend(G::probe_and_consider_object_bound_candidate(
877 self,
878 CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
879 goal,
880 bound.with_self_ty(cx, self_ty),
881 ));
882 }
883 }
884 }
885
886 if let Some(principal) = bounds.principal() {
890 let principal_trait_ref = principal.with_self_ty(cx, self_ty);
891 for (idx, assumption) in elaborate::supertraits(cx, principal_trait_ref).enumerate() {
892 candidates.extend(G::probe_and_consider_object_bound_candidate(
893 self,
894 CandidateSource::BuiltinImpl(BuiltinImplSource::Object(idx)),
895 goal,
896 assumption.upcast(cx),
897 ));
898 }
899 }
900 }
901
902 #[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(908u32),
::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)]
909 fn consider_coherence_unknowable_candidate<G: GoalKind<D>>(
910 &mut self,
911 goal: Goal<I, G>,
912 ) -> Result<Candidate<I>, NoSolution> {
913 self.probe_trait_candidate(CandidateSource::CoherenceUnknowable).enter(|ecx| {
914 let cx = ecx.cx();
915 let trait_ref = goal.predicate.trait_ref(cx);
916 if ecx.trait_ref_is_knowable(goal.param_env, trait_ref)? {
917 Err(NoSolution)
918 } else {
919 let predicate: I::Predicate = trait_ref.upcast(cx);
925 ecx.add_goals(
926 GoalSource::Misc,
927 elaborate::elaborate(cx, [predicate])
928 .skip(1)
929 .map(|predicate| goal.with(cx, predicate)),
930 );
931 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
932 }
933 })
934 }
935}
936
937pub(super) enum AllowInferenceConstraints {
938 Yes,
939 No,
940}
941
942impl<D, I> EvalCtxt<'_, D>
943where
944 D: SolverDelegate<Interner = I>,
945 I: Interner,
946{
947 pub(super) fn filter_specialized_impls(
951 &mut self,
952 allow_inference_constraints: AllowInferenceConstraints,
953 candidates: &mut Vec<Candidate<I>>,
954 ) {
955 match self.typing_mode() {
956 TypingMode::Coherence => return,
957 TypingMode::Analysis { .. }
958 | TypingMode::Borrowck { .. }
959 | TypingMode::PostBorrowckAnalysis { .. }
960 | TypingMode::PostAnalysis => {}
961 }
962
963 let mut i = 0;
964 'outer: while i < candidates.len() {
965 let CandidateSource::Impl(victim_def_id) = candidates[i].source else {
966 i += 1;
967 continue;
968 };
969
970 for (j, c) in candidates.iter().enumerate() {
971 if i == j {
972 continue;
973 }
974
975 let CandidateSource::Impl(other_def_id) = c.source else {
976 continue;
977 };
978
979 if #[allow(non_exhaustive_omitted_patterns)] match allow_inference_constraints {
AllowInferenceConstraints::Yes => true,
_ => false,
}matches!(allow_inference_constraints, AllowInferenceConstraints::Yes)
986 || has_only_region_constraints(c.result)
987 {
988 if self.cx().impl_specializes(other_def_id, victim_def_id) {
989 candidates.remove(i);
990 continue 'outer;
991 }
992 }
993 }
994
995 i += 1;
996 }
997 }
998
999 fn try_assemble_bounds_via_registered_opaques<G: GoalKind<D>>(
1011 &mut self,
1012 goal: Goal<I, G>,
1013 assemble_from: AssembleCandidatesFrom,
1014 candidates: &mut Vec<Candidate<I>>,
1015 ) {
1016 let self_ty = goal.predicate.self_ty();
1017 let opaque_types = match self.typing_mode() {
1019 TypingMode::Analysis { .. } => self.opaques_with_sub_unified_hidden_type(self_ty),
1020 TypingMode::Coherence
1021 | TypingMode::Borrowck { .. }
1022 | TypingMode::PostBorrowckAnalysis { .. }
1023 | TypingMode::PostAnalysis => ::alloc::vec::Vec::new()vec![],
1024 };
1025
1026 if opaque_types.is_empty() {
1027 candidates.extend(self.forced_ambiguity(MaybeCause::Ambiguity));
1028 return;
1029 }
1030
1031 for &alias_ty in &opaque_types {
1032 {
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:1032",
"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(1032u32),
::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 { ; }
};debug!("self ty is sub unified with {alias_ty:?}");
1033
1034 struct ReplaceOpaque<I: Interner> {
1035 cx: I,
1036 alias_ty: ty::AliasTy<I>,
1037 self_ty: I::Ty,
1038 }
1039 impl<I: Interner> TypeFolder<I> for ReplaceOpaque<I> {
1040 fn cx(&self) -> I {
1041 self.cx
1042 }
1043 fn fold_ty(&mut self, ty: I::Ty) -> I::Ty {
1044 if let ty::Alias(alias_ty) = ty.kind() {
1045 if alias_ty == self.alias_ty {
1046 return self.self_ty;
1047 }
1048 }
1049 ty.super_fold_with(self)
1050 }
1051 }
1052
1053 for item_bound in self
1061 .cx()
1062 .item_self_bounds(alias_ty.kind.def_id())
1063 .iter_instantiated(self.cx(), alias_ty.args)
1064 {
1065 let assumption =
1066 item_bound.fold_with(&mut ReplaceOpaque { cx: self.cx(), alias_ty, self_ty });
1067 candidates.extend(G::probe_and_match_goal_against_assumption(
1068 self,
1069 CandidateSource::AliasBound(AliasBoundKind::SelfBounds),
1070 goal,
1071 assumption,
1072 |ecx| {
1073 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
1076 },
1077 ));
1078 }
1079 }
1080
1081 if assemble_from.should_assemble_impl_candidates() {
1086 let cx = self.cx();
1087 cx.for_each_blanket_impl(goal.predicate.trait_def_id(cx), |impl_def_id| {
1088 if cx.impl_is_default(impl_def_id) {
1092 return;
1093 }
1094
1095 match G::consider_impl_candidate(self, goal, impl_def_id, |ecx, certainty| {
1096 if ecx.shallow_resolve(self_ty).is_ty_var() {
1097 let certainty = certainty.and(Certainty::AMBIGUOUS);
1099 ecx.evaluate_added_goals_and_make_canonical_response(certainty)
1100 } else {
1101 Err(NoSolution)
1107 }
1108 }) {
1109 Ok(candidate) => candidates.push(candidate),
1110 Err(NoSolution) => (),
1111 }
1112 });
1113 }
1114
1115 if candidates.is_empty() {
1116 let source = CandidateSource::BuiltinImpl(BuiltinImplSource::Misc);
1117 let certainty = Certainty::Maybe {
1118 cause: MaybeCause::Ambiguity,
1119 opaque_types_jank: OpaqueTypesJank::ErrorIfRigidSelfTy,
1120 };
1121 candidates
1122 .extend(self.probe_trait_candidate(source).enter(|this| {
1123 this.evaluate_added_goals_and_make_canonical_response(certainty)
1124 }));
1125 }
1126 }
1127
1128 x;#[instrument(level = "debug", skip_all, fields(proven_via, goal), ret)]
1159 pub(super) fn assemble_and_merge_candidates<G: GoalKind<D>>(
1160 &mut self,
1161 proven_via: Option<TraitGoalProvenVia>,
1162 goal: Goal<I, G>,
1163 inject_forced_ambiguity_candidate: impl FnOnce(&mut EvalCtxt<'_, D>) -> Option<QueryResult<I>>,
1164 inject_normalize_to_rigid_candidate: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResult<I>,
1165 ) -> QueryResult<I> {
1166 let Some(proven_via) = proven_via else {
1167 return self.forced_ambiguity(MaybeCause::Ambiguity).map(|cand| cand.result);
1174 };
1175
1176 match proven_via {
1177 TraitGoalProvenVia::ParamEnv | TraitGoalProvenVia::AliasBound => {
1178 let (mut candidates, _) = self
1182 .assemble_and_evaluate_candidates(goal, AssembleCandidatesFrom::EnvAndBounds);
1183 debug!(?candidates);
1184
1185 if candidates.is_empty() {
1188 return inject_normalize_to_rigid_candidate(self);
1189 }
1190
1191 if let Some(result) = inject_forced_ambiguity_candidate(self) {
1194 return result;
1195 }
1196
1197 if candidates.iter().any(|c| matches!(c.source, CandidateSource::ParamEnv(_))) {
1200 candidates.retain(|c| matches!(c.source, CandidateSource::ParamEnv(_)));
1201 }
1202
1203 if let Some((response, _)) = self.try_merge_candidates(&candidates) {
1204 Ok(response)
1205 } else {
1206 self.flounder(&candidates)
1207 }
1208 }
1209 TraitGoalProvenVia::Misc => {
1210 let (mut candidates, _) =
1211 self.assemble_and_evaluate_candidates(goal, AssembleCandidatesFrom::All);
1212
1213 if candidates.iter().any(|c| matches!(c.source, CandidateSource::ParamEnv(_))) {
1216 candidates.retain(|c| matches!(c.source, CandidateSource::ParamEnv(_)));
1217 }
1218
1219 self.filter_specialized_impls(AllowInferenceConstraints::Yes, &mut candidates);
1225 if let Some((response, _)) = self.try_merge_candidates(&candidates) {
1226 Ok(response)
1227 } else {
1228 self.flounder(&candidates)
1229 }
1230 }
1231 }
1232 }
1233
1234 fn characterize_param_env_assumption(
1248 &mut self,
1249 param_env: I::ParamEnv,
1250 assumption: I::Clause,
1251 ) -> Result<(CandidateSource<I>, Certainty), NoSolution> {
1252 if assumption.has_bound_vars() {
1255 return Ok((CandidateSource::ParamEnv(ParamEnvSource::NonGlobal), Certainty::Yes));
1256 }
1257
1258 match assumption.visit_with(&mut FindParamInClause {
1259 ecx: self,
1260 param_env,
1261 universes: ::alloc::vec::Vec::new()vec![],
1262 recursion_depth: 0,
1263 }) {
1264 ControlFlow::Break(Err(NoSolution)) => Err(NoSolution),
1265 ControlFlow::Break(Ok(certainty)) => {
1266 Ok((CandidateSource::ParamEnv(ParamEnvSource::NonGlobal), certainty))
1267 }
1268 ControlFlow::Continue(()) => {
1269 Ok((CandidateSource::ParamEnv(ParamEnvSource::Global), Certainty::Yes))
1270 }
1271 }
1272 }
1273}
1274
1275struct FindParamInClause<'a, 'b, D: SolverDelegate<Interner = I>, I: Interner> {
1276 ecx: &'a mut EvalCtxt<'b, D>,
1277 param_env: I::ParamEnv,
1278 universes: Vec<Option<ty::UniverseIndex>>,
1279 recursion_depth: usize,
1280}
1281
1282impl<D, I> TypeVisitor<I> for FindParamInClause<'_, '_, D, I>
1283where
1284 D: SolverDelegate<Interner = I>,
1285 I: Interner,
1286{
1287 type Result = ControlFlow<Result<Certainty, NoSolution>>;
1292
1293 fn visit_binder<T: TypeVisitable<I>>(&mut self, t: &ty::Binder<I, T>) -> Self::Result {
1294 self.universes.push(None);
1295 t.super_visit_with(self)?;
1296 self.universes.pop();
1297 ControlFlow::Continue(())
1298 }
1299
1300 fn visit_ty(&mut self, ty: I::Ty) -> Self::Result {
1301 let ty = self.ecx.replace_bound_vars(ty, &mut self.universes);
1302 let Ok(ty) = self.ecx.structurally_normalize_ty(self.param_env, ty) else {
1303 return ControlFlow::Break(Err(NoSolution));
1304 };
1305
1306 match ty.kind() {
1307 ty::Placeholder(p) => {
1308 if p.universe() == ty::UniverseIndex::ROOT {
1309 ControlFlow::Break(Ok(Certainty::Yes))
1310 } else {
1311 ControlFlow::Continue(())
1312 }
1313 }
1314 ty::Infer(_) => ControlFlow::Break(Ok(Certainty::AMBIGUOUS)),
1315 _ if ty.has_type_flags(
1316 TypeFlags::HAS_PLACEHOLDER | TypeFlags::HAS_INFER | TypeFlags::HAS_ALIAS,
1317 ) =>
1318 {
1319 self.recursion_depth += 1;
1320 if self.recursion_depth > self.ecx.cx().recursion_limit() {
1321 return ControlFlow::Break(Ok(Certainty::Maybe {
1322 cause: MaybeCause::Overflow {
1323 suggest_increasing_limit: true,
1324 keep_constraints: false,
1325 },
1326 opaque_types_jank: OpaqueTypesJank::AllGood,
1327 }));
1328 }
1329 let result = ty.super_visit_with(self);
1330 self.recursion_depth -= 1;
1331 result
1332 }
1333 _ => ControlFlow::Continue(()),
1334 }
1335 }
1336
1337 fn visit_const(&mut self, ct: I::Const) -> Self::Result {
1338 let ct = self.ecx.replace_bound_vars(ct, &mut self.universes);
1339 let Ok(ct) = self.ecx.structurally_normalize_const(self.param_env, ct) else {
1340 return ControlFlow::Break(Err(NoSolution));
1341 };
1342
1343 match ct.kind() {
1344 ty::ConstKind::Placeholder(p) => {
1345 if p.universe() == ty::UniverseIndex::ROOT {
1346 ControlFlow::Break(Ok(Certainty::Yes))
1347 } else {
1348 ControlFlow::Continue(())
1349 }
1350 }
1351 ty::ConstKind::Infer(_) => ControlFlow::Break(Ok(Certainty::AMBIGUOUS)),
1352 _ if ct.has_type_flags(
1353 TypeFlags::HAS_PLACEHOLDER | TypeFlags::HAS_INFER | TypeFlags::HAS_ALIAS,
1354 ) =>
1355 {
1356 ct.super_visit_with(self)
1358 }
1359 _ => ControlFlow::Continue(()),
1360 }
1361 }
1362
1363 fn visit_region(&mut self, r: I::Region) -> Self::Result {
1364 match self.ecx.eager_resolve_region(r).kind() {
1365 ty::ReStatic | ty::ReError(_) | ty::ReBound(..) => ControlFlow::Continue(()),
1366 ty::RePlaceholder(p) => {
1367 if p.universe() == ty::UniverseIndex::ROOT {
1368 ControlFlow::Break(Ok(Certainty::Yes))
1369 } else {
1370 ControlFlow::Continue(())
1371 }
1372 }
1373 ty::ReVar(_) => ControlFlow::Break(Ok(Certainty::Yes)),
1374 ty::ReErased | ty::ReEarlyParam(_) | ty::ReLateParam(_) => {
1375 {
::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")
1376 }
1377 }
1378 }
1379}