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, Unnormalized,
16 Upcast, 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 self.typing_mode().is_coherence()
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 .map(Unnormalized::skip_norm_wip)
775 {
776 candidates.extend(G::probe_and_consider_implied_clause(
777 self,
778 CandidateSource::AliasBound(consider_self_bounds),
779 goal,
780 assumption,
781 [],
782 ));
783 }
784 }
785 AliasBoundKind::NonSelfBounds => {
786 for assumption in self
787 .cx()
788 .item_non_self_bounds(alias_ty.kind.def_id())
789 .iter_instantiated(self.cx(), alias_ty.args)
790 .map(Unnormalized::skip_norm_wip)
791 {
792 candidates.extend(G::probe_and_consider_implied_clause(
793 self,
794 CandidateSource::AliasBound(consider_self_bounds),
795 goal,
796 assumption,
797 [],
798 ));
799 }
800 }
801 }
802
803 candidates.extend(G::consider_additional_alias_assumptions(self, goal, alias_ty));
804
805 if !#[allow(non_exhaustive_omitted_patterns)] match alias_ty.kind {
ty::Projection { .. } => true,
_ => false,
}matches!(alias_ty.kind, ty::Projection { .. }) {
806 return;
807 }
808
809 match self.structurally_normalize_ty(goal.param_env, alias_ty.self_ty()) {
811 Ok(next_self_ty) => self.assemble_alias_bound_candidates_recur(
812 next_self_ty,
813 goal,
814 candidates,
815 AliasBoundKind::NonSelfBounds,
816 ),
817 Err(NoSolution) => {}
818 }
819 }
820
821 #[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(821u32),
::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)]
822 fn assemble_object_bound_candidates<G: GoalKind<D>>(
823 &mut self,
824 goal: Goal<I, G>,
825 candidates: &mut Vec<Candidate<I>>,
826 ) {
827 let cx = self.cx();
828 if cx.is_sizedness_trait(goal.predicate.trait_def_id(cx)) {
829 return;
832 }
833
834 let self_ty = goal.predicate.self_ty();
835 let bounds = match self_ty.kind() {
836 ty::Bool
837 | ty::Char
838 | ty::Int(_)
839 | ty::Uint(_)
840 | ty::Float(_)
841 | ty::Adt(_, _)
842 | ty::Foreign(_)
843 | ty::Str
844 | ty::Array(_, _)
845 | ty::Pat(_, _)
846 | ty::Slice(_)
847 | ty::RawPtr(_, _)
848 | ty::Ref(_, _, _)
849 | ty::FnDef(_, _)
850 | ty::FnPtr(..)
851 | ty::UnsafeBinder(_)
852 | ty::Alias(..)
853 | ty::Closure(..)
854 | ty::CoroutineClosure(..)
855 | ty::Coroutine(..)
856 | ty::CoroutineWitness(..)
857 | ty::Never
858 | ty::Tuple(_)
859 | ty::Param(_)
860 | ty::Placeholder(..)
861 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
862 | ty::Error(_) => return,
863 ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_))
864 | ty::Bound(..) => panic!("unexpected self type for `{goal:?}`"),
865 ty::Dynamic(bounds, ..) => bounds,
866 };
867
868 if bounds.principal_def_id().is_some_and(|def_id| !cx.trait_is_dyn_compatible(def_id)) {
870 return;
871 }
872
873 for bound in bounds.iter() {
877 match bound.skip_binder() {
878 ty::ExistentialPredicate::Trait(_) => {
879 }
881 ty::ExistentialPredicate::Projection(_)
882 | ty::ExistentialPredicate::AutoTrait(_) => {
883 candidates.extend(G::probe_and_consider_object_bound_candidate(
884 self,
885 CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
886 goal,
887 bound.with_self_ty(cx, self_ty),
888 ));
889 }
890 }
891 }
892
893 if let Some(principal) = bounds.principal() {
897 let principal_trait_ref = principal.with_self_ty(cx, self_ty);
898 for (idx, assumption) in elaborate::supertraits(cx, principal_trait_ref).enumerate() {
899 candidates.extend(G::probe_and_consider_object_bound_candidate(
900 self,
901 CandidateSource::BuiltinImpl(BuiltinImplSource::Object(idx)),
902 goal,
903 assumption.upcast(cx),
904 ));
905 }
906 }
907 }
908
909 #[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(915u32),
::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)]
916 fn consider_coherence_unknowable_candidate<G: GoalKind<D>>(
917 &mut self,
918 goal: Goal<I, G>,
919 ) -> Result<Candidate<I>, NoSolution> {
920 self.probe_trait_candidate(CandidateSource::CoherenceUnknowable).enter(|ecx| {
921 let cx = ecx.cx();
922 let trait_ref = goal.predicate.trait_ref(cx);
923 if ecx.trait_ref_is_knowable(goal.param_env, trait_ref)? {
924 Err(NoSolution)
925 } else {
926 let predicate: I::Predicate = trait_ref.upcast(cx);
932 ecx.add_goals(
933 GoalSource::Misc,
934 elaborate::elaborate(cx, [predicate])
935 .skip(1)
936 .map(|predicate| goal.with(cx, predicate)),
937 );
938 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
939 }
940 })
941 }
942}
943
944pub(super) enum AllowInferenceConstraints {
945 Yes,
946 No,
947}
948
949impl<D, I> EvalCtxt<'_, D>
950where
951 D: SolverDelegate<Interner = I>,
952 I: Interner,
953{
954 pub(super) fn filter_specialized_impls(
958 &mut self,
959 allow_inference_constraints: AllowInferenceConstraints,
960 candidates: &mut Vec<Candidate<I>>,
961 ) {
962 match self.typing_mode() {
963 TypingMode::Coherence => return,
964 TypingMode::Analysis { .. }
965 | TypingMode::Borrowck { .. }
966 | TypingMode::PostBorrowckAnalysis { .. }
967 | TypingMode::PostAnalysis => {}
968 }
969
970 let mut i = 0;
971 'outer: while i < candidates.len() {
972 let CandidateSource::Impl(victim_def_id) = candidates[i].source else {
973 i += 1;
974 continue;
975 };
976
977 for (j, c) in candidates.iter().enumerate() {
978 if i == j {
979 continue;
980 }
981
982 let CandidateSource::Impl(other_def_id) = c.source else {
983 continue;
984 };
985
986 if #[allow(non_exhaustive_omitted_patterns)] match allow_inference_constraints {
AllowInferenceConstraints::Yes => true,
_ => false,
}matches!(allow_inference_constraints, AllowInferenceConstraints::Yes)
993 || has_only_region_constraints(c.result)
994 {
995 if self.cx().impl_specializes(other_def_id, victim_def_id) {
996 candidates.remove(i);
997 continue 'outer;
998 }
999 }
1000 }
1001
1002 i += 1;
1003 }
1004 }
1005
1006 fn try_assemble_bounds_via_registered_opaques<G: GoalKind<D>>(
1018 &mut self,
1019 goal: Goal<I, G>,
1020 assemble_from: AssembleCandidatesFrom,
1021 candidates: &mut Vec<Candidate<I>>,
1022 ) {
1023 let self_ty = goal.predicate.self_ty();
1024 let opaque_types = match self.typing_mode() {
1026 TypingMode::Analysis { .. } => self.opaques_with_sub_unified_hidden_type(self_ty),
1027 TypingMode::Coherence
1028 | TypingMode::Borrowck { .. }
1029 | TypingMode::PostBorrowckAnalysis { .. }
1030 | TypingMode::PostAnalysis => ::alloc::vec::Vec::new()vec![],
1031 };
1032
1033 if opaque_types.is_empty() {
1034 candidates.extend(self.forced_ambiguity(MaybeCause::Ambiguity));
1035 return;
1036 }
1037
1038 for &alias_ty in &opaque_types {
1039 {
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:1039",
"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(1039u32),
::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:?}");
1040
1041 struct ReplaceOpaque<I: Interner> {
1042 cx: I,
1043 alias_ty: ty::AliasTy<I>,
1044 self_ty: I::Ty,
1045 }
1046 impl<I: Interner> TypeFolder<I> for ReplaceOpaque<I> {
1047 fn cx(&self) -> I {
1048 self.cx
1049 }
1050 fn fold_ty(&mut self, ty: I::Ty) -> I::Ty {
1051 if let ty::Alias(alias_ty) = ty.kind() {
1052 if alias_ty == self.alias_ty {
1053 return self.self_ty;
1054 }
1055 }
1056 ty.super_fold_with(self)
1057 }
1058 }
1059
1060 for item_bound in self
1068 .cx()
1069 .item_self_bounds(alias_ty.kind.def_id())
1070 .iter_instantiated(self.cx(), alias_ty.args)
1071 .map(Unnormalized::skip_norm_wip)
1072 {
1073 let assumption =
1074 item_bound.fold_with(&mut ReplaceOpaque { cx: self.cx(), alias_ty, self_ty });
1075 candidates.extend(G::probe_and_match_goal_against_assumption(
1076 self,
1077 CandidateSource::AliasBound(AliasBoundKind::SelfBounds),
1078 goal,
1079 assumption,
1080 |ecx| {
1081 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
1084 },
1085 ));
1086 }
1087 }
1088
1089 if assemble_from.should_assemble_impl_candidates() {
1094 let cx = self.cx();
1095 cx.for_each_blanket_impl(goal.predicate.trait_def_id(cx), |impl_def_id| {
1096 if cx.impl_is_default(impl_def_id) {
1100 return;
1101 }
1102
1103 match G::consider_impl_candidate(self, goal, impl_def_id, |ecx, certainty| {
1104 if ecx.shallow_resolve(self_ty).is_ty_var() {
1105 let certainty = certainty.and(Certainty::AMBIGUOUS);
1107 ecx.evaluate_added_goals_and_make_canonical_response(certainty)
1108 } else {
1109 Err(NoSolution)
1115 }
1116 }) {
1117 Ok(candidate) => candidates.push(candidate),
1118 Err(NoSolution) => (),
1119 }
1120 });
1121 }
1122
1123 if candidates.is_empty() {
1124 let source = CandidateSource::BuiltinImpl(BuiltinImplSource::Misc);
1125 let certainty = Certainty::Maybe {
1126 cause: MaybeCause::Ambiguity,
1127 opaque_types_jank: OpaqueTypesJank::ErrorIfRigidSelfTy,
1128 };
1129 candidates
1130 .extend(self.probe_trait_candidate(source).enter(|this| {
1131 this.evaluate_added_goals_and_make_canonical_response(certainty)
1132 }));
1133 }
1134 }
1135
1136 x;#[instrument(level = "debug", skip_all, fields(proven_via, goal), ret)]
1167 pub(super) fn assemble_and_merge_candidates<G: GoalKind<D>>(
1168 &mut self,
1169 proven_via: Option<TraitGoalProvenVia>,
1170 goal: Goal<I, G>,
1171 inject_forced_ambiguity_candidate: impl FnOnce(&mut EvalCtxt<'_, D>) -> Option<QueryResult<I>>,
1172 inject_normalize_to_rigid_candidate: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResult<I>,
1173 ) -> QueryResult<I> {
1174 let Some(proven_via) = proven_via else {
1175 return self.forced_ambiguity(MaybeCause::Ambiguity).map(|cand| cand.result);
1182 };
1183
1184 match proven_via {
1185 TraitGoalProvenVia::ParamEnv | TraitGoalProvenVia::AliasBound => {
1186 let (mut candidates, _) = self
1190 .assemble_and_evaluate_candidates(goal, AssembleCandidatesFrom::EnvAndBounds);
1191 debug!(?candidates);
1192
1193 if candidates.is_empty() {
1196 return inject_normalize_to_rigid_candidate(self);
1197 }
1198
1199 if let Some(result) = inject_forced_ambiguity_candidate(self) {
1202 return result;
1203 }
1204
1205 if candidates.iter().any(|c| matches!(c.source, CandidateSource::ParamEnv(_))) {
1208 candidates.retain(|c| matches!(c.source, CandidateSource::ParamEnv(_)));
1209 }
1210
1211 if let Some((response, _)) = self.try_merge_candidates(&candidates) {
1212 Ok(response)
1213 } else {
1214 self.flounder(&candidates)
1215 }
1216 }
1217 TraitGoalProvenVia::Misc => {
1218 let (mut candidates, _) =
1219 self.assemble_and_evaluate_candidates(goal, AssembleCandidatesFrom::All);
1220
1221 if candidates.iter().any(|c| matches!(c.source, CandidateSource::ParamEnv(_))) {
1224 candidates.retain(|c| matches!(c.source, CandidateSource::ParamEnv(_)));
1225 }
1226
1227 self.filter_specialized_impls(AllowInferenceConstraints::Yes, &mut candidates);
1233 if let Some((response, _)) = self.try_merge_candidates(&candidates) {
1234 Ok(response)
1235 } else {
1236 self.flounder(&candidates)
1237 }
1238 }
1239 }
1240 }
1241
1242 fn characterize_param_env_assumption(
1256 &mut self,
1257 param_env: I::ParamEnv,
1258 assumption: I::Clause,
1259 ) -> Result<(CandidateSource<I>, Certainty), NoSolution> {
1260 if assumption.has_bound_vars() {
1263 return Ok((CandidateSource::ParamEnv(ParamEnvSource::NonGlobal), Certainty::Yes));
1264 }
1265
1266 match assumption.visit_with(&mut FindParamInClause {
1267 ecx: self,
1268 param_env,
1269 universes: ::alloc::vec::Vec::new()vec![],
1270 recursion_depth: 0,
1271 }) {
1272 ControlFlow::Break(Err(NoSolution)) => Err(NoSolution),
1273 ControlFlow::Break(Ok(certainty)) => {
1274 Ok((CandidateSource::ParamEnv(ParamEnvSource::NonGlobal), certainty))
1275 }
1276 ControlFlow::Continue(()) => {
1277 Ok((CandidateSource::ParamEnv(ParamEnvSource::Global), Certainty::Yes))
1278 }
1279 }
1280 }
1281}
1282
1283struct FindParamInClause<'a, 'b, D: SolverDelegate<Interner = I>, I: Interner> {
1284 ecx: &'a mut EvalCtxt<'b, D>,
1285 param_env: I::ParamEnv,
1286 universes: Vec<Option<ty::UniverseIndex>>,
1287 recursion_depth: usize,
1288}
1289
1290impl<D, I> TypeVisitor<I> for FindParamInClause<'_, '_, D, I>
1291where
1292 D: SolverDelegate<Interner = I>,
1293 I: Interner,
1294{
1295 type Result = ControlFlow<Result<Certainty, NoSolution>>;
1300
1301 fn visit_binder<T: TypeVisitable<I>>(&mut self, t: &ty::Binder<I, T>) -> Self::Result {
1302 self.universes.push(None);
1303 t.super_visit_with(self)?;
1304 self.universes.pop();
1305 ControlFlow::Continue(())
1306 }
1307
1308 fn visit_ty(&mut self, ty: I::Ty) -> Self::Result {
1309 let ty = self.ecx.replace_bound_vars(ty, &mut self.universes);
1310 let Ok(ty) = self.ecx.structurally_normalize_ty(self.param_env, ty) else {
1311 return ControlFlow::Break(Err(NoSolution));
1312 };
1313
1314 match ty.kind() {
1315 ty::Placeholder(p) => {
1316 if p.universe() == ty::UniverseIndex::ROOT {
1317 ControlFlow::Break(Ok(Certainty::Yes))
1318 } else {
1319 ControlFlow::Continue(())
1320 }
1321 }
1322 ty::Infer(_) => ControlFlow::Break(Ok(Certainty::AMBIGUOUS)),
1323 _ if ty.has_type_flags(
1324 TypeFlags::HAS_PLACEHOLDER | TypeFlags::HAS_INFER | TypeFlags::HAS_ALIAS,
1325 ) =>
1326 {
1327 self.recursion_depth += 1;
1328 if self.recursion_depth > self.ecx.cx().recursion_limit() {
1329 return ControlFlow::Break(Ok(Certainty::Maybe {
1330 cause: MaybeCause::Overflow {
1331 suggest_increasing_limit: true,
1332 keep_constraints: false,
1333 },
1334 opaque_types_jank: OpaqueTypesJank::AllGood,
1335 }));
1336 }
1337 let result = ty.super_visit_with(self);
1338 self.recursion_depth -= 1;
1339 result
1340 }
1341 _ => ControlFlow::Continue(()),
1342 }
1343 }
1344
1345 fn visit_const(&mut self, ct: I::Const) -> Self::Result {
1346 let ct = self.ecx.replace_bound_vars(ct, &mut self.universes);
1347 let Ok(ct) = self.ecx.structurally_normalize_const(self.param_env, ct) else {
1348 return ControlFlow::Break(Err(NoSolution));
1349 };
1350
1351 match ct.kind() {
1352 ty::ConstKind::Placeholder(p) => {
1353 if p.universe() == ty::UniverseIndex::ROOT {
1354 ControlFlow::Break(Ok(Certainty::Yes))
1355 } else {
1356 ControlFlow::Continue(())
1357 }
1358 }
1359 ty::ConstKind::Infer(_) => ControlFlow::Break(Ok(Certainty::AMBIGUOUS)),
1360 _ if ct.has_type_flags(
1361 TypeFlags::HAS_PLACEHOLDER | TypeFlags::HAS_INFER | TypeFlags::HAS_ALIAS,
1362 ) =>
1363 {
1364 ct.super_visit_with(self)
1366 }
1367 _ => ControlFlow::Continue(()),
1368 }
1369 }
1370
1371 fn visit_region(&mut self, r: I::Region) -> Self::Result {
1372 match self.ecx.eager_resolve_region(r).kind() {
1373 ty::ReStatic | ty::ReError(_) | ty::ReBound(..) => ControlFlow::Continue(()),
1374 ty::RePlaceholder(p) => {
1375 if p.universe() == ty::UniverseIndex::ROOT {
1376 ControlFlow::Break(Ok(Certainty::Yes))
1377 } else {
1378 ControlFlow::Continue(())
1379 }
1380 }
1381 ty::ReVar(_) => ControlFlow::Break(Ok(Certainty::Yes)),
1382 ty::ReErased | ty::ReEarlyParam(_) | ty::ReLateParam(_) => {
1383 {
::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")
1384 }
1385 }
1386 }
1387}