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 let assemble_impls = match self.typing_mode() {
470 TypingMode::Coherence => true,
471 TypingMode::Analysis { .. }
472 | TypingMode::Borrowck { .. }
473 | TypingMode::PostBorrowckAnalysis { .. }
474 | TypingMode::PostAnalysis => !candidates.iter().any(|c| {
475 #[allow(non_exhaustive_omitted_patterns)] match c.source {
CandidateSource::ParamEnv(ParamEnvSource::NonGlobal) |
CandidateSource::AliasBound(_) => true,
_ => false,
}matches!(
476 c.source,
477 CandidateSource::ParamEnv(ParamEnvSource::NonGlobal)
478 | CandidateSource::AliasBound(_)
479 ) && has_no_inference_or_external_constraints(c.result)
480 }),
481 };
482 if assemble_impls {
483 self.assemble_impl_candidates(goal, &mut candidates);
484 self.assemble_object_bound_candidates(goal, &mut candidates);
485 }
486 }
487 AssembleCandidatesFrom::EnvAndBounds => {
488 if #[allow(non_exhaustive_omitted_patterns)] match normalized_self_ty.kind() {
ty::Dynamic(..) => true,
_ => false,
}matches!(normalized_self_ty.kind(), ty::Dynamic(..))
492 && !candidates.iter().any(|c| #[allow(non_exhaustive_omitted_patterns)] match c.source {
CandidateSource::ParamEnv(_) => true,
_ => false,
}matches!(c.source, CandidateSource::ParamEnv(_)))
493 {
494 self.assemble_object_bound_candidates(goal, &mut candidates);
495 }
496 }
497 }
498
499 (candidates, failed_candidate_info)
500 }
501
502 pub(super) fn forced_ambiguity(
503 &mut self,
504 cause: MaybeCause,
505 ) -> Result<Candidate<I>, NoSolution> {
506 let source = CandidateSource::BuiltinImpl(BuiltinImplSource::Misc);
515 let certainty = Certainty::Maybe { cause, opaque_types_jank: OpaqueTypesJank::AllGood };
516 self.probe_trait_candidate(source)
517 .enter(|this| this.evaluate_added_goals_and_make_canonical_response(certainty))
518 }
519
520 #[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(520u32),
::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)]
521 fn assemble_impl_candidates<G: GoalKind<D>>(
522 &mut self,
523 goal: Goal<I, G>,
524 candidates: &mut Vec<Candidate<I>>,
525 ) {
526 let cx = self.cx();
527 cx.for_each_relevant_impl(
528 goal.predicate.trait_def_id(cx),
529 goal.predicate.self_ty(),
530 |impl_def_id| {
531 if cx.impl_is_default(impl_def_id) {
535 return;
536 }
537 match G::consider_impl_candidate(self, goal, impl_def_id, |ecx, certainty| {
538 ecx.evaluate_added_goals_and_make_canonical_response(certainty)
539 }) {
540 Ok(candidate) => candidates.push(candidate),
541 Err(NoSolution) => (),
542 }
543 },
544 );
545 }
546
547 #[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(547u32),
::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)]
548 fn assemble_builtin_impl_candidates<G: GoalKind<D>>(
549 &mut self,
550 goal: Goal<I, G>,
551 candidates: &mut Vec<Candidate<I>>,
552 ) {
553 let cx = self.cx();
554 let trait_def_id = goal.predicate.trait_def_id(cx);
555
556 let result = if let Err(guar) = goal.predicate.error_reported() {
564 G::consider_error_guaranteed_candidate(self, guar)
565 } else if cx.trait_is_auto(trait_def_id) {
566 G::consider_auto_trait_candidate(self, goal)
567 } else if cx.trait_is_alias(trait_def_id) {
568 G::consider_trait_alias_candidate(self, goal)
569 } else {
570 match cx.as_trait_lang_item(trait_def_id) {
571 Some(SolverTraitLangItem::Sized) => {
572 G::consider_builtin_sizedness_candidates(self, goal, SizedTraitKind::Sized)
573 }
574 Some(SolverTraitLangItem::MetaSized) => {
575 G::consider_builtin_sizedness_candidates(self, goal, SizedTraitKind::MetaSized)
576 }
577 Some(SolverTraitLangItem::PointeeSized) => {
578 unreachable!("`PointeeSized` is removed during lowering");
579 }
580 Some(
581 SolverTraitLangItem::Copy
582 | SolverTraitLangItem::Clone
583 | SolverTraitLangItem::TrivialClone,
584 ) => G::consider_builtin_copy_clone_candidate(self, goal),
585 Some(SolverTraitLangItem::Fn) => {
586 G::consider_builtin_fn_trait_candidates(self, goal, ty::ClosureKind::Fn)
587 }
588 Some(SolverTraitLangItem::FnMut) => {
589 G::consider_builtin_fn_trait_candidates(self, goal, ty::ClosureKind::FnMut)
590 }
591 Some(SolverTraitLangItem::FnOnce) => {
592 G::consider_builtin_fn_trait_candidates(self, goal, ty::ClosureKind::FnOnce)
593 }
594 Some(SolverTraitLangItem::AsyncFn) => {
595 G::consider_builtin_async_fn_trait_candidates(self, goal, ty::ClosureKind::Fn)
596 }
597 Some(SolverTraitLangItem::AsyncFnMut) => {
598 G::consider_builtin_async_fn_trait_candidates(
599 self,
600 goal,
601 ty::ClosureKind::FnMut,
602 )
603 }
604 Some(SolverTraitLangItem::AsyncFnOnce) => {
605 G::consider_builtin_async_fn_trait_candidates(
606 self,
607 goal,
608 ty::ClosureKind::FnOnce,
609 )
610 }
611 Some(SolverTraitLangItem::FnPtrTrait) => {
612 G::consider_builtin_fn_ptr_trait_candidate(self, goal)
613 }
614 Some(SolverTraitLangItem::AsyncFnKindHelper) => {
615 G::consider_builtin_async_fn_kind_helper_candidate(self, goal)
616 }
617 Some(SolverTraitLangItem::Tuple) => G::consider_builtin_tuple_candidate(self, goal),
618 Some(SolverTraitLangItem::PointeeTrait) => {
619 G::consider_builtin_pointee_candidate(self, goal)
620 }
621 Some(SolverTraitLangItem::Future) => {
622 G::consider_builtin_future_candidate(self, goal)
623 }
624 Some(SolverTraitLangItem::Iterator) => {
625 G::consider_builtin_iterator_candidate(self, goal)
626 }
627 Some(SolverTraitLangItem::FusedIterator) => {
628 G::consider_builtin_fused_iterator_candidate(self, goal)
629 }
630 Some(SolverTraitLangItem::AsyncIterator) => {
631 G::consider_builtin_async_iterator_candidate(self, goal)
632 }
633 Some(SolverTraitLangItem::Coroutine) => {
634 G::consider_builtin_coroutine_candidate(self, goal)
635 }
636 Some(SolverTraitLangItem::DiscriminantKind) => {
637 G::consider_builtin_discriminant_kind_candidate(self, goal)
638 }
639 Some(SolverTraitLangItem::Destruct) => {
640 G::consider_builtin_destruct_candidate(self, goal)
641 }
642 Some(SolverTraitLangItem::TransmuteTrait) => {
643 G::consider_builtin_transmute_candidate(self, goal)
644 }
645 Some(SolverTraitLangItem::BikeshedGuaranteedNoDrop) => {
646 G::consider_builtin_bikeshed_guaranteed_no_drop_candidate(self, goal)
647 }
648 Some(SolverTraitLangItem::Field) => G::consider_builtin_field_candidate(self, goal),
649 _ => Err(NoSolution),
650 }
651 };
652
653 candidates.extend(result);
654
655 if cx.is_trait_lang_item(trait_def_id, SolverTraitLangItem::Unsize) {
658 candidates.extend(G::consider_structural_builtin_unsize_candidates(self, goal));
659 }
660 }
661
662 #[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(662u32),
::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)]
663 fn assemble_param_env_candidates<G: GoalKind<D>>(
664 &mut self,
665 goal: Goal<I, G>,
666 candidates: &mut Vec<Candidate<I>>,
667 failed_candidate_info: &mut FailedCandidateInfo,
668 ) {
669 for assumption in goal.param_env.caller_bounds().iter() {
670 match G::probe_and_consider_param_env_candidate(self, goal, assumption) {
671 Ok(candidate) => candidates.push(candidate),
672 Err(head_usages) => {
673 failed_candidate_info.param_env_head_usages.merge_usages(head_usages)
674 }
675 }
676 }
677 }
678
679 #[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(679u32),
::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)]
680 fn assemble_alias_bound_candidates<G: GoalKind<D>>(
681 &mut self,
682 goal: Goal<I, G>,
683 candidates: &mut Vec<Candidate<I>>,
684 ) {
685 let () = self.probe(|_| ProbeKind::NormalizedSelfTyAssembly).enter(|ecx| {
686 ecx.assemble_alias_bound_candidates_recur(
687 goal.predicate.self_ty(),
688 goal,
689 candidates,
690 AliasBoundKind::SelfBounds,
691 );
692 });
693 }
694
695 fn assemble_alias_bound_candidates_recur<G: GoalKind<D>>(
705 &mut self,
706 self_ty: I::Ty,
707 goal: Goal<I, G>,
708 candidates: &mut Vec<Candidate<I>>,
709 consider_self_bounds: AliasBoundKind,
710 ) {
711 let alias_ty = match self_ty.kind() {
712 ty::Bool
713 | ty::Char
714 | ty::Int(_)
715 | ty::Uint(_)
716 | ty::Float(_)
717 | ty::Adt(_, _)
718 | ty::Foreign(_)
719 | ty::Str
720 | ty::Array(_, _)
721 | ty::Pat(_, _)
722 | ty::Slice(_)
723 | ty::RawPtr(_, _)
724 | ty::Ref(_, _, _)
725 | ty::FnDef(_, _)
726 | ty::FnPtr(..)
727 | ty::UnsafeBinder(_)
728 | ty::Dynamic(..)
729 | ty::Closure(..)
730 | ty::CoroutineClosure(..)
731 | ty::Coroutine(..)
732 | ty::CoroutineWitness(..)
733 | ty::Never
734 | ty::Tuple(_)
735 | ty::Param(_)
736 | ty::Placeholder(..)
737 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
738 | ty::Error(_) => return,
739 ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) | ty::Bound(..) => {
740 {
::core::panicking::panic_fmt(format_args!("unexpected self type for `{0:?}`",
goal));
}panic!("unexpected self type for `{goal:?}`")
741 }
742
743 ty::Infer(ty::TyVar(_)) => {
744 if let Ok(result) =
748 self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
749 {
750 candidates.push(Candidate {
751 source: CandidateSource::AliasBound(consider_self_bounds),
752 result,
753 head_usages: CandidateHeadUsages::default(),
754 });
755 }
756 return;
757 }
758
759 ty::Alias(
760 alias_ty @ AliasTy { kind: ty::Projection { .. } | ty::Opaque { .. }, .. },
761 ) => alias_ty,
762 ty::Alias(AliasTy { kind: ty::Inherent { .. } | ty::Free { .. }, .. }) => {
763 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"));
764 return;
765 }
766 };
767
768 match consider_self_bounds {
769 AliasBoundKind::SelfBounds => {
770 for assumption in self
771 .cx()
772 .item_self_bounds(alias_ty.kind.def_id())
773 .iter_instantiated(self.cx(), alias_ty.args)
774 {
775 candidates.extend(G::probe_and_consider_implied_clause(
776 self,
777 CandidateSource::AliasBound(consider_self_bounds),
778 goal,
779 assumption,
780 [],
781 ));
782 }
783 }
784 AliasBoundKind::NonSelfBounds => {
785 for assumption in self
786 .cx()
787 .item_non_self_bounds(alias_ty.kind.def_id())
788 .iter_instantiated(self.cx(), alias_ty.args)
789 {
790 candidates.extend(G::probe_and_consider_implied_clause(
791 self,
792 CandidateSource::AliasBound(consider_self_bounds),
793 goal,
794 assumption,
795 [],
796 ));
797 }
798 }
799 }
800
801 candidates.extend(G::consider_additional_alias_assumptions(self, goal, alias_ty));
802
803 if !#[allow(non_exhaustive_omitted_patterns)] match alias_ty.kind {
ty::Projection { .. } => true,
_ => false,
}matches!(alias_ty.kind, ty::Projection { .. }) {
804 return;
805 }
806
807 match self.structurally_normalize_ty(goal.param_env, alias_ty.self_ty()) {
809 Ok(next_self_ty) => self.assemble_alias_bound_candidates_recur(
810 next_self_ty,
811 goal,
812 candidates,
813 AliasBoundKind::NonSelfBounds,
814 ),
815 Err(NoSolution) => {}
816 }
817 }
818
819 #[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(819u32),
::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)]
820 fn assemble_object_bound_candidates<G: GoalKind<D>>(
821 &mut self,
822 goal: Goal<I, G>,
823 candidates: &mut Vec<Candidate<I>>,
824 ) {
825 let cx = self.cx();
826 if cx.is_sizedness_trait(goal.predicate.trait_def_id(cx)) {
827 return;
830 }
831
832 let self_ty = goal.predicate.self_ty();
833 let bounds = match self_ty.kind() {
834 ty::Bool
835 | ty::Char
836 | ty::Int(_)
837 | ty::Uint(_)
838 | ty::Float(_)
839 | ty::Adt(_, _)
840 | ty::Foreign(_)
841 | ty::Str
842 | ty::Array(_, _)
843 | ty::Pat(_, _)
844 | ty::Slice(_)
845 | ty::RawPtr(_, _)
846 | ty::Ref(_, _, _)
847 | ty::FnDef(_, _)
848 | ty::FnPtr(..)
849 | ty::UnsafeBinder(_)
850 | ty::Alias(..)
851 | ty::Closure(..)
852 | ty::CoroutineClosure(..)
853 | ty::Coroutine(..)
854 | ty::CoroutineWitness(..)
855 | ty::Never
856 | ty::Tuple(_)
857 | ty::Param(_)
858 | ty::Placeholder(..)
859 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
860 | ty::Error(_) => return,
861 ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_))
862 | ty::Bound(..) => panic!("unexpected self type for `{goal:?}`"),
863 ty::Dynamic(bounds, ..) => bounds,
864 };
865
866 if bounds.principal_def_id().is_some_and(|def_id| !cx.trait_is_dyn_compatible(def_id)) {
868 return;
869 }
870
871 for bound in bounds.iter() {
875 match bound.skip_binder() {
876 ty::ExistentialPredicate::Trait(_) => {
877 }
879 ty::ExistentialPredicate::Projection(_)
880 | ty::ExistentialPredicate::AutoTrait(_) => {
881 candidates.extend(G::probe_and_consider_object_bound_candidate(
882 self,
883 CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
884 goal,
885 bound.with_self_ty(cx, self_ty),
886 ));
887 }
888 }
889 }
890
891 if let Some(principal) = bounds.principal() {
895 let principal_trait_ref = principal.with_self_ty(cx, self_ty);
896 for (idx, assumption) in elaborate::supertraits(cx, principal_trait_ref).enumerate() {
897 candidates.extend(G::probe_and_consider_object_bound_candidate(
898 self,
899 CandidateSource::BuiltinImpl(BuiltinImplSource::Object(idx)),
900 goal,
901 assumption.upcast(cx),
902 ));
903 }
904 }
905 }
906
907 #[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(913u32),
::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)]
914 fn consider_coherence_unknowable_candidate<G: GoalKind<D>>(
915 &mut self,
916 goal: Goal<I, G>,
917 ) -> Result<Candidate<I>, NoSolution> {
918 self.probe_trait_candidate(CandidateSource::CoherenceUnknowable).enter(|ecx| {
919 let cx = ecx.cx();
920 let trait_ref = goal.predicate.trait_ref(cx);
921 if ecx.trait_ref_is_knowable(goal.param_env, trait_ref)? {
922 Err(NoSolution)
923 } else {
924 let predicate: I::Predicate = trait_ref.upcast(cx);
930 ecx.add_goals(
931 GoalSource::Misc,
932 elaborate::elaborate(cx, [predicate])
933 .skip(1)
934 .map(|predicate| goal.with(cx, predicate)),
935 );
936 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
937 }
938 })
939 }
940}
941
942pub(super) enum AllowInferenceConstraints {
943 Yes,
944 No,
945}
946
947impl<D, I> EvalCtxt<'_, D>
948where
949 D: SolverDelegate<Interner = I>,
950 I: Interner,
951{
952 pub(super) fn filter_specialized_impls(
956 &mut self,
957 allow_inference_constraints: AllowInferenceConstraints,
958 candidates: &mut Vec<Candidate<I>>,
959 ) {
960 match self.typing_mode() {
961 TypingMode::Coherence => return,
962 TypingMode::Analysis { .. }
963 | TypingMode::Borrowck { .. }
964 | TypingMode::PostBorrowckAnalysis { .. }
965 | TypingMode::PostAnalysis => {}
966 }
967
968 let mut i = 0;
969 'outer: while i < candidates.len() {
970 let CandidateSource::Impl(victim_def_id) = candidates[i].source else {
971 i += 1;
972 continue;
973 };
974
975 for (j, c) in candidates.iter().enumerate() {
976 if i == j {
977 continue;
978 }
979
980 let CandidateSource::Impl(other_def_id) = c.source else {
981 continue;
982 };
983
984 if #[allow(non_exhaustive_omitted_patterns)] match allow_inference_constraints {
AllowInferenceConstraints::Yes => true,
_ => false,
}matches!(allow_inference_constraints, AllowInferenceConstraints::Yes)
991 || has_only_region_constraints(c.result)
992 {
993 if self.cx().impl_specializes(other_def_id, victim_def_id) {
994 candidates.remove(i);
995 continue 'outer;
996 }
997 }
998 }
999
1000 i += 1;
1001 }
1002 }
1003
1004 fn try_assemble_bounds_via_registered_opaques<G: GoalKind<D>>(
1016 &mut self,
1017 goal: Goal<I, G>,
1018 assemble_from: AssembleCandidatesFrom,
1019 candidates: &mut Vec<Candidate<I>>,
1020 ) {
1021 let self_ty = goal.predicate.self_ty();
1022 let opaque_types = match self.typing_mode() {
1024 TypingMode::Analysis { .. } => self.opaques_with_sub_unified_hidden_type(self_ty),
1025 TypingMode::Coherence
1026 | TypingMode::Borrowck { .. }
1027 | TypingMode::PostBorrowckAnalysis { .. }
1028 | TypingMode::PostAnalysis => ::alloc::vec::Vec::new()vec![],
1029 };
1030
1031 if opaque_types.is_empty() {
1032 candidates.extend(self.forced_ambiguity(MaybeCause::Ambiguity));
1033 return;
1034 }
1035
1036 for &alias_ty in &opaque_types {
1037 {
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:1037",
"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(1037u32),
::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:?}");
1038
1039 struct ReplaceOpaque<I: Interner> {
1040 cx: I,
1041 alias_ty: ty::AliasTy<I>,
1042 self_ty: I::Ty,
1043 }
1044 impl<I: Interner> TypeFolder<I> for ReplaceOpaque<I> {
1045 fn cx(&self) -> I {
1046 self.cx
1047 }
1048 fn fold_ty(&mut self, ty: I::Ty) -> I::Ty {
1049 if let ty::Alias(alias_ty) = ty.kind() {
1050 if alias_ty == self.alias_ty {
1051 return self.self_ty;
1052 }
1053 }
1054 ty.super_fold_with(self)
1055 }
1056 }
1057
1058 for item_bound in self
1066 .cx()
1067 .item_self_bounds(alias_ty.kind.def_id())
1068 .iter_instantiated(self.cx(), alias_ty.args)
1069 {
1070 let assumption =
1071 item_bound.fold_with(&mut ReplaceOpaque { cx: self.cx(), alias_ty, self_ty });
1072 candidates.extend(G::probe_and_match_goal_against_assumption(
1073 self,
1074 CandidateSource::AliasBound(AliasBoundKind::SelfBounds),
1075 goal,
1076 assumption,
1077 |ecx| {
1078 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
1081 },
1082 ));
1083 }
1084 }
1085
1086 if assemble_from.should_assemble_impl_candidates() {
1091 let cx = self.cx();
1092 cx.for_each_blanket_impl(goal.predicate.trait_def_id(cx), |impl_def_id| {
1093 if cx.impl_is_default(impl_def_id) {
1097 return;
1098 }
1099
1100 match G::consider_impl_candidate(self, goal, impl_def_id, |ecx, certainty| {
1101 if ecx.shallow_resolve(self_ty).is_ty_var() {
1102 let certainty = certainty.and(Certainty::AMBIGUOUS);
1104 ecx.evaluate_added_goals_and_make_canonical_response(certainty)
1105 } else {
1106 Err(NoSolution)
1112 }
1113 }) {
1114 Ok(candidate) => candidates.push(candidate),
1115 Err(NoSolution) => (),
1116 }
1117 });
1118 }
1119
1120 if candidates.is_empty() {
1121 let source = CandidateSource::BuiltinImpl(BuiltinImplSource::Misc);
1122 let certainty = Certainty::Maybe {
1123 cause: MaybeCause::Ambiguity,
1124 opaque_types_jank: OpaqueTypesJank::ErrorIfRigidSelfTy,
1125 };
1126 candidates
1127 .extend(self.probe_trait_candidate(source).enter(|this| {
1128 this.evaluate_added_goals_and_make_canonical_response(certainty)
1129 }));
1130 }
1131 }
1132
1133 x;#[instrument(level = "debug", skip_all, fields(proven_via, goal), ret)]
1164 pub(super) fn assemble_and_merge_candidates<G: GoalKind<D>>(
1165 &mut self,
1166 proven_via: Option<TraitGoalProvenVia>,
1167 goal: Goal<I, G>,
1168 inject_forced_ambiguity_candidate: impl FnOnce(&mut EvalCtxt<'_, D>) -> Option<QueryResult<I>>,
1169 inject_normalize_to_rigid_candidate: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResult<I>,
1170 ) -> QueryResult<I> {
1171 let Some(proven_via) = proven_via else {
1172 return self.forced_ambiguity(MaybeCause::Ambiguity).map(|cand| cand.result);
1179 };
1180
1181 match proven_via {
1182 TraitGoalProvenVia::ParamEnv | TraitGoalProvenVia::AliasBound => {
1183 let (mut candidates, _) = self
1187 .assemble_and_evaluate_candidates(goal, AssembleCandidatesFrom::EnvAndBounds);
1188 debug!(?candidates);
1189
1190 if candidates.is_empty() {
1193 return inject_normalize_to_rigid_candidate(self);
1194 }
1195
1196 if let Some(result) = inject_forced_ambiguity_candidate(self) {
1199 return result;
1200 }
1201
1202 if candidates.iter().any(|c| matches!(c.source, CandidateSource::ParamEnv(_))) {
1205 candidates.retain(|c| matches!(c.source, CandidateSource::ParamEnv(_)));
1206 }
1207
1208 if let Some((response, _)) = self.try_merge_candidates(&candidates) {
1209 Ok(response)
1210 } else {
1211 self.flounder(&candidates)
1212 }
1213 }
1214 TraitGoalProvenVia::Misc => {
1215 let (mut candidates, _) =
1216 self.assemble_and_evaluate_candidates(goal, AssembleCandidatesFrom::All);
1217
1218 if candidates.iter().any(|c| matches!(c.source, CandidateSource::ParamEnv(_))) {
1221 candidates.retain(|c| matches!(c.source, CandidateSource::ParamEnv(_)));
1222 }
1223
1224 self.filter_specialized_impls(AllowInferenceConstraints::Yes, &mut candidates);
1230 if let Some((response, _)) = self.try_merge_candidates(&candidates) {
1231 Ok(response)
1232 } else {
1233 self.flounder(&candidates)
1234 }
1235 }
1236 }
1237 }
1238
1239 fn characterize_param_env_assumption(
1253 &mut self,
1254 param_env: I::ParamEnv,
1255 assumption: I::Clause,
1256 ) -> Result<(CandidateSource<I>, Certainty), NoSolution> {
1257 if assumption.has_bound_vars() {
1260 return Ok((CandidateSource::ParamEnv(ParamEnvSource::NonGlobal), Certainty::Yes));
1261 }
1262
1263 match assumption.visit_with(&mut FindParamInClause {
1264 ecx: self,
1265 param_env,
1266 universes: ::alloc::vec::Vec::new()vec![],
1267 recursion_depth: 0,
1268 }) {
1269 ControlFlow::Break(Err(NoSolution)) => Err(NoSolution),
1270 ControlFlow::Break(Ok(certainty)) => {
1271 Ok((CandidateSource::ParamEnv(ParamEnvSource::NonGlobal), certainty))
1272 }
1273 ControlFlow::Continue(()) => {
1274 Ok((CandidateSource::ParamEnv(ParamEnvSource::Global), Certainty::Yes))
1275 }
1276 }
1277 }
1278}
1279
1280struct FindParamInClause<'a, 'b, D: SolverDelegate<Interner = I>, I: Interner> {
1281 ecx: &'a mut EvalCtxt<'b, D>,
1282 param_env: I::ParamEnv,
1283 universes: Vec<Option<ty::UniverseIndex>>,
1284 recursion_depth: usize,
1285}
1286
1287impl<D, I> TypeVisitor<I> for FindParamInClause<'_, '_, D, I>
1288where
1289 D: SolverDelegate<Interner = I>,
1290 I: Interner,
1291{
1292 type Result = ControlFlow<Result<Certainty, NoSolution>>;
1297
1298 fn visit_binder<T: TypeVisitable<I>>(&mut self, t: &ty::Binder<I, T>) -> Self::Result {
1299 self.universes.push(None);
1300 t.super_visit_with(self)?;
1301 self.universes.pop();
1302 ControlFlow::Continue(())
1303 }
1304
1305 fn visit_ty(&mut self, ty: I::Ty) -> Self::Result {
1306 let ty = self.ecx.replace_bound_vars(ty, &mut self.universes);
1307 let Ok(ty) = self.ecx.structurally_normalize_ty(self.param_env, ty) else {
1308 return ControlFlow::Break(Err(NoSolution));
1309 };
1310
1311 match ty.kind() {
1312 ty::Placeholder(p) => {
1313 if p.universe() == ty::UniverseIndex::ROOT {
1314 ControlFlow::Break(Ok(Certainty::Yes))
1315 } else {
1316 ControlFlow::Continue(())
1317 }
1318 }
1319 ty::Infer(_) => ControlFlow::Break(Ok(Certainty::AMBIGUOUS)),
1320 _ if ty.has_type_flags(
1321 TypeFlags::HAS_PLACEHOLDER | TypeFlags::HAS_INFER | TypeFlags::HAS_ALIAS,
1322 ) =>
1323 {
1324 self.recursion_depth += 1;
1325 if self.recursion_depth > self.ecx.cx().recursion_limit() {
1326 return ControlFlow::Break(Ok(Certainty::Maybe {
1327 cause: MaybeCause::Overflow {
1328 suggest_increasing_limit: true,
1329 keep_constraints: false,
1330 },
1331 opaque_types_jank: OpaqueTypesJank::AllGood,
1332 }));
1333 }
1334 let result = ty.super_visit_with(self);
1335 self.recursion_depth -= 1;
1336 result
1337 }
1338 _ => ControlFlow::Continue(()),
1339 }
1340 }
1341
1342 fn visit_const(&mut self, ct: I::Const) -> Self::Result {
1343 let ct = self.ecx.replace_bound_vars(ct, &mut self.universes);
1344 let Ok(ct) = self.ecx.structurally_normalize_const(self.param_env, ct) else {
1345 return ControlFlow::Break(Err(NoSolution));
1346 };
1347
1348 match ct.kind() {
1349 ty::ConstKind::Placeholder(p) => {
1350 if p.universe() == ty::UniverseIndex::ROOT {
1351 ControlFlow::Break(Ok(Certainty::Yes))
1352 } else {
1353 ControlFlow::Continue(())
1354 }
1355 }
1356 ty::ConstKind::Infer(_) => ControlFlow::Break(Ok(Certainty::AMBIGUOUS)),
1357 _ if ct.has_type_flags(
1358 TypeFlags::HAS_PLACEHOLDER | TypeFlags::HAS_INFER | TypeFlags::HAS_ALIAS,
1359 ) =>
1360 {
1361 ct.super_visit_with(self)
1363 }
1364 _ => ControlFlow::Continue(()),
1365 }
1366 }
1367
1368 fn visit_region(&mut self, r: I::Region) -> Self::Result {
1369 match self.ecx.eager_resolve_region(r).kind() {
1370 ty::ReStatic | ty::ReError(_) | ty::ReBound(..) => ControlFlow::Continue(()),
1371 ty::RePlaceholder(p) => {
1372 if p.universe() == ty::UniverseIndex::ROOT {
1373 ControlFlow::Break(Ok(Certainty::Yes))
1374 } else {
1375 ControlFlow::Continue(())
1376 }
1377 }
1378 ty::ReVar(_) => ControlFlow::Break(Ok(Certainty::Yes)),
1379 ty::ReErased | ty::ReEarlyParam(_) | ty::ReLateParam(_) => {
1380 {
::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")
1381 }
1382 }
1383 }
1384}