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, 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 match structural_traits::predicates_for_object_candidate(
91 ecx,
92 goal.param_env,
93 goal.predicate.trait_ref(cx),
94 bounds,
95 ) {
96 Ok(requirements) => {
97 ecx.add_goals(GoalSource::ImplWhereBound, requirements);
98 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
99 }
100 Err(_) => {
101 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
102 }
103 }
104 })
105 }
106
107 fn consider_additional_alias_assumptions(
111 ecx: &mut EvalCtxt<'_, D>,
112 goal: Goal<I, Self>,
113 alias_ty: ty::AliasTy<I>,
114 ) -> Vec<Candidate<I>>;
115
116 fn probe_and_consider_param_env_candidate(
117 ecx: &mut EvalCtxt<'_, D>,
118 goal: Goal<I, Self>,
119 assumption: I::Clause,
120 ) -> Result<Candidate<I>, CandidateHeadUsages> {
121 match Self::fast_reject_assumption(ecx, goal, assumption) {
122 Ok(()) => {}
123 Err(NoSolution) => return Err(CandidateHeadUsages::default()),
124 }
125
126 let source = Cell::new(CandidateSource::ParamEnv(ParamEnvSource::Global));
133 let (result, head_usages) = ecx
134 .probe(|result: &QueryResult<I>| inspect::ProbeKind::TraitCandidate {
135 source: source.get(),
136 result: *result,
137 })
138 .enter_single_candidate(|ecx| {
139 Self::match_assumption(ecx, goal, assumption, |ecx| {
140 ecx.try_evaluate_added_goals()?;
141 source.set(ecx.characterize_param_env_assumption(goal.param_env, assumption)?);
142 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
143 })
144 });
145
146 match result {
147 Ok(result) => Ok(Candidate { source: source.get(), result, head_usages }),
148 Err(NoSolution) => Err(head_usages),
149 }
150 }
151
152 fn probe_and_match_goal_against_assumption(
157 ecx: &mut EvalCtxt<'_, D>,
158 source: CandidateSource<I>,
159 goal: Goal<I, Self>,
160 assumption: I::Clause,
161 then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResult<I>,
162 ) -> Result<Candidate<I>, NoSolution> {
163 Self::fast_reject_assumption(ecx, goal, assumption)?;
164
165 ecx.probe_trait_candidate(source)
166 .enter(|ecx| Self::match_assumption(ecx, goal, assumption, then))
167 }
168
169 fn fast_reject_assumption(
172 ecx: &mut EvalCtxt<'_, D>,
173 goal: Goal<I, Self>,
174 assumption: I::Clause,
175 ) -> Result<(), NoSolution>;
176
177 fn match_assumption(
179 ecx: &mut EvalCtxt<'_, D>,
180 goal: Goal<I, Self>,
181 assumption: I::Clause,
182 then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResult<I>,
183 ) -> QueryResult<I>;
184
185 fn consider_impl_candidate(
186 ecx: &mut EvalCtxt<'_, D>,
187 goal: Goal<I, Self>,
188 impl_def_id: I::ImplId,
189 then: impl FnOnce(&mut EvalCtxt<'_, D>, Certainty) -> QueryResult<I>,
190 ) -> Result<Candidate<I>, NoSolution>;
191
192 fn consider_error_guaranteed_candidate(
199 ecx: &mut EvalCtxt<'_, D>,
200 guar: I::ErrorGuaranteed,
201 ) -> Result<Candidate<I>, NoSolution>;
202
203 fn consider_auto_trait_candidate(
208 ecx: &mut EvalCtxt<'_, D>,
209 goal: Goal<I, Self>,
210 ) -> Result<Candidate<I>, NoSolution>;
211
212 fn consider_trait_alias_candidate(
214 ecx: &mut EvalCtxt<'_, D>,
215 goal: Goal<I, Self>,
216 ) -> Result<Candidate<I>, NoSolution>;
217
218 fn consider_builtin_sizedness_candidates(
224 ecx: &mut EvalCtxt<'_, D>,
225 goal: Goal<I, Self>,
226 sizedness: SizedTraitKind,
227 ) -> Result<Candidate<I>, NoSolution>;
228
229 fn consider_builtin_copy_clone_candidate(
234 ecx: &mut EvalCtxt<'_, D>,
235 goal: Goal<I, Self>,
236 ) -> Result<Candidate<I>, NoSolution>;
237
238 fn consider_builtin_fn_ptr_trait_candidate(
240 ecx: &mut EvalCtxt<'_, D>,
241 goal: Goal<I, Self>,
242 ) -> Result<Candidate<I>, NoSolution>;
243
244 fn consider_builtin_fn_trait_candidates(
247 ecx: &mut EvalCtxt<'_, D>,
248 goal: Goal<I, Self>,
249 kind: ty::ClosureKind,
250 ) -> Result<Candidate<I>, NoSolution>;
251
252 fn consider_builtin_async_fn_trait_candidates(
255 ecx: &mut EvalCtxt<'_, D>,
256 goal: Goal<I, Self>,
257 kind: ty::ClosureKind,
258 ) -> Result<Candidate<I>, NoSolution>;
259
260 fn consider_builtin_async_fn_kind_helper_candidate(
264 ecx: &mut EvalCtxt<'_, D>,
265 goal: Goal<I, Self>,
266 ) -> Result<Candidate<I>, NoSolution>;
267
268 fn consider_builtin_tuple_candidate(
270 ecx: &mut EvalCtxt<'_, D>,
271 goal: Goal<I, Self>,
272 ) -> Result<Candidate<I>, NoSolution>;
273
274 fn consider_builtin_pointee_candidate(
280 ecx: &mut EvalCtxt<'_, D>,
281 goal: Goal<I, Self>,
282 ) -> Result<Candidate<I>, NoSolution>;
283
284 fn consider_builtin_future_candidate(
288 ecx: &mut EvalCtxt<'_, D>,
289 goal: Goal<I, Self>,
290 ) -> Result<Candidate<I>, NoSolution>;
291
292 fn consider_builtin_iterator_candidate(
296 ecx: &mut EvalCtxt<'_, D>,
297 goal: Goal<I, Self>,
298 ) -> Result<Candidate<I>, NoSolution>;
299
300 fn consider_builtin_fused_iterator_candidate(
303 ecx: &mut EvalCtxt<'_, D>,
304 goal: Goal<I, Self>,
305 ) -> Result<Candidate<I>, NoSolution>;
306
307 fn consider_builtin_async_iterator_candidate(
308 ecx: &mut EvalCtxt<'_, D>,
309 goal: Goal<I, Self>,
310 ) -> Result<Candidate<I>, NoSolution>;
311
312 fn consider_builtin_coroutine_candidate(
316 ecx: &mut EvalCtxt<'_, D>,
317 goal: Goal<I, Self>,
318 ) -> Result<Candidate<I>, NoSolution>;
319
320 fn consider_builtin_discriminant_kind_candidate(
321 ecx: &mut EvalCtxt<'_, D>,
322 goal: Goal<I, Self>,
323 ) -> Result<Candidate<I>, NoSolution>;
324
325 fn consider_builtin_destruct_candidate(
326 ecx: &mut EvalCtxt<'_, D>,
327 goal: Goal<I, Self>,
328 ) -> Result<Candidate<I>, NoSolution>;
329
330 fn consider_builtin_transmute_candidate(
331 ecx: &mut EvalCtxt<'_, D>,
332 goal: Goal<I, Self>,
333 ) -> Result<Candidate<I>, NoSolution>;
334
335 fn consider_builtin_bikeshed_guaranteed_no_drop_candidate(
336 ecx: &mut EvalCtxt<'_, D>,
337 goal: Goal<I, Self>,
338 ) -> Result<Candidate<I>, NoSolution>;
339
340 fn consider_structural_builtin_unsize_candidates(
348 ecx: &mut EvalCtxt<'_, D>,
349 goal: Goal<I, Self>,
350 ) -> Vec<Candidate<I>>;
351
352 fn consider_builtin_field_candidate(
353 ecx: &mut EvalCtxt<'_, D>,
354 goal: Goal<I, Self>,
355 ) -> Result<Candidate<I>, NoSolution>;
356}
357
358pub(super) enum AssembleCandidatesFrom {
366 All,
367 EnvAndBounds,
371}
372
373impl AssembleCandidatesFrom {
374 fn should_assemble_impl_candidates(&self) -> bool {
375 match self {
376 AssembleCandidatesFrom::All => true,
377 AssembleCandidatesFrom::EnvAndBounds => false,
378 }
379 }
380}
381
382#[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)]
391pub(super) struct FailedCandidateInfo {
392 pub param_env_head_usages: CandidateHeadUsages,
393}
394
395impl<D, I> EvalCtxt<'_, D>
396where
397 D: SolverDelegate<Interner = I>,
398 I: Interner,
399{
400 pub(super) fn assemble_and_evaluate_candidates<G: GoalKind<D>>(
401 &mut self,
402 goal: Goal<I, G>,
403 assemble_from: AssembleCandidatesFrom,
404 ) -> (Vec<Candidate<I>>, FailedCandidateInfo) {
405 let mut candidates = ::alloc::vec::Vec::new()vec![];
406 let mut failed_candidate_info =
407 FailedCandidateInfo { param_env_head_usages: CandidateHeadUsages::default() };
408 let Ok(normalized_self_ty) =
409 self.structurally_normalize_ty(goal.param_env, goal.predicate.self_ty())
410 else {
411 return (candidates, failed_candidate_info);
412 };
413
414 let goal: Goal<I, G> = goal
415 .with(self.cx(), goal.predicate.with_replaced_self_ty(self.cx(), normalized_self_ty));
416
417 if normalized_self_ty.is_ty_var() {
418 {
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:418",
"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(418u32),
::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");
419 self.try_assemble_bounds_via_registered_opaques(goal, assemble_from, &mut candidates);
420 return (candidates, failed_candidate_info);
421 }
422
423 let goal = self.resolve_vars_if_possible(goal);
426
427 if let TypingMode::Coherence = self.typing_mode()
428 && let Ok(candidate) = self.consider_coherence_unknowable_candidate(goal)
429 {
430 candidates.push(candidate);
431 return (candidates, failed_candidate_info);
432 }
433
434 self.assemble_alias_bound_candidates(goal, &mut candidates);
435 self.assemble_param_env_candidates(goal, &mut candidates, &mut failed_candidate_info);
436
437 match assemble_from {
438 AssembleCandidatesFrom::All => {
439 self.assemble_builtin_impl_candidates(goal, &mut candidates);
440 if TypingMode::Coherence == self.typing_mode()
452 || !candidates.iter().any(|c| {
453 #[allow(non_exhaustive_omitted_patterns)] match c.source {
CandidateSource::ParamEnv(ParamEnvSource::NonGlobal) |
CandidateSource::AliasBound(_) => true,
_ => false,
}matches!(
454 c.source,
455 CandidateSource::ParamEnv(ParamEnvSource::NonGlobal)
456 | CandidateSource::AliasBound(_)
457 ) && has_no_inference_or_external_constraints(c.result)
458 })
459 {
460 self.assemble_impl_candidates(goal, &mut candidates);
461 self.assemble_object_bound_candidates(goal, &mut candidates);
462 }
463 }
464 AssembleCandidatesFrom::EnvAndBounds => {
465 if #[allow(non_exhaustive_omitted_patterns)] match normalized_self_ty.kind() {
ty::Dynamic(..) => true,
_ => false,
}matches!(normalized_self_ty.kind(), ty::Dynamic(..))
469 && !candidates.iter().any(|c| #[allow(non_exhaustive_omitted_patterns)] match c.source {
CandidateSource::ParamEnv(_) => true,
_ => false,
}matches!(c.source, CandidateSource::ParamEnv(_)))
470 {
471 self.assemble_object_bound_candidates(goal, &mut candidates);
472 }
473 }
474 }
475
476 (candidates, failed_candidate_info)
477 }
478
479 pub(super) fn forced_ambiguity(
480 &mut self,
481 cause: MaybeCause,
482 ) -> Result<Candidate<I>, NoSolution> {
483 let source = CandidateSource::BuiltinImpl(BuiltinImplSource::Misc);
492 let certainty = Certainty::Maybe { cause, opaque_types_jank: OpaqueTypesJank::AllGood };
493 self.probe_trait_candidate(source)
494 .enter(|this| this.evaluate_added_goals_and_make_canonical_response(certainty))
495 }
496
497 #[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(497u32),
::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)]
498 fn assemble_impl_candidates<G: GoalKind<D>>(
499 &mut self,
500 goal: Goal<I, G>,
501 candidates: &mut Vec<Candidate<I>>,
502 ) {
503 let cx = self.cx();
504 cx.for_each_relevant_impl(
505 goal.predicate.trait_def_id(cx),
506 goal.predicate.self_ty(),
507 |impl_def_id| {
508 if cx.impl_is_default(impl_def_id) {
512 return;
513 }
514 match G::consider_impl_candidate(self, goal, impl_def_id, |ecx, certainty| {
515 ecx.evaluate_added_goals_and_make_canonical_response(certainty)
516 }) {
517 Ok(candidate) => candidates.push(candidate),
518 Err(NoSolution) => (),
519 }
520 },
521 );
522 }
523
524 #[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(524u32),
::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)]
525 fn assemble_builtin_impl_candidates<G: GoalKind<D>>(
526 &mut self,
527 goal: Goal<I, G>,
528 candidates: &mut Vec<Candidate<I>>,
529 ) {
530 let cx = self.cx();
531 let trait_def_id = goal.predicate.trait_def_id(cx);
532
533 let result = if let Err(guar) = goal.predicate.error_reported() {
541 G::consider_error_guaranteed_candidate(self, guar)
542 } else if cx.trait_is_auto(trait_def_id) {
543 G::consider_auto_trait_candidate(self, goal)
544 } else if cx.trait_is_alias(trait_def_id) {
545 G::consider_trait_alias_candidate(self, goal)
546 } else {
547 match cx.as_trait_lang_item(trait_def_id) {
548 Some(SolverTraitLangItem::Sized) => {
549 G::consider_builtin_sizedness_candidates(self, goal, SizedTraitKind::Sized)
550 }
551 Some(SolverTraitLangItem::MetaSized) => {
552 G::consider_builtin_sizedness_candidates(self, goal, SizedTraitKind::MetaSized)
553 }
554 Some(SolverTraitLangItem::PointeeSized) => {
555 unreachable!("`PointeeSized` is removed during lowering");
556 }
557 Some(
558 SolverTraitLangItem::Copy
559 | SolverTraitLangItem::Clone
560 | SolverTraitLangItem::TrivialClone,
561 ) => G::consider_builtin_copy_clone_candidate(self, goal),
562 Some(SolverTraitLangItem::Fn) => {
563 G::consider_builtin_fn_trait_candidates(self, goal, ty::ClosureKind::Fn)
564 }
565 Some(SolverTraitLangItem::FnMut) => {
566 G::consider_builtin_fn_trait_candidates(self, goal, ty::ClosureKind::FnMut)
567 }
568 Some(SolverTraitLangItem::FnOnce) => {
569 G::consider_builtin_fn_trait_candidates(self, goal, ty::ClosureKind::FnOnce)
570 }
571 Some(SolverTraitLangItem::AsyncFn) => {
572 G::consider_builtin_async_fn_trait_candidates(self, goal, ty::ClosureKind::Fn)
573 }
574 Some(SolverTraitLangItem::AsyncFnMut) => {
575 G::consider_builtin_async_fn_trait_candidates(
576 self,
577 goal,
578 ty::ClosureKind::FnMut,
579 )
580 }
581 Some(SolverTraitLangItem::AsyncFnOnce) => {
582 G::consider_builtin_async_fn_trait_candidates(
583 self,
584 goal,
585 ty::ClosureKind::FnOnce,
586 )
587 }
588 Some(SolverTraitLangItem::FnPtrTrait) => {
589 G::consider_builtin_fn_ptr_trait_candidate(self, goal)
590 }
591 Some(SolverTraitLangItem::AsyncFnKindHelper) => {
592 G::consider_builtin_async_fn_kind_helper_candidate(self, goal)
593 }
594 Some(SolverTraitLangItem::Tuple) => G::consider_builtin_tuple_candidate(self, goal),
595 Some(SolverTraitLangItem::PointeeTrait) => {
596 G::consider_builtin_pointee_candidate(self, goal)
597 }
598 Some(SolverTraitLangItem::Future) => {
599 G::consider_builtin_future_candidate(self, goal)
600 }
601 Some(SolverTraitLangItem::Iterator) => {
602 G::consider_builtin_iterator_candidate(self, goal)
603 }
604 Some(SolverTraitLangItem::FusedIterator) => {
605 G::consider_builtin_fused_iterator_candidate(self, goal)
606 }
607 Some(SolverTraitLangItem::AsyncIterator) => {
608 G::consider_builtin_async_iterator_candidate(self, goal)
609 }
610 Some(SolverTraitLangItem::Coroutine) => {
611 G::consider_builtin_coroutine_candidate(self, goal)
612 }
613 Some(SolverTraitLangItem::DiscriminantKind) => {
614 G::consider_builtin_discriminant_kind_candidate(self, goal)
615 }
616 Some(SolverTraitLangItem::Destruct) => {
617 G::consider_builtin_destruct_candidate(self, goal)
618 }
619 Some(SolverTraitLangItem::TransmuteTrait) => {
620 G::consider_builtin_transmute_candidate(self, goal)
621 }
622 Some(SolverTraitLangItem::BikeshedGuaranteedNoDrop) => {
623 G::consider_builtin_bikeshed_guaranteed_no_drop_candidate(self, goal)
624 }
625 Some(SolverTraitLangItem::Field) => G::consider_builtin_field_candidate(self, goal),
626 _ => Err(NoSolution),
627 }
628 };
629
630 candidates.extend(result);
631
632 if cx.is_trait_lang_item(trait_def_id, SolverTraitLangItem::Unsize) {
635 candidates.extend(G::consider_structural_builtin_unsize_candidates(self, goal));
636 }
637 }
638
639 #[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(639u32),
::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)]
640 fn assemble_param_env_candidates<G: GoalKind<D>>(
641 &mut self,
642 goal: Goal<I, G>,
643 candidates: &mut Vec<Candidate<I>>,
644 failed_candidate_info: &mut FailedCandidateInfo,
645 ) {
646 for assumption in goal.param_env.caller_bounds().iter() {
647 match G::probe_and_consider_param_env_candidate(self, goal, assumption) {
648 Ok(candidate) => candidates.push(candidate),
649 Err(head_usages) => {
650 failed_candidate_info.param_env_head_usages.merge_usages(head_usages)
651 }
652 }
653 }
654 }
655
656 #[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(656u32),
::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)]
657 fn assemble_alias_bound_candidates<G: GoalKind<D>>(
658 &mut self,
659 goal: Goal<I, G>,
660 candidates: &mut Vec<Candidate<I>>,
661 ) {
662 let () = self.probe(|_| ProbeKind::NormalizedSelfTyAssembly).enter(|ecx| {
663 ecx.assemble_alias_bound_candidates_recur(
664 goal.predicate.self_ty(),
665 goal,
666 candidates,
667 AliasBoundKind::SelfBounds,
668 );
669 });
670 }
671
672 fn assemble_alias_bound_candidates_recur<G: GoalKind<D>>(
682 &mut self,
683 self_ty: I::Ty,
684 goal: Goal<I, G>,
685 candidates: &mut Vec<Candidate<I>>,
686 consider_self_bounds: AliasBoundKind,
687 ) {
688 let (kind, alias_ty) = match self_ty.kind() {
689 ty::Bool
690 | ty::Char
691 | ty::Int(_)
692 | ty::Uint(_)
693 | ty::Float(_)
694 | ty::Adt(_, _)
695 | ty::Foreign(_)
696 | ty::Str
697 | ty::Array(_, _)
698 | ty::Pat(_, _)
699 | ty::Slice(_)
700 | ty::RawPtr(_, _)
701 | ty::Ref(_, _, _)
702 | ty::FnDef(_, _)
703 | ty::FnPtr(..)
704 | ty::UnsafeBinder(_)
705 | ty::Dynamic(..)
706 | ty::Closure(..)
707 | ty::CoroutineClosure(..)
708 | ty::Coroutine(..)
709 | ty::CoroutineWitness(..)
710 | ty::Never
711 | ty::Tuple(_)
712 | ty::Param(_)
713 | ty::Placeholder(..)
714 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
715 | ty::Error(_) => return,
716 ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) | ty::Bound(..) => {
717 {
::core::panicking::panic_fmt(format_args!("unexpected self type for `{0:?}`",
goal));
}panic!("unexpected self type for `{goal:?}`")
718 }
719
720 ty::Infer(ty::TyVar(_)) => {
721 if let Ok(result) =
725 self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
726 {
727 candidates.push(Candidate {
728 source: CandidateSource::AliasBound(consider_self_bounds),
729 result,
730 head_usages: CandidateHeadUsages::default(),
731 });
732 }
733 return;
734 }
735
736 ty::Alias(kind @ (ty::Projection | ty::Opaque), alias_ty) => (kind, alias_ty),
737 ty::Alias(ty::Inherent | ty::Free, _) => {
738 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"));
739 return;
740 }
741 };
742
743 match consider_self_bounds {
744 AliasBoundKind::SelfBounds => {
745 for assumption in self
746 .cx()
747 .item_self_bounds(alias_ty.def_id)
748 .iter_instantiated(self.cx(), alias_ty.args)
749 {
750 candidates.extend(G::probe_and_consider_implied_clause(
751 self,
752 CandidateSource::AliasBound(consider_self_bounds),
753 goal,
754 assumption,
755 [],
756 ));
757 }
758 }
759 AliasBoundKind::NonSelfBounds => {
760 for assumption in self
761 .cx()
762 .item_non_self_bounds(alias_ty.def_id)
763 .iter_instantiated(self.cx(), alias_ty.args)
764 {
765 candidates.extend(G::probe_and_consider_implied_clause(
766 self,
767 CandidateSource::AliasBound(consider_self_bounds),
768 goal,
769 assumption,
770 [],
771 ));
772 }
773 }
774 }
775
776 candidates.extend(G::consider_additional_alias_assumptions(self, goal, alias_ty));
777
778 if kind != ty::Projection {
779 return;
780 }
781
782 match self.structurally_normalize_ty(goal.param_env, alias_ty.self_ty()) {
784 Ok(next_self_ty) => self.assemble_alias_bound_candidates_recur(
785 next_self_ty,
786 goal,
787 candidates,
788 AliasBoundKind::NonSelfBounds,
789 ),
790 Err(NoSolution) => {}
791 }
792 }
793
794 #[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(794u32),
::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)]
795 fn assemble_object_bound_candidates<G: GoalKind<D>>(
796 &mut self,
797 goal: Goal<I, G>,
798 candidates: &mut Vec<Candidate<I>>,
799 ) {
800 let cx = self.cx();
801 if cx.is_sizedness_trait(goal.predicate.trait_def_id(cx)) {
802 return;
805 }
806
807 let self_ty = goal.predicate.self_ty();
808 let bounds = match self_ty.kind() {
809 ty::Bool
810 | ty::Char
811 | ty::Int(_)
812 | ty::Uint(_)
813 | ty::Float(_)
814 | ty::Adt(_, _)
815 | ty::Foreign(_)
816 | ty::Str
817 | ty::Array(_, _)
818 | ty::Pat(_, _)
819 | ty::Slice(_)
820 | ty::RawPtr(_, _)
821 | ty::Ref(_, _, _)
822 | ty::FnDef(_, _)
823 | ty::FnPtr(..)
824 | ty::UnsafeBinder(_)
825 | ty::Alias(..)
826 | ty::Closure(..)
827 | ty::CoroutineClosure(..)
828 | ty::Coroutine(..)
829 | ty::CoroutineWitness(..)
830 | ty::Never
831 | ty::Tuple(_)
832 | ty::Param(_)
833 | ty::Placeholder(..)
834 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
835 | ty::Error(_) => return,
836 ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_))
837 | ty::Bound(..) => panic!("unexpected self type for `{goal:?}`"),
838 ty::Dynamic(bounds, ..) => bounds,
839 };
840
841 if bounds.principal_def_id().is_some_and(|def_id| !cx.trait_is_dyn_compatible(def_id)) {
843 return;
844 }
845
846 for bound in bounds.iter() {
850 match bound.skip_binder() {
851 ty::ExistentialPredicate::Trait(_) => {
852 }
854 ty::ExistentialPredicate::Projection(_)
855 | ty::ExistentialPredicate::AutoTrait(_) => {
856 candidates.extend(G::probe_and_consider_object_bound_candidate(
857 self,
858 CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
859 goal,
860 bound.with_self_ty(cx, self_ty),
861 ));
862 }
863 }
864 }
865
866 if let Some(principal) = bounds.principal() {
870 let principal_trait_ref = principal.with_self_ty(cx, self_ty);
871 for (idx, assumption) in elaborate::supertraits(cx, principal_trait_ref).enumerate() {
872 candidates.extend(G::probe_and_consider_object_bound_candidate(
873 self,
874 CandidateSource::BuiltinImpl(BuiltinImplSource::Object(idx)),
875 goal,
876 assumption.upcast(cx),
877 ));
878 }
879 }
880 }
881
882 #[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(888u32),
::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)]
889 fn consider_coherence_unknowable_candidate<G: GoalKind<D>>(
890 &mut self,
891 goal: Goal<I, G>,
892 ) -> Result<Candidate<I>, NoSolution> {
893 self.probe_trait_candidate(CandidateSource::CoherenceUnknowable).enter(|ecx| {
894 let cx = ecx.cx();
895 let trait_ref = goal.predicate.trait_ref(cx);
896 if ecx.trait_ref_is_knowable(goal.param_env, trait_ref)? {
897 Err(NoSolution)
898 } else {
899 let predicate: I::Predicate = trait_ref.upcast(cx);
905 ecx.add_goals(
906 GoalSource::Misc,
907 elaborate::elaborate(cx, [predicate])
908 .skip(1)
909 .map(|predicate| goal.with(cx, predicate)),
910 );
911 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
912 }
913 })
914 }
915}
916
917pub(super) enum AllowInferenceConstraints {
918 Yes,
919 No,
920}
921
922impl<D, I> EvalCtxt<'_, D>
923where
924 D: SolverDelegate<Interner = I>,
925 I: Interner,
926{
927 pub(super) fn filter_specialized_impls(
931 &mut self,
932 allow_inference_constraints: AllowInferenceConstraints,
933 candidates: &mut Vec<Candidate<I>>,
934 ) {
935 match self.typing_mode() {
936 TypingMode::Coherence => return,
937 TypingMode::Analysis { .. }
938 | TypingMode::Borrowck { .. }
939 | TypingMode::PostBorrowckAnalysis { .. }
940 | TypingMode::PostAnalysis => {}
941 }
942
943 let mut i = 0;
944 'outer: while i < candidates.len() {
945 let CandidateSource::Impl(victim_def_id) = candidates[i].source else {
946 i += 1;
947 continue;
948 };
949
950 for (j, c) in candidates.iter().enumerate() {
951 if i == j {
952 continue;
953 }
954
955 let CandidateSource::Impl(other_def_id) = c.source else {
956 continue;
957 };
958
959 if #[allow(non_exhaustive_omitted_patterns)] match allow_inference_constraints {
AllowInferenceConstraints::Yes => true,
_ => false,
}matches!(allow_inference_constraints, AllowInferenceConstraints::Yes)
966 || has_only_region_constraints(c.result)
967 {
968 if self.cx().impl_specializes(other_def_id, victim_def_id) {
969 candidates.remove(i);
970 continue 'outer;
971 }
972 }
973 }
974
975 i += 1;
976 }
977 }
978
979 fn try_assemble_bounds_via_registered_opaques<G: GoalKind<D>>(
991 &mut self,
992 goal: Goal<I, G>,
993 assemble_from: AssembleCandidatesFrom,
994 candidates: &mut Vec<Candidate<I>>,
995 ) {
996 let self_ty = goal.predicate.self_ty();
997 let opaque_types = match self.typing_mode() {
999 TypingMode::Analysis { .. } => self.opaques_with_sub_unified_hidden_type(self_ty),
1000 TypingMode::Coherence
1001 | TypingMode::Borrowck { .. }
1002 | TypingMode::PostBorrowckAnalysis { .. }
1003 | TypingMode::PostAnalysis => ::alloc::vec::Vec::new()vec![],
1004 };
1005
1006 if opaque_types.is_empty() {
1007 candidates.extend(self.forced_ambiguity(MaybeCause::Ambiguity));
1008 return;
1009 }
1010
1011 for &alias_ty in &opaque_types {
1012 {
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:1012",
"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(1012u32),
::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:?}");
1013
1014 struct ReplaceOpaque<I: Interner> {
1015 cx: I,
1016 alias_ty: ty::AliasTy<I>,
1017 self_ty: I::Ty,
1018 }
1019 impl<I: Interner> TypeFolder<I> for ReplaceOpaque<I> {
1020 fn cx(&self) -> I {
1021 self.cx
1022 }
1023 fn fold_ty(&mut self, ty: I::Ty) -> I::Ty {
1024 if let ty::Alias(ty::Opaque, alias_ty) = ty.kind() {
1025 if alias_ty == self.alias_ty {
1026 return self.self_ty;
1027 }
1028 }
1029 ty.super_fold_with(self)
1030 }
1031 }
1032
1033 for item_bound in self
1041 .cx()
1042 .item_self_bounds(alias_ty.def_id)
1043 .iter_instantiated(self.cx(), alias_ty.args)
1044 {
1045 let assumption =
1046 item_bound.fold_with(&mut ReplaceOpaque { cx: self.cx(), alias_ty, self_ty });
1047 candidates.extend(G::probe_and_match_goal_against_assumption(
1048 self,
1049 CandidateSource::AliasBound(AliasBoundKind::SelfBounds),
1050 goal,
1051 assumption,
1052 |ecx| {
1053 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
1056 },
1057 ));
1058 }
1059 }
1060
1061 if assemble_from.should_assemble_impl_candidates() {
1066 let cx = self.cx();
1067 cx.for_each_blanket_impl(goal.predicate.trait_def_id(cx), |impl_def_id| {
1068 if cx.impl_is_default(impl_def_id) {
1072 return;
1073 }
1074
1075 match G::consider_impl_candidate(self, goal, impl_def_id, |ecx, certainty| {
1076 if ecx.shallow_resolve(self_ty).is_ty_var() {
1077 let certainty = certainty.and(Certainty::AMBIGUOUS);
1079 ecx.evaluate_added_goals_and_make_canonical_response(certainty)
1080 } else {
1081 Err(NoSolution)
1087 }
1088 }) {
1089 Ok(candidate) => candidates.push(candidate),
1090 Err(NoSolution) => (),
1091 }
1092 });
1093 }
1094
1095 if candidates.is_empty() {
1096 let source = CandidateSource::BuiltinImpl(BuiltinImplSource::Misc);
1097 let certainty = Certainty::Maybe {
1098 cause: MaybeCause::Ambiguity,
1099 opaque_types_jank: OpaqueTypesJank::ErrorIfRigidSelfTy,
1100 };
1101 candidates
1102 .extend(self.probe_trait_candidate(source).enter(|this| {
1103 this.evaluate_added_goals_and_make_canonical_response(certainty)
1104 }));
1105 }
1106 }
1107
1108 x;#[instrument(level = "debug", skip_all, fields(proven_via, goal), ret)]
1139 pub(super) fn assemble_and_merge_candidates<G: GoalKind<D>>(
1140 &mut self,
1141 proven_via: Option<TraitGoalProvenVia>,
1142 goal: Goal<I, G>,
1143 inject_forced_ambiguity_candidate: impl FnOnce(&mut EvalCtxt<'_, D>) -> Option<QueryResult<I>>,
1144 inject_normalize_to_rigid_candidate: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResult<I>,
1145 ) -> QueryResult<I> {
1146 let Some(proven_via) = proven_via else {
1147 return self.forced_ambiguity(MaybeCause::Ambiguity).map(|cand| cand.result);
1154 };
1155
1156 match proven_via {
1157 TraitGoalProvenVia::ParamEnv | TraitGoalProvenVia::AliasBound => {
1158 let (mut candidates, _) = self
1162 .assemble_and_evaluate_candidates(goal, AssembleCandidatesFrom::EnvAndBounds);
1163 debug!(?candidates);
1164
1165 if candidates.is_empty() {
1168 return inject_normalize_to_rigid_candidate(self);
1169 }
1170
1171 if let Some(result) = inject_forced_ambiguity_candidate(self) {
1174 return result;
1175 }
1176
1177 if candidates.iter().any(|c| matches!(c.source, CandidateSource::ParamEnv(_))) {
1180 candidates.retain(|c| matches!(c.source, CandidateSource::ParamEnv(_)));
1181 }
1182
1183 if let Some((response, _)) = self.try_merge_candidates(&candidates) {
1184 Ok(response)
1185 } else {
1186 self.flounder(&candidates)
1187 }
1188 }
1189 TraitGoalProvenVia::Misc => {
1190 let (mut candidates, _) =
1191 self.assemble_and_evaluate_candidates(goal, AssembleCandidatesFrom::All);
1192
1193 if candidates.iter().any(|c| matches!(c.source, CandidateSource::ParamEnv(_))) {
1196 candidates.retain(|c| matches!(c.source, CandidateSource::ParamEnv(_)));
1197 }
1198
1199 self.filter_specialized_impls(AllowInferenceConstraints::Yes, &mut candidates);
1205 if let Some((response, _)) = self.try_merge_candidates(&candidates) {
1206 Ok(response)
1207 } else {
1208 self.flounder(&candidates)
1209 }
1210 }
1211 }
1212 }
1213
1214 fn characterize_param_env_assumption(
1228 &mut self,
1229 param_env: I::ParamEnv,
1230 assumption: I::Clause,
1231 ) -> Result<CandidateSource<I>, NoSolution> {
1232 if assumption.has_bound_vars() {
1235 return Ok(CandidateSource::ParamEnv(ParamEnvSource::NonGlobal));
1236 }
1237
1238 match assumption.visit_with(&mut FindParamInClause {
1239 ecx: self,
1240 param_env,
1241 universes: ::alloc::vec::Vec::new()vec![],
1242 }) {
1243 ControlFlow::Break(Err(NoSolution)) => Err(NoSolution),
1244 ControlFlow::Break(Ok(())) => Ok(CandidateSource::ParamEnv(ParamEnvSource::NonGlobal)),
1245 ControlFlow::Continue(()) => Ok(CandidateSource::ParamEnv(ParamEnvSource::Global)),
1246 }
1247 }
1248}
1249
1250struct FindParamInClause<'a, 'b, D: SolverDelegate<Interner = I>, I: Interner> {
1251 ecx: &'a mut EvalCtxt<'b, D>,
1252 param_env: I::ParamEnv,
1253 universes: Vec<Option<ty::UniverseIndex>>,
1254}
1255
1256impl<D, I> TypeVisitor<I> for FindParamInClause<'_, '_, D, I>
1257where
1258 D: SolverDelegate<Interner = I>,
1259 I: Interner,
1260{
1261 type Result = ControlFlow<Result<(), NoSolution>>;
1262
1263 fn visit_binder<T: TypeVisitable<I>>(&mut self, t: &ty::Binder<I, T>) -> Self::Result {
1264 self.universes.push(None);
1265 t.super_visit_with(self)?;
1266 self.universes.pop();
1267 ControlFlow::Continue(())
1268 }
1269
1270 fn visit_ty(&mut self, ty: I::Ty) -> Self::Result {
1271 let ty = self.ecx.replace_bound_vars(ty, &mut self.universes);
1272 let Ok(ty) = self.ecx.structurally_normalize_ty(self.param_env, ty) else {
1273 return ControlFlow::Break(Err(NoSolution));
1274 };
1275
1276 if let ty::Placeholder(p) = ty.kind() {
1277 if p.universe() == ty::UniverseIndex::ROOT {
1278 ControlFlow::Break(Ok(()))
1279 } else {
1280 ControlFlow::Continue(())
1281 }
1282 } else if ty.has_type_flags(TypeFlags::HAS_PLACEHOLDER | TypeFlags::HAS_RE_INFER) {
1283 ty.super_visit_with(self)
1284 } else {
1285 ControlFlow::Continue(())
1286 }
1287 }
1288
1289 fn visit_const(&mut self, ct: I::Const) -> Self::Result {
1290 let ct = self.ecx.replace_bound_vars(ct, &mut self.universes);
1291 let Ok(ct) = self.ecx.structurally_normalize_const(self.param_env, ct) else {
1292 return ControlFlow::Break(Err(NoSolution));
1293 };
1294
1295 if let ty::ConstKind::Placeholder(p) = ct.kind() {
1296 if p.universe() == ty::UniverseIndex::ROOT {
1297 ControlFlow::Break(Ok(()))
1298 } else {
1299 ControlFlow::Continue(())
1300 }
1301 } else if ct.has_type_flags(TypeFlags::HAS_PLACEHOLDER | TypeFlags::HAS_RE_INFER) {
1302 ct.super_visit_with(self)
1303 } else {
1304 ControlFlow::Continue(())
1305 }
1306 }
1307
1308 fn visit_region(&mut self, r: I::Region) -> Self::Result {
1309 match self.ecx.eager_resolve_region(r).kind() {
1310 ty::ReStatic | ty::ReError(_) | ty::ReBound(..) => ControlFlow::Continue(()),
1311 ty::RePlaceholder(p) => {
1312 if p.universe() == ty::UniverseIndex::ROOT {
1313 ControlFlow::Break(Ok(()))
1314 } else {
1315 ControlFlow::Continue(())
1316 }
1317 }
1318 ty::ReVar(_) => ControlFlow::Break(Ok(())),
1319 ty::ReErased | ty::ReEarlyParam(_) | ty::ReLateParam(_) => {
1320 {
::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")
1321 }
1322 }
1323 }
1324}