1use std::ops::ControlFlow;
4
5use rustc_data_structures::sso::SsoHashSet;
6use rustc_data_structures::stack::ensure_sufficient_stack;
7use rustc_errors::ErrorGuaranteed;
8use rustc_hir::lang_items::LangItem;
9use rustc_infer::infer::DefineOpaqueTypes;
10use rustc_infer::infer::resolve::OpportunisticRegionResolver;
11use rustc_infer::traits::{ObligationCauseCode, PredicateObligations};
12use rustc_middle::traits::select::OverflowError;
13use rustc_middle::traits::{BuiltinImplSource, ImplSource, ImplSourceUserDefinedData};
14use rustc_middle::ty::fast_reject::DeepRejectCtxt;
15use rustc_middle::ty::{
16 self, FieldInfo, Term, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, TypingMode, Upcast,
17};
18use rustc_middle::{bug, span_bug};
19use rustc_span::sym;
20use tracing::{debug, instrument};
21
22use super::{
23 MismatchedProjectionTypes, Normalized, NormalizedTerm, Obligation, ObligationCause,
24 PredicateObligation, ProjectionCacheEntry, ProjectionCacheKey, Selection, SelectionContext,
25 SelectionError, specialization_graph, translate_args, util,
26};
27use crate::errors::InherentProjectionNormalizationOverflow;
28use crate::infer::{BoundRegionConversionTime, InferOk};
29use crate::traits::normalize::{normalize_with_depth, normalize_with_depth_to};
30use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
31use crate::traits::select::ProjectionMatchesProjection;
32
33pub type PolyProjectionObligation<'tcx> = Obligation<'tcx, ty::PolyProjectionPredicate<'tcx>>;
34
35pub type ProjectionObligation<'tcx> = Obligation<'tcx, ty::ProjectionPredicate<'tcx>>;
36
37pub type ProjectionTermObligation<'tcx> = Obligation<'tcx, ty::AliasTerm<'tcx>>;
38
39pub(super) struct InProgress;
40
41#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ProjectionError<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ProjectionError::TooManyCandidates =>
::core::fmt::Formatter::write_str(f, "TooManyCandidates"),
ProjectionError::TraitSelectionError(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"TraitSelectionError", &__self_0),
}
}
}Debug)]
43pub enum ProjectionError<'tcx> {
44 TooManyCandidates,
46
47 TraitSelectionError(SelectionError<'tcx>),
49}
50
51#[derive(#[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for ProjectionCandidate<'tcx> {
#[inline]
fn eq(&self, other: &ProjectionCandidate<'tcx>) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(ProjectionCandidate::ParamEnv(__self_0),
ProjectionCandidate::ParamEnv(__arg1_0)) =>
__self_0 == __arg1_0,
(ProjectionCandidate::TraitDef(__self_0),
ProjectionCandidate::TraitDef(__arg1_0)) =>
__self_0 == __arg1_0,
(ProjectionCandidate::Object(__self_0),
ProjectionCandidate::Object(__arg1_0)) =>
__self_0 == __arg1_0,
(ProjectionCandidate::Select(__self_0),
ProjectionCandidate::Select(__arg1_0)) =>
__self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for ProjectionCandidate<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _:
::core::cmp::AssertParamIsEq<ty::PolyProjectionPredicate<'tcx>>;
let _:
::core::cmp::AssertParamIsEq<ty::PolyProjectionPredicate<'tcx>>;
let _:
::core::cmp::AssertParamIsEq<ty::PolyProjectionPredicate<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<Selection<'tcx>>;
}
}Eq, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ProjectionCandidate<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ProjectionCandidate::ParamEnv(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ParamEnv", &__self_0),
ProjectionCandidate::TraitDef(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"TraitDef", &__self_0),
ProjectionCandidate::Object(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Object",
&__self_0),
ProjectionCandidate::Select(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Select",
&__self_0),
}
}
}Debug)]
52enum ProjectionCandidate<'tcx> {
53 ParamEnv(ty::PolyProjectionPredicate<'tcx>),
55
56 TraitDef(ty::PolyProjectionPredicate<'tcx>),
59
60 Object(ty::PolyProjectionPredicate<'tcx>),
62
63 Select(Selection<'tcx>),
65}
66
67enum ProjectionCandidateSet<'tcx> {
68 None,
69 Single(ProjectionCandidate<'tcx>),
70 Ambiguous,
71 Error(SelectionError<'tcx>),
72}
73
74impl<'tcx> ProjectionCandidateSet<'tcx> {
75 fn mark_ambiguous(&mut self) {
76 *self = ProjectionCandidateSet::Ambiguous;
77 }
78
79 fn mark_error(&mut self, err: SelectionError<'tcx>) {
80 *self = ProjectionCandidateSet::Error(err);
81 }
82
83 fn push_candidate(&mut self, candidate: ProjectionCandidate<'tcx>) -> bool {
87 let convert_to_ambiguous;
96
97 match self {
98 ProjectionCandidateSet::None => {
99 *self = ProjectionCandidateSet::Single(candidate);
100 return true;
101 }
102
103 ProjectionCandidateSet::Single(current) => {
104 if current == &candidate {
107 return false;
108 }
109
110 match (current, candidate) {
118 (ProjectionCandidate::ParamEnv(..), ProjectionCandidate::ParamEnv(..)) => {
119 convert_to_ambiguous = ()
120 }
121 (ProjectionCandidate::ParamEnv(..), _) => return false,
122 (_, ProjectionCandidate::ParamEnv(..)) => ::rustc_middle::util::bug::bug_fmt(format_args!("should never prefer non-param-env candidates over param-env candidates"))bug!(
123 "should never prefer non-param-env candidates over param-env candidates"
124 ),
125 (_, _) => convert_to_ambiguous = (),
126 }
127 }
128
129 ProjectionCandidateSet::Ambiguous | ProjectionCandidateSet::Error(..) => {
130 return false;
131 }
132 }
133
134 let () = convert_to_ambiguous;
137 *self = ProjectionCandidateSet::Ambiguous;
138 false
139 }
140}
141
142pub(super) enum ProjectAndUnifyResult<'tcx> {
151 Holds(PredicateObligations<'tcx>),
156 FailedNormalization,
159 Recursive,
162 MismatchedProjectionTypes(MismatchedProjectionTypes<'tcx>),
165}
166
167#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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("poly_project_and_unify_term",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(174u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["obligation"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: ProjectAndUnifyResult<'tcx> =
loop {};
return __tracing_attr_fake_return;
}
{
let infcx = selcx.infcx;
let r =
infcx.commit_if_ok(|_snapshot|
{
let placeholder_predicate =
infcx.enter_forall_and_leak_universe(obligation.predicate);
let placeholder_obligation =
obligation.with(infcx.tcx, placeholder_predicate);
match project_and_unify_term(selcx, &placeholder_obligation)
{
ProjectAndUnifyResult::MismatchedProjectionTypes(e) =>
Err(e),
other => Ok(other),
}
});
match r {
Ok(inner) => inner,
Err(err) =>
ProjectAndUnifyResult::MismatchedProjectionTypes(err),
}
}
}
}#[instrument(level = "debug", skip(selcx))]
175pub(super) fn poly_project_and_unify_term<'cx, 'tcx>(
176 selcx: &mut SelectionContext<'cx, 'tcx>,
177 obligation: &PolyProjectionObligation<'tcx>,
178) -> ProjectAndUnifyResult<'tcx> {
179 let infcx = selcx.infcx;
180 let r = infcx.commit_if_ok(|_snapshot| {
181 let placeholder_predicate = infcx.enter_forall_and_leak_universe(obligation.predicate);
182
183 let placeholder_obligation = obligation.with(infcx.tcx, placeholder_predicate);
184 match project_and_unify_term(selcx, &placeholder_obligation) {
185 ProjectAndUnifyResult::MismatchedProjectionTypes(e) => Err(e),
186 other => Ok(other),
187 }
188 });
189
190 match r {
191 Ok(inner) => inner,
192 Err(err) => ProjectAndUnifyResult::MismatchedProjectionTypes(err),
193 }
194}
195
196#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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("project_and_unify_term",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(204u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["obligation"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: ProjectAndUnifyResult<'tcx> =
loop {};
return __tracing_attr_fake_return;
}
{
let mut obligations = PredicateObligations::new();
let infcx = selcx.infcx;
let normalized =
match opt_normalize_projection_term(selcx,
obligation.param_env, obligation.predicate.projection_term,
obligation.cause.clone(), obligation.recursion_depth,
&mut obligations) {
Ok(Some(n)) => n,
Ok(None) =>
return ProjectAndUnifyResult::FailedNormalization,
Err(InProgress) => return ProjectAndUnifyResult::Recursive,
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:224",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(224u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message",
"normalized", "obligations"],
::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!("project_and_unify_type result")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&normalized)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligations)
as &dyn Value))])
});
} else { ; }
};
let actual = obligation.predicate.term;
let InferOk { value: actual, obligations: new } =
selcx.infcx.replace_opaque_types_with_inference_vars(actual,
obligation.cause.body_id, obligation.cause.span,
obligation.param_env);
obligations.extend(new);
match infcx.at(&obligation.cause,
obligation.param_env).eq(DefineOpaqueTypes::Yes, normalized,
actual) {
Ok(InferOk { obligations: inferred_obligations, value: () })
=> {
obligations.extend(inferred_obligations);
ProjectAndUnifyResult::Holds(obligations)
}
Err(err) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:249",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(249u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::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!("equating types encountered error {0:?}",
err) as &dyn Value))])
});
} else { ; }
};
ProjectAndUnifyResult::MismatchedProjectionTypes(MismatchedProjectionTypes {
err,
})
}
}
}
}
}#[instrument(level = "debug", skip(selcx))]
205fn project_and_unify_term<'cx, 'tcx>(
206 selcx: &mut SelectionContext<'cx, 'tcx>,
207 obligation: &ProjectionObligation<'tcx>,
208) -> ProjectAndUnifyResult<'tcx> {
209 let mut obligations = PredicateObligations::new();
210
211 let infcx = selcx.infcx;
212 let normalized = match opt_normalize_projection_term(
213 selcx,
214 obligation.param_env,
215 obligation.predicate.projection_term,
216 obligation.cause.clone(),
217 obligation.recursion_depth,
218 &mut obligations,
219 ) {
220 Ok(Some(n)) => n,
221 Ok(None) => return ProjectAndUnifyResult::FailedNormalization,
222 Err(InProgress) => return ProjectAndUnifyResult::Recursive,
223 };
224 debug!(?normalized, ?obligations, "project_and_unify_type result");
225 let actual = obligation.predicate.term;
226 let InferOk { value: actual, obligations: new } =
230 selcx.infcx.replace_opaque_types_with_inference_vars(
231 actual,
232 obligation.cause.body_id,
233 obligation.cause.span,
234 obligation.param_env,
235 );
236 obligations.extend(new);
237
238 match infcx.at(&obligation.cause, obligation.param_env).eq(
240 DefineOpaqueTypes::Yes,
241 normalized,
242 actual,
243 ) {
244 Ok(InferOk { obligations: inferred_obligations, value: () }) => {
245 obligations.extend(inferred_obligations);
246 ProjectAndUnifyResult::Holds(obligations)
247 }
248 Err(err) => {
249 debug!("equating types encountered error {:?}", err);
250 ProjectAndUnifyResult::MismatchedProjectionTypes(MismatchedProjectionTypes { err })
251 }
252 }
253}
254
255pub fn normalize_projection_term<'a, 'b, 'tcx>(
263 selcx: &'a mut SelectionContext<'b, 'tcx>,
264 param_env: ty::ParamEnv<'tcx>,
265 alias_term: ty::AliasTerm<'tcx>,
266 cause: ObligationCause<'tcx>,
267 depth: usize,
268 obligations: &mut PredicateObligations<'tcx>,
269) -> Term<'tcx> {
270 opt_normalize_projection_term(selcx, param_env, alias_term, cause.clone(), depth, obligations)
271 .ok()
272 .flatten()
273 .unwrap_or_else(move || {
274 selcx
279 .infcx
280 .projection_term_to_infer(param_env, alias_term, cause, depth + 1, obligations)
281 .into()
282 })
283}
284
285#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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("opt_normalize_projection_term",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(296u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["projection_term",
"depth"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&projection_term)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&depth as
&dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
Result<Option<Term<'tcx>>, InProgress> = loop {};
return __tracing_attr_fake_return;
}
{
let infcx = selcx.infcx;
if true {
if !!selcx.infcx.next_trait_solver() {
::core::panicking::panic("assertion failed: !selcx.infcx.next_trait_solver()")
};
};
let projection_term =
infcx.resolve_vars_if_possible(projection_term);
let cache_key =
ProjectionCacheKey::new(projection_term, param_env);
let cache_entry =
infcx.inner.borrow_mut().projection_cache().try_start(cache_key);
match cache_entry {
Ok(()) => {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:319",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(319u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::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!("no cache")
as &dyn Value))])
});
} else { ; }
}
Err(ProjectionCacheEntry::Ambiguous) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:324",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(324u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::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!("found cache entry: ambiguous")
as &dyn Value))])
});
} else { ; }
};
return Ok(None);
}
Err(ProjectionCacheEntry::InProgress) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:336",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(336u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::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!("found cache entry: in-progress")
as &dyn Value))])
});
} else { ; }
};
infcx.inner.borrow_mut().projection_cache().recur(cache_key);
return Err(InProgress);
}
Err(ProjectionCacheEntry::Recur) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:345",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(345u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::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!("recur cache")
as &dyn Value))])
});
} else { ; }
};
return Err(InProgress);
}
Err(ProjectionCacheEntry::NormalizedTerm { ty, complete: _ })
=> {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:360",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(360u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message", "ty"],
::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!("found normalized ty")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&ty) as
&dyn Value))])
});
} else { ; }
};
obligations.extend(ty.obligations);
return Ok(Some(ty.value));
}
Err(ProjectionCacheEntry::Error) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:365",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(365u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::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!("opt_normalize_projection_type: found error")
as &dyn Value))])
});
} else { ; }
};
let result =
normalize_to_error(selcx, param_env, projection_term, cause,
depth);
obligations.extend(result.obligations);
return Ok(Some(result.value));
}
}
let obligation =
Obligation::with_depth(selcx.tcx(), cause.clone(), depth,
param_env, projection_term);
match project(selcx, &obligation) {
Ok(Projected::Progress(Progress {
term: projected_term, obligations: mut projected_obligations
})) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:380",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(380u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::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!("opt_normalize_projection_type: progress")
as &dyn Value))])
});
} else { ; }
};
let projected_term =
selcx.infcx.resolve_vars_if_possible(projected_term);
let mut result =
if projected_term.has_aliases() {
let normalized_ty =
normalize_with_depth_to(selcx, param_env, cause, depth + 1,
projected_term, &mut projected_obligations);
Normalized {
value: normalized_ty,
obligations: projected_obligations,
}
} else {
Normalized {
value: projected_term,
obligations: projected_obligations,
}
};
let mut deduped =
SsoHashSet::with_capacity(result.obligations.len());
result.obligations.retain(|obligation|
deduped.insert(obligation.clone()));
infcx.inner.borrow_mut().projection_cache().insert_term(cache_key,
result.clone());
obligations.extend(result.obligations);
Ok(Some(result.value))
}
Ok(Projected::NoProgress(projected_ty)) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:411",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(411u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::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!("opt_normalize_projection_type: no progress")
as &dyn Value))])
});
} else { ; }
};
let result =
Normalized {
value: projected_ty,
obligations: PredicateObligations::new(),
};
infcx.inner.borrow_mut().projection_cache().insert_term(cache_key,
result.clone());
Ok(Some(result.value))
}
Err(ProjectionError::TooManyCandidates) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:419",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(419u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::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!("opt_normalize_projection_type: too many candidates")
as &dyn Value))])
});
} else { ; }
};
infcx.inner.borrow_mut().projection_cache().ambiguous(cache_key);
Ok(None)
}
Err(ProjectionError::TraitSelectionError(_)) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:424",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(424u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::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!("opt_normalize_projection_type: ERROR")
as &dyn Value))])
});
} else { ; }
};
infcx.inner.borrow_mut().projection_cache().error(cache_key);
let result =
normalize_to_error(selcx, param_env, projection_term, cause,
depth);
obligations.extend(result.obligations);
Ok(Some(result.value))
}
}
}
}
}#[instrument(level = "debug", skip(selcx, param_env, cause, obligations))]
297pub(super) fn opt_normalize_projection_term<'a, 'b, 'tcx>(
298 selcx: &'a mut SelectionContext<'b, 'tcx>,
299 param_env: ty::ParamEnv<'tcx>,
300 projection_term: ty::AliasTerm<'tcx>,
301 cause: ObligationCause<'tcx>,
302 depth: usize,
303 obligations: &mut PredicateObligations<'tcx>,
304) -> Result<Option<Term<'tcx>>, InProgress> {
305 let infcx = selcx.infcx;
306 debug_assert!(!selcx.infcx.next_trait_solver());
307 let projection_term = infcx.resolve_vars_if_possible(projection_term);
308 let cache_key = ProjectionCacheKey::new(projection_term, param_env);
309
310 let cache_entry = infcx.inner.borrow_mut().projection_cache().try_start(cache_key);
318 match cache_entry {
319 Ok(()) => debug!("no cache"),
320 Err(ProjectionCacheEntry::Ambiguous) => {
321 debug!("found cache entry: ambiguous");
325 return Ok(None);
326 }
327 Err(ProjectionCacheEntry::InProgress) => {
328 debug!("found cache entry: in-progress");
337
338 infcx.inner.borrow_mut().projection_cache().recur(cache_key);
342 return Err(InProgress);
343 }
344 Err(ProjectionCacheEntry::Recur) => {
345 debug!("recur cache");
346 return Err(InProgress);
347 }
348 Err(ProjectionCacheEntry::NormalizedTerm { ty, complete: _ }) => {
349 debug!(?ty, "found normalized ty");
361 obligations.extend(ty.obligations);
362 return Ok(Some(ty.value));
363 }
364 Err(ProjectionCacheEntry::Error) => {
365 debug!("opt_normalize_projection_type: found error");
366 let result = normalize_to_error(selcx, param_env, projection_term, cause, depth);
367 obligations.extend(result.obligations);
368 return Ok(Some(result.value));
369 }
370 }
371
372 let obligation =
373 Obligation::with_depth(selcx.tcx(), cause.clone(), depth, param_env, projection_term);
374
375 match project(selcx, &obligation) {
376 Ok(Projected::Progress(Progress {
377 term: projected_term,
378 obligations: mut projected_obligations,
379 })) => {
380 debug!("opt_normalize_projection_type: progress");
381 let projected_term = selcx.infcx.resolve_vars_if_possible(projected_term);
387
388 let mut result = if projected_term.has_aliases() {
389 let normalized_ty = normalize_with_depth_to(
390 selcx,
391 param_env,
392 cause,
393 depth + 1,
394 projected_term,
395 &mut projected_obligations,
396 );
397
398 Normalized { value: normalized_ty, obligations: projected_obligations }
399 } else {
400 Normalized { value: projected_term, obligations: projected_obligations }
401 };
402
403 let mut deduped = SsoHashSet::with_capacity(result.obligations.len());
404 result.obligations.retain(|obligation| deduped.insert(obligation.clone()));
405
406 infcx.inner.borrow_mut().projection_cache().insert_term(cache_key, result.clone());
407 obligations.extend(result.obligations);
408 Ok(Some(result.value))
409 }
410 Ok(Projected::NoProgress(projected_ty)) => {
411 debug!("opt_normalize_projection_type: no progress");
412 let result =
413 Normalized { value: projected_ty, obligations: PredicateObligations::new() };
414 infcx.inner.borrow_mut().projection_cache().insert_term(cache_key, result.clone());
415 Ok(Some(result.value))
417 }
418 Err(ProjectionError::TooManyCandidates) => {
419 debug!("opt_normalize_projection_type: too many candidates");
420 infcx.inner.borrow_mut().projection_cache().ambiguous(cache_key);
421 Ok(None)
422 }
423 Err(ProjectionError::TraitSelectionError(_)) => {
424 debug!("opt_normalize_projection_type: ERROR");
425 infcx.inner.borrow_mut().projection_cache().error(cache_key);
430 let result = normalize_to_error(selcx, param_env, projection_term, cause, depth);
431 obligations.extend(result.obligations);
432 Ok(Some(result.value))
433 }
434 }
435}
436
437fn normalize_to_error<'a, 'tcx>(
458 selcx: &SelectionContext<'a, 'tcx>,
459 param_env: ty::ParamEnv<'tcx>,
460 projection_term: ty::AliasTerm<'tcx>,
461 cause: ObligationCause<'tcx>,
462 depth: usize,
463) -> NormalizedTerm<'tcx> {
464 let trait_ref = ty::Binder::dummy(projection_term.trait_ref(selcx.tcx()));
465 let new_value = match projection_term.kind(selcx.tcx()) {
466 ty::AliasTermKind::ProjectionTy { .. }
467 | ty::AliasTermKind::InherentTy { .. }
468 | ty::AliasTermKind::OpaqueTy { .. }
469 | ty::AliasTermKind::FreeTy { .. } => selcx.infcx.next_ty_var(cause.span).into(),
470 ty::AliasTermKind::FreeConst { .. }
471 | ty::AliasTermKind::InherentConst { .. }
472 | ty::AliasTermKind::UnevaluatedConst { .. }
473 | ty::AliasTermKind::ProjectionConst { .. } => {
474 selcx.infcx.next_const_var(cause.span).into()
475 }
476 };
477 let mut obligations = PredicateObligations::new();
478 obligations.push(Obligation {
479 cause,
480 recursion_depth: depth,
481 param_env,
482 predicate: trait_ref.upcast(selcx.tcx()),
483 });
484 Normalized { value: new_value, obligations }
485}
486
487#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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("normalize_inherent_projection",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(489u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["alias_term",
"depth"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&alias_term)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&depth as
&dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: ty::Term<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = selcx.tcx();
if !tcx.recursion_limit().value_within_limit(depth) {
tcx.dcx().emit_fatal(InherentProjectionNormalizationOverflow {
span: cause.span,
ty: alias_term.to_string(),
});
}
let args =
compute_inherent_assoc_term_args(selcx, param_env, alias_term,
cause.clone(), depth, obligations);
let predicates =
tcx.predicates_of(alias_term.def_id()).instantiate(tcx, args);
for (predicate, span) in predicates {
let predicate =
normalize_with_depth_to(selcx, param_env, cause.clone(),
depth + 1, predicate.skip_norm_wip(), obligations);
let nested_cause =
ObligationCause::new(cause.span, cause.body_id,
ObligationCauseCode::WhereClause(alias_term.def_id(),
span));
obligations.push(Obligation::with_depth(tcx, nested_cause,
depth + 1, param_env, predicate));
}
let term: Term<'tcx> =
if alias_term.kind(tcx).is_type() {
tcx.type_of(alias_term.def_id()).instantiate(tcx,
args).skip_norm_wip().into()
} else {
tcx.const_of_item(alias_term.def_id()).instantiate(tcx,
args).skip_norm_wip().into()
};
let mut term = selcx.infcx.resolve_vars_if_possible(term);
if term.has_aliases() {
term =
normalize_with_depth_to(selcx, param_env, cause.clone(),
depth + 1, term, obligations);
}
term
}
}
}#[instrument(level = "debug", skip(selcx, param_env, cause, obligations))]
490pub fn normalize_inherent_projection<'a, 'b, 'tcx>(
491 selcx: &'a mut SelectionContext<'b, 'tcx>,
492 param_env: ty::ParamEnv<'tcx>,
493 alias_term: ty::AliasTerm<'tcx>,
494 cause: ObligationCause<'tcx>,
495 depth: usize,
496 obligations: &mut PredicateObligations<'tcx>,
497) -> ty::Term<'tcx> {
498 let tcx = selcx.tcx();
499
500 if !tcx.recursion_limit().value_within_limit(depth) {
501 tcx.dcx().emit_fatal(InherentProjectionNormalizationOverflow {
503 span: cause.span,
504 ty: alias_term.to_string(),
505 });
506 }
507
508 let args = compute_inherent_assoc_term_args(
509 selcx,
510 param_env,
511 alias_term,
512 cause.clone(),
513 depth,
514 obligations,
515 );
516
517 let predicates = tcx.predicates_of(alias_term.def_id()).instantiate(tcx, args);
519 for (predicate, span) in predicates {
520 let predicate = normalize_with_depth_to(
521 selcx,
522 param_env,
523 cause.clone(),
524 depth + 1,
525 predicate.skip_norm_wip(),
526 obligations,
527 );
528
529 let nested_cause = ObligationCause::new(
530 cause.span,
531 cause.body_id,
532 ObligationCauseCode::WhereClause(alias_term.def_id(), span),
537 );
538
539 obligations.push(Obligation::with_depth(
540 tcx,
541 nested_cause,
542 depth + 1,
543 param_env,
544 predicate,
545 ));
546 }
547
548 let term: Term<'tcx> = if alias_term.kind(tcx).is_type() {
549 tcx.type_of(alias_term.def_id()).instantiate(tcx, args).skip_norm_wip().into()
550 } else {
551 tcx.const_of_item(alias_term.def_id()).instantiate(tcx, args).skip_norm_wip().into()
552 };
553
554 let mut term = selcx.infcx.resolve_vars_if_possible(term);
555 if term.has_aliases() {
556 term =
557 normalize_with_depth_to(selcx, param_env, cause.clone(), depth + 1, term, obligations);
558 }
559
560 term
561}
562
563pub fn compute_inherent_assoc_term_args<'a, 'b, 'tcx>(
565 selcx: &'a mut SelectionContext<'b, 'tcx>,
566 param_env: ty::ParamEnv<'tcx>,
567 alias_term: ty::AliasTerm<'tcx>,
568 cause: ObligationCause<'tcx>,
569 depth: usize,
570 obligations: &mut PredicateObligations<'tcx>,
571) -> ty::GenericArgsRef<'tcx> {
572 let tcx = selcx.tcx();
573
574 let impl_def_id = tcx.parent(alias_term.def_id());
575 let impl_args = selcx.infcx.fresh_args_for_item(cause.span, impl_def_id);
576
577 let mut impl_ty = tcx.type_of(impl_def_id).instantiate(tcx, impl_args).skip_norm_wip();
578 if !selcx.infcx.next_trait_solver() {
579 impl_ty = normalize_with_depth_to(
580 selcx,
581 param_env,
582 cause.clone(),
583 depth + 1,
584 impl_ty,
585 obligations,
586 );
587 }
588
589 let mut self_ty = alias_term.self_ty();
592 if !selcx.infcx.next_trait_solver() {
593 self_ty = normalize_with_depth_to(
594 selcx,
595 param_env,
596 cause.clone(),
597 depth + 1,
598 self_ty,
599 obligations,
600 );
601 }
602
603 match selcx.infcx.at(&cause, param_env).eq(DefineOpaqueTypes::Yes, impl_ty, self_ty) {
604 Ok(mut ok) => obligations.append(&mut ok.obligations),
605 Err(_) => {
606 tcx.dcx().span_bug(
607 cause.span,
608 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:?} was equal to {1:?} during selection but now it is not",
self_ty, impl_ty))
})format!("{self_ty:?} was equal to {impl_ty:?} during selection but now it is not"),
609 );
610 }
611 }
612
613 alias_term.rebase_inherent_args_onto_impl(impl_args, tcx)
614}
615
616enum Projected<'tcx> {
617 Progress(Progress<'tcx>),
618 NoProgress(ty::Term<'tcx>),
619}
620
621struct Progress<'tcx> {
622 term: ty::Term<'tcx>,
623 obligations: PredicateObligations<'tcx>,
624}
625
626impl<'tcx> Progress<'tcx> {
627 fn error_for_term(
628 tcx: TyCtxt<'tcx>,
629 alias_term: ty::AliasTerm<'tcx>,
630 guar: ErrorGuaranteed,
631 ) -> Self {
632 let err_term = if alias_term.kind(tcx).is_type() {
633 Ty::new_error(tcx, guar).into()
634 } else {
635 ty::Const::new_error(tcx, guar).into()
636 };
637 Progress { term: err_term, obligations: PredicateObligations::new() }
638 }
639
640 fn with_addl_obligations(mut self, mut obligations: PredicateObligations<'tcx>) -> Self {
641 self.obligations.append(&mut obligations);
642 self
643 }
644}
645
646#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::INFO <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::INFO <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("project",
"rustc_trait_selection::traits::project",
::tracing::Level::INFO,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(651u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["obligation"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::INFO <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::INFO <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
Result<Projected<'tcx>, ProjectionError<'tcx>> = loop {};
return __tracing_attr_fake_return;
}
{
if !selcx.tcx().recursion_limit().value_within_limit(obligation.recursion_depth)
{
return Err(ProjectionError::TraitSelectionError(SelectionError::Overflow(OverflowError::Canonical)));
}
if let Err(guar) =
obligation.predicate.non_region_error_reported() {
return Ok(Projected::Progress(Progress::error_for_term(selcx.tcx(),
obligation.predicate, guar)));
}
let mut candidates = ProjectionCandidateSet::None;
assemble_candidates_from_param_env(selcx, obligation,
&mut candidates);
assemble_candidates_from_trait_def(selcx, obligation,
&mut candidates);
assemble_candidates_from_object_ty(selcx, obligation,
&mut candidates);
if let ProjectionCandidateSet::Single(ProjectionCandidate::Object(_))
= candidates
{} else {
assemble_candidates_from_impls(selcx, obligation,
&mut candidates);
};
match candidates {
ProjectionCandidateSet::Single(candidate) => {
confirm_candidate(selcx, obligation, candidate)
}
ProjectionCandidateSet::None => {
let tcx = selcx.tcx();
let term = obligation.predicate.to_term(tcx);
Ok(Projected::NoProgress(term))
}
ProjectionCandidateSet::Error(e) =>
Err(ProjectionError::TraitSelectionError(e)),
ProjectionCandidateSet::Ambiguous =>
Err(ProjectionError::TooManyCandidates),
}
}
}
}#[instrument(level = "info", skip(selcx))]
652fn project<'cx, 'tcx>(
653 selcx: &mut SelectionContext<'cx, 'tcx>,
654 obligation: &ProjectionTermObligation<'tcx>,
655) -> Result<Projected<'tcx>, ProjectionError<'tcx>> {
656 if !selcx.tcx().recursion_limit().value_within_limit(obligation.recursion_depth) {
657 return Err(ProjectionError::TraitSelectionError(SelectionError::Overflow(
660 OverflowError::Canonical,
661 )));
662 }
663
664 if let Err(guar) = obligation.predicate.non_region_error_reported() {
667 return Ok(Projected::Progress(Progress::error_for_term(
668 selcx.tcx(),
669 obligation.predicate,
670 guar,
671 )));
672 }
673
674 let mut candidates = ProjectionCandidateSet::None;
675
676 assemble_candidates_from_param_env(selcx, obligation, &mut candidates);
680
681 assemble_candidates_from_trait_def(selcx, obligation, &mut candidates);
682
683 assemble_candidates_from_object_ty(selcx, obligation, &mut candidates);
684
685 if let ProjectionCandidateSet::Single(ProjectionCandidate::Object(_)) = candidates {
686 } else {
691 assemble_candidates_from_impls(selcx, obligation, &mut candidates);
692 };
693
694 match candidates {
695 ProjectionCandidateSet::Single(candidate) => {
696 confirm_candidate(selcx, obligation, candidate)
697 }
698 ProjectionCandidateSet::None => {
699 let tcx = selcx.tcx();
700 let term = obligation.predicate.to_term(tcx);
701 Ok(Projected::NoProgress(term))
702 }
703 ProjectionCandidateSet::Error(e) => Err(ProjectionError::TraitSelectionError(e)),
705 ProjectionCandidateSet::Ambiguous => Err(ProjectionError::TooManyCandidates),
708 }
709}
710
711fn assemble_candidates_from_param_env<'cx, 'tcx>(
715 selcx: &mut SelectionContext<'cx, 'tcx>,
716 obligation: &ProjectionTermObligation<'tcx>,
717 candidate_set: &mut ProjectionCandidateSet<'tcx>,
718) {
719 assemble_candidates_from_predicates(
720 selcx,
721 obligation,
722 candidate_set,
723 ProjectionCandidate::ParamEnv,
724 obligation.param_env.caller_bounds().iter(),
725 false,
726 );
727}
728
729fn assemble_candidates_from_trait_def<'cx, 'tcx>(
740 selcx: &mut SelectionContext<'cx, 'tcx>,
741 obligation: &ProjectionTermObligation<'tcx>,
742 candidate_set: &mut ProjectionCandidateSet<'tcx>,
743) {
744 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:744",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(744u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::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!("assemble_candidates_from_trait_def(..)")
as &dyn Value))])
});
} else { ; }
};debug!("assemble_candidates_from_trait_def(..)");
745 let mut ambiguous = false;
746 let _ = selcx.for_each_item_bound(
747 obligation.predicate.self_ty(),
748 |selcx, clause, _, _| {
749 let Some(clause) = clause.as_projection_clause() else {
750 return ControlFlow::Continue(());
751 };
752 if clause.item_def_id() != obligation.predicate.def_id() {
753 return ControlFlow::Continue(());
754 }
755
756 let is_match =
757 selcx.infcx.probe(|_| selcx.match_projection_projections(obligation, clause, true));
758
759 match is_match {
760 ProjectionMatchesProjection::Yes => {
761 candidate_set.push_candidate(ProjectionCandidate::TraitDef(clause));
762
763 if !obligation.predicate.has_non_region_infer() {
764 return ControlFlow::Break(());
768 }
769 }
770 ProjectionMatchesProjection::Ambiguous => {
771 candidate_set.mark_ambiguous();
772 }
773 ProjectionMatchesProjection::No => {}
774 }
775
776 ControlFlow::Continue(())
777 },
778 || ambiguous = true,
781 );
782
783 if ambiguous {
784 candidate_set.mark_ambiguous();
785 }
786}
787
788fn assemble_candidates_from_object_ty<'cx, 'tcx>(
798 selcx: &mut SelectionContext<'cx, 'tcx>,
799 obligation: &ProjectionTermObligation<'tcx>,
800 candidate_set: &mut ProjectionCandidateSet<'tcx>,
801) {
802 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:802",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(802u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::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!("assemble_candidates_from_object_ty(..)")
as &dyn Value))])
});
} else { ; }
};debug!("assemble_candidates_from_object_ty(..)");
803
804 let tcx = selcx.tcx();
805
806 let self_ty = obligation.predicate.self_ty();
807 let object_ty = selcx.infcx.shallow_resolve(self_ty);
808 let data = match object_ty.kind() {
809 ty::Dynamic(data, ..) => data,
810 ty::Infer(ty::TyVar(_)) => {
811 candidate_set.mark_ambiguous();
814 return;
815 }
816 _ => return,
817 };
818 let env_predicates = data
819 .projection_bounds()
820 .filter(|bound| bound.item_def_id() == obligation.predicate.def_id())
821 .map(|p| p.with_self_ty(tcx, object_ty).upcast(tcx));
822
823 assemble_candidates_from_predicates(
824 selcx,
825 obligation,
826 candidate_set,
827 ProjectionCandidate::Object,
828 env_predicates,
829 false,
830 );
831}
832
833#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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_candidates_from_predicates",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(833u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["obligation"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let infcx = selcx.infcx;
let drcx = DeepRejectCtxt::relate_rigid_rigid(selcx.tcx());
for predicate in env_predicates {
let bound_predicate = predicate.kind();
if let ty::ClauseKind::Projection(data) =
predicate.kind().skip_binder() {
let data = bound_predicate.rebind(data);
if data.item_def_id() != obligation.predicate.def_id() {
continue;
}
if !drcx.args_may_unify(obligation.predicate.args,
data.skip_binder().projection_term.args) {
continue;
}
let is_match =
infcx.probe(|_|
{
selcx.match_projection_projections(obligation, data,
potentially_unnormalized_candidates)
});
match is_match {
ProjectionMatchesProjection::Yes => {
candidate_set.push_candidate(ctor(data));
if potentially_unnormalized_candidates &&
!obligation.predicate.has_non_region_infer() {
return;
}
}
ProjectionMatchesProjection::Ambiguous => {
candidate_set.mark_ambiguous();
}
ProjectionMatchesProjection::No => {}
}
}
}
}
}
}#[instrument(
834 level = "debug",
835 skip(selcx, candidate_set, ctor, env_predicates, potentially_unnormalized_candidates)
836)]
837fn assemble_candidates_from_predicates<'cx, 'tcx>(
838 selcx: &mut SelectionContext<'cx, 'tcx>,
839 obligation: &ProjectionTermObligation<'tcx>,
840 candidate_set: &mut ProjectionCandidateSet<'tcx>,
841 ctor: fn(ty::PolyProjectionPredicate<'tcx>) -> ProjectionCandidate<'tcx>,
842 env_predicates: impl Iterator<Item = ty::Clause<'tcx>>,
843 potentially_unnormalized_candidates: bool,
844) {
845 let infcx = selcx.infcx;
846 let drcx = DeepRejectCtxt::relate_rigid_rigid(selcx.tcx());
847 for predicate in env_predicates {
848 let bound_predicate = predicate.kind();
849 if let ty::ClauseKind::Projection(data) = predicate.kind().skip_binder() {
850 let data = bound_predicate.rebind(data);
851 if data.item_def_id() != obligation.predicate.def_id() {
852 continue;
853 }
854
855 if !drcx
856 .args_may_unify(obligation.predicate.args, data.skip_binder().projection_term.args)
857 {
858 continue;
859 }
860
861 let is_match = infcx.probe(|_| {
862 selcx.match_projection_projections(
863 obligation,
864 data,
865 potentially_unnormalized_candidates,
866 )
867 });
868
869 match is_match {
870 ProjectionMatchesProjection::Yes => {
871 candidate_set.push_candidate(ctor(data));
872
873 if potentially_unnormalized_candidates
874 && !obligation.predicate.has_non_region_infer()
875 {
876 return;
880 }
881 }
882 ProjectionMatchesProjection::Ambiguous => {
883 candidate_set.mark_ambiguous();
884 }
885 ProjectionMatchesProjection::No => {}
886 }
887 }
888 }
889}
890
891#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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_candidates_from_impls",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(891u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::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::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::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 trait_ref = obligation.predicate.trait_ref(selcx.tcx());
let trait_obligation = obligation.with(selcx.tcx(), trait_ref);
let _ =
selcx.infcx.commit_if_ok(|_|
{
let impl_source =
match selcx.select(&trait_obligation) {
Ok(Some(impl_source)) => impl_source,
Ok(None) => {
candidate_set.mark_ambiguous();
return Err(());
}
Err(e) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:909",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(909u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message", "error"],
::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!("selection error")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&e) as
&dyn Value))])
});
} else { ; }
};
candidate_set.mark_error(e);
return Err(());
}
};
let eligible =
match &impl_source {
ImplSource::UserDefined(impl_data) => {
match specialization_graph::assoc_def(selcx.tcx(),
impl_data.impl_def_id, obligation.predicate.def_id()) {
Ok(node_item) => {
if node_item.is_final() {
true
} else {
match selcx.infcx.typing_mode() {
TypingMode::Coherence | TypingMode::Analysis { .. } |
TypingMode::Borrowck { .. } |
TypingMode::PostBorrowckAnalysis { .. } => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:958",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(958u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message",
"assoc_ty", "obligation.predicate"],
::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!("not eligible due to default")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&selcx.tcx().def_path_str(node_item.item.def_id))
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligation.predicate)
as &dyn Value))])
});
} else { ; }
};
false
}
TypingMode::PostAnalysis => {
let poly_trait_ref =
selcx.infcx.resolve_vars_if_possible(trait_ref);
!poly_trait_ref.still_further_specializable()
}
}
}
}
Err(ErrorGuaranteed { .. }) => true,
}
}
ImplSource::Builtin(BuiltinImplSource::Misc |
BuiltinImplSource::Trivial, _) => {
let self_ty =
selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
let tcx = selcx.tcx();
match selcx.tcx().as_lang_item(trait_ref.def_id) {
Some(LangItem::Coroutine | LangItem::Future |
LangItem::Iterator | LangItem::AsyncIterator |
LangItem::Field | LangItem::Fn | LangItem::FnMut |
LangItem::FnOnce | LangItem::AsyncFn | LangItem::AsyncFnMut
| LangItem::AsyncFnOnce) => true,
Some(LangItem::AsyncFnKindHelper) => {
if obligation.predicate.args.type_at(0).is_ty_var() ||
obligation.predicate.args.type_at(4).is_ty_var() ||
obligation.predicate.args.type_at(5).is_ty_var() {
candidate_set.mark_ambiguous();
true
} else {
obligation.predicate.args.type_at(0).to_opt_closure_kind().is_some()
&&
obligation.predicate.args.type_at(1).to_opt_closure_kind().is_some()
}
}
Some(LangItem::DiscriminantKind) =>
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::Dynamic(..) | ty::Closure(..) | ty::CoroutineClosure(..)
| ty::Coroutine(..) | ty::CoroutineWitness(..) | ty::Never |
ty::Tuple(..) |
ty::Infer(ty::InferTy::IntVar(_) |
ty::InferTy::FloatVar(..)) => true,
ty::UnsafeBinder(_) => {
::core::panicking::panic_fmt(format_args!("not yet implemented: {0}",
format_args!("FIXME(unsafe_binder)")));
}
ty::Param(_) | ty::Alias(..) | ty::Bound(..) |
ty::Placeholder(..) | ty::Infer(..) | ty::Error(_) => false,
},
Some(LangItem::PointeeTrait) => {
let tail =
selcx.tcx().struct_tail_raw(self_ty, &obligation.cause,
|ty|
{
normalize_with_depth(selcx, obligation.param_env,
obligation.cause.clone(), obligation.recursion_depth + 1,
ty).value
}, || {});
match tail.kind() {
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) |
ty::Float(_) | ty::Str | ty::Array(..) | ty::Pat(..) |
ty::Slice(_) | ty::RawPtr(..) | ty::Ref(..) | ty::FnDef(..)
| ty::FnPtr(..) | ty::Dynamic(..) | ty::Closure(..) |
ty::CoroutineClosure(..) | ty::Coroutine(..) |
ty::CoroutineWitness(..) | ty::Never | ty::Foreign(_) |
ty::Adt(..) | ty::Tuple(..) |
ty::Infer(ty::InferTy::IntVar(_) |
ty::InferTy::FloatVar(..)) | ty::Error(..) => true,
ty::Param(_) | ty::Alias(..) if
self_ty != tail ||
selcx.infcx.predicate_must_hold_modulo_regions(&obligation.with(selcx.tcx(),
ty::TraitRef::new(selcx.tcx(),
selcx.tcx().require_lang_item(LangItem::Sized,
obligation.cause.span), [self_ty]))) => {
true
}
ty::UnsafeBinder(_) => {
::core::panicking::panic_fmt(format_args!("not yet implemented: {0}",
format_args!("FIXME(unsafe_binder)")));
}
ty::Param(_) | ty::Alias(..) | ty::Bound(..) |
ty::Placeholder(..) | ty::Infer(..) => {
if tail.has_infer_types() {
candidate_set.mark_ambiguous();
}
false
}
}
}
_ if tcx.trait_is_auto(trait_ref.def_id) => {
tcx.dcx().span_delayed_bug(tcx.def_span(obligation.predicate.def_id()),
"associated types not allowed on auto traits");
false
}
_ => {
::rustc_middle::util::bug::bug_fmt(format_args!("unexpected builtin trait with associated type: {0:?}",
trait_ref))
}
}
}
ImplSource::Param(..) => { false }
ImplSource::Builtin(BuiltinImplSource::Object { .. }, _) =>
{
false
}
ImplSource::Builtin(BuiltinImplSource::TraitUpcasting { ..
}, _) => {
selcx.tcx().dcx().span_delayed_bug(obligation.cause.span,
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("Cannot project an associated type from `{0:?}`",
impl_source))
}));
return Err(());
}
};
if eligible {
if candidate_set.push_candidate(ProjectionCandidate::Select(impl_source))
{
Ok(())
} else { Err(()) }
} else { Err(()) }
});
}
}
}#[instrument(level = "debug", skip(selcx, obligation, candidate_set))]
892fn assemble_candidates_from_impls<'cx, 'tcx>(
893 selcx: &mut SelectionContext<'cx, 'tcx>,
894 obligation: &ProjectionTermObligation<'tcx>,
895 candidate_set: &mut ProjectionCandidateSet<'tcx>,
896) {
897 let trait_ref = obligation.predicate.trait_ref(selcx.tcx());
900 let trait_obligation = obligation.with(selcx.tcx(), trait_ref);
901 let _ = selcx.infcx.commit_if_ok(|_| {
902 let impl_source = match selcx.select(&trait_obligation) {
903 Ok(Some(impl_source)) => impl_source,
904 Ok(None) => {
905 candidate_set.mark_ambiguous();
906 return Err(());
907 }
908 Err(e) => {
909 debug!(error = ?e, "selection error");
910 candidate_set.mark_error(e);
911 return Err(());
912 }
913 };
914
915 let eligible = match &impl_source {
916 ImplSource::UserDefined(impl_data) => {
917 match specialization_graph::assoc_def(
940 selcx.tcx(),
941 impl_data.impl_def_id,
942 obligation.predicate.def_id(),
943 ) {
944 Ok(node_item) => {
945 if node_item.is_final() {
946 true
948 } else {
949 match selcx.infcx.typing_mode() {
954 TypingMode::Coherence
955 | TypingMode::Analysis { .. }
956 | TypingMode::Borrowck { .. }
957 | TypingMode::PostBorrowckAnalysis { .. } => {
958 debug!(
959 assoc_ty = ?selcx.tcx().def_path_str(node_item.item.def_id),
960 ?obligation.predicate,
961 "not eligible due to default",
962 );
963 false
964 }
965 TypingMode::PostAnalysis => {
966 let poly_trait_ref =
969 selcx.infcx.resolve_vars_if_possible(trait_ref);
970 !poly_trait_ref.still_further_specializable()
971 }
972 }
973 }
974 }
975 Err(ErrorGuaranteed { .. }) => true,
979 }
980 }
981 ImplSource::Builtin(BuiltinImplSource::Misc | BuiltinImplSource::Trivial, _) => {
982 let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
986
987 let tcx = selcx.tcx();
988 match selcx.tcx().as_lang_item(trait_ref.def_id) {
989 Some(
990 LangItem::Coroutine
991 | LangItem::Future
992 | LangItem::Iterator
993 | LangItem::AsyncIterator
994 | LangItem::Field
995 | LangItem::Fn
996 | LangItem::FnMut
997 | LangItem::FnOnce
998 | LangItem::AsyncFn
999 | LangItem::AsyncFnMut
1000 | LangItem::AsyncFnOnce,
1001 ) => true,
1002 Some(LangItem::AsyncFnKindHelper) => {
1003 if obligation.predicate.args.type_at(0).is_ty_var()
1005 || obligation.predicate.args.type_at(4).is_ty_var()
1006 || obligation.predicate.args.type_at(5).is_ty_var()
1007 {
1008 candidate_set.mark_ambiguous();
1009 true
1010 } else {
1011 obligation.predicate.args.type_at(0).to_opt_closure_kind().is_some()
1012 && obligation
1013 .predicate
1014 .args
1015 .type_at(1)
1016 .to_opt_closure_kind()
1017 .is_some()
1018 }
1019 }
1020 Some(LangItem::DiscriminantKind) => match self_ty.kind() {
1021 ty::Bool
1022 | ty::Char
1023 | ty::Int(_)
1024 | ty::Uint(_)
1025 | ty::Float(_)
1026 | ty::Adt(..)
1027 | ty::Foreign(_)
1028 | ty::Str
1029 | ty::Array(..)
1030 | ty::Pat(..)
1031 | ty::Slice(_)
1032 | ty::RawPtr(..)
1033 | ty::Ref(..)
1034 | ty::FnDef(..)
1035 | ty::FnPtr(..)
1036 | ty::Dynamic(..)
1037 | ty::Closure(..)
1038 | ty::CoroutineClosure(..)
1039 | ty::Coroutine(..)
1040 | ty::CoroutineWitness(..)
1041 | ty::Never
1042 | ty::Tuple(..)
1043 | ty::Infer(ty::InferTy::IntVar(_) | ty::InferTy::FloatVar(..)) => true,
1045
1046 ty::UnsafeBinder(_) => todo!("FIXME(unsafe_binder)"),
1047
1048 ty::Param(_)
1052 | ty::Alias(..)
1053 | ty::Bound(..)
1054 | ty::Placeholder(..)
1055 | ty::Infer(..)
1056 | ty::Error(_) => false,
1057 },
1058 Some(LangItem::PointeeTrait) => {
1059 let tail = selcx.tcx().struct_tail_raw(
1060 self_ty,
1061 &obligation.cause,
1062 |ty| {
1063 normalize_with_depth(
1066 selcx,
1067 obligation.param_env,
1068 obligation.cause.clone(),
1069 obligation.recursion_depth + 1,
1070 ty,
1071 )
1072 .value
1073 },
1074 || {},
1075 );
1076
1077 match tail.kind() {
1078 ty::Bool
1079 | ty::Char
1080 | ty::Int(_)
1081 | ty::Uint(_)
1082 | ty::Float(_)
1083 | ty::Str
1084 | ty::Array(..)
1085 | ty::Pat(..)
1086 | ty::Slice(_)
1087 | ty::RawPtr(..)
1088 | ty::Ref(..)
1089 | ty::FnDef(..)
1090 | ty::FnPtr(..)
1091 | ty::Dynamic(..)
1092 | ty::Closure(..)
1093 | ty::CoroutineClosure(..)
1094 | ty::Coroutine(..)
1095 | ty::CoroutineWitness(..)
1096 | ty::Never
1097 | ty::Foreign(_)
1099 | ty::Adt(..)
1102 | ty::Tuple(..)
1104 | ty::Infer(ty::InferTy::IntVar(_) | ty::InferTy::FloatVar(..))
1106 | ty::Error(..) => true,
1108
1109 ty::Param(_) | ty::Alias(..)
1113 if self_ty != tail
1114 || selcx.infcx.predicate_must_hold_modulo_regions(
1115 &obligation.with(
1116 selcx.tcx(),
1117 ty::TraitRef::new(
1118 selcx.tcx(),
1119 selcx.tcx().require_lang_item(
1120 LangItem::Sized,
1121 obligation.cause.span,
1122 ),
1123 [self_ty],
1124 ),
1125 ),
1126 ) =>
1127 {
1128 true
1129 }
1130
1131 ty::UnsafeBinder(_) => todo!("FIXME(unsafe_binder)"),
1132
1133 ty::Param(_)
1135 | ty::Alias(..)
1136 | ty::Bound(..)
1137 | ty::Placeholder(..)
1138 | ty::Infer(..) => {
1139 if tail.has_infer_types() {
1140 candidate_set.mark_ambiguous();
1141 }
1142 false
1143 }
1144 }
1145 }
1146 _ if tcx.trait_is_auto(trait_ref.def_id) => {
1147 tcx.dcx().span_delayed_bug(
1148 tcx.def_span(obligation.predicate.def_id()),
1149 "associated types not allowed on auto traits",
1150 );
1151 false
1152 }
1153 _ => {
1154 bug!("unexpected builtin trait with associated type: {trait_ref:?}")
1155 }
1156 }
1157 }
1158 ImplSource::Param(..) => {
1159 false
1185 }
1186 ImplSource::Builtin(BuiltinImplSource::Object { .. }, _) => {
1187 false
1191 }
1192 ImplSource::Builtin(BuiltinImplSource::TraitUpcasting { .. }, _) => {
1193 selcx.tcx().dcx().span_delayed_bug(
1195 obligation.cause.span,
1196 format!("Cannot project an associated type from `{impl_source:?}`"),
1197 );
1198 return Err(());
1199 }
1200 };
1201
1202 if eligible {
1203 if candidate_set.push_candidate(ProjectionCandidate::Select(impl_source)) {
1204 Ok(())
1205 } else {
1206 Err(())
1207 }
1208 } else {
1209 Err(())
1210 }
1211 });
1212}
1213
1214fn confirm_candidate<'cx, 'tcx>(
1216 selcx: &mut SelectionContext<'cx, 'tcx>,
1217 obligation: &ProjectionTermObligation<'tcx>,
1218 candidate: ProjectionCandidate<'tcx>,
1219) -> Result<Projected<'tcx>, ProjectionError<'tcx>> {
1220 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:1220",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(1220u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message",
"obligation", "candidate"],
::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!("confirm_candidate")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligation)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&candidate)
as &dyn Value))])
});
} else { ; }
};debug!(?obligation, ?candidate, "confirm_candidate");
1221 let mut result = match candidate {
1222 ProjectionCandidate::ParamEnv(poly_projection)
1223 | ProjectionCandidate::Object(poly_projection) => Ok(Projected::Progress(
1224 confirm_param_env_candidate(selcx, obligation, poly_projection, false),
1225 )),
1226 ProjectionCandidate::TraitDef(poly_projection) => Ok(Projected::Progress(
1227 confirm_param_env_candidate(selcx, obligation, poly_projection, true),
1228 )),
1229 ProjectionCandidate::Select(impl_source) => {
1230 confirm_select_candidate(selcx, obligation, impl_source)
1231 }
1232 };
1233
1234 if let Ok(Projected::Progress(progress)) = &mut result
1240 && progress.term.has_infer_regions()
1241 {
1242 progress.term = progress.term.fold_with(&mut OpportunisticRegionResolver::new(selcx.infcx));
1243 }
1244
1245 result
1246}
1247
1248fn confirm_select_candidate<'cx, 'tcx>(
1250 selcx: &mut SelectionContext<'cx, 'tcx>,
1251 obligation: &ProjectionTermObligation<'tcx>,
1252 impl_source: Selection<'tcx>,
1253) -> Result<Projected<'tcx>, ProjectionError<'tcx>> {
1254 match impl_source {
1255 ImplSource::UserDefined(data) => confirm_impl_candidate(selcx, obligation, data),
1256 ImplSource::Builtin(BuiltinImplSource::Misc | BuiltinImplSource::Trivial, data) => {
1257 let tcx = selcx.tcx();
1258 let trait_def_id = obligation.predicate.trait_def_id(tcx);
1259 let progress = if tcx.is_lang_item(trait_def_id, LangItem::Coroutine) {
1260 confirm_coroutine_candidate(selcx, obligation, data)
1261 } else if tcx.is_lang_item(trait_def_id, LangItem::Future) {
1262 confirm_future_candidate(selcx, obligation, data)
1263 } else if tcx.is_lang_item(trait_def_id, LangItem::Iterator) {
1264 confirm_iterator_candidate(selcx, obligation, data)
1265 } else if tcx.is_lang_item(trait_def_id, LangItem::AsyncIterator) {
1266 confirm_async_iterator_candidate(selcx, obligation, data)
1267 } else if selcx.tcx().fn_trait_kind_from_def_id(trait_def_id).is_some() {
1268 if obligation.predicate.self_ty().is_closure()
1269 || obligation.predicate.self_ty().is_coroutine_closure()
1270 {
1271 confirm_closure_candidate(selcx, obligation, data)
1272 } else {
1273 confirm_fn_pointer_candidate(selcx, obligation, data)
1274 }
1275 } else if selcx.tcx().async_fn_trait_kind_from_def_id(trait_def_id).is_some() {
1276 confirm_async_closure_candidate(selcx, obligation, data)
1277 } else if tcx.is_lang_item(trait_def_id, LangItem::AsyncFnKindHelper) {
1278 confirm_async_fn_kind_helper_candidate(selcx, obligation, data)
1279 } else {
1280 confirm_builtin_candidate(selcx, obligation, data)
1281 };
1282 Ok(Projected::Progress(progress))
1283 }
1284 ImplSource::Builtin(BuiltinImplSource::Object { .. }, _)
1285 | ImplSource::Param(..)
1286 | ImplSource::Builtin(BuiltinImplSource::TraitUpcasting { .. }, _) => {
1287 ::rustc_middle::util::bug::span_bug_fmt(obligation.cause.span,
format_args!("Cannot project an associated type from `{0:?}`",
impl_source))span_bug!(
1289 obligation.cause.span,
1290 "Cannot project an associated type from `{:?}`",
1291 impl_source
1292 )
1293 }
1294 }
1295}
1296
1297fn confirm_coroutine_candidate<'cx, 'tcx>(
1298 selcx: &mut SelectionContext<'cx, 'tcx>,
1299 obligation: &ProjectionTermObligation<'tcx>,
1300 nested: PredicateObligations<'tcx>,
1301) -> Progress<'tcx> {
1302 let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
1303 let ty::Coroutine(_, args) = self_ty.kind() else {
1304 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("expected coroutine self type for built-in coroutine candidate, found {0}",
self_ty)));
}unreachable!(
1305 "expected coroutine self type for built-in coroutine candidate, found {self_ty}"
1306 )
1307 };
1308 let coroutine_sig = args.as_coroutine().sig();
1309 let Normalized { value: coroutine_sig, obligations } = normalize_with_depth(
1310 selcx,
1311 obligation.param_env,
1312 obligation.cause.clone(),
1313 obligation.recursion_depth + 1,
1314 coroutine_sig,
1315 );
1316
1317 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:1317",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(1317u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message",
"obligation", "coroutine_sig", "obligations"],
::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!("confirm_coroutine_candidate")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligation)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&coroutine_sig)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligations)
as &dyn Value))])
});
} else { ; }
};debug!(?obligation, ?coroutine_sig, ?obligations, "confirm_coroutine_candidate");
1318
1319 let tcx = selcx.tcx();
1320
1321 let coroutine_def_id = tcx.require_lang_item(LangItem::Coroutine, obligation.cause.span);
1322
1323 let (trait_ref, yield_ty, return_ty) = super::util::coroutine_trait_ref_and_outputs(
1324 tcx,
1325 coroutine_def_id,
1326 obligation.predicate.self_ty(),
1327 coroutine_sig,
1328 );
1329
1330 let ty = if tcx.is_lang_item(obligation.predicate.def_id(), LangItem::CoroutineReturn) {
1331 return_ty
1332 } else if tcx.is_lang_item(obligation.predicate.def_id(), LangItem::CoroutineYield) {
1333 yield_ty
1334 } else {
1335 ::rustc_middle::util::bug::span_bug_fmt(tcx.def_span(obligation.predicate.def_id()),
format_args!("unexpected associated type: `Coroutine::{0}`",
tcx.item_name(obligation.predicate.def_id())));span_bug!(
1336 tcx.def_span(obligation.predicate.def_id()),
1337 "unexpected associated type: `Coroutine::{}`",
1338 tcx.item_name(obligation.predicate.def_id()),
1339 );
1340 };
1341
1342 let predicate = ty::ProjectionPredicate {
1343 projection_term: obligation.predicate.with_args(tcx, trait_ref.args),
1344 term: ty.into(),
1345 };
1346
1347 confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
1348 .with_addl_obligations(nested)
1349 .with_addl_obligations(obligations)
1350}
1351
1352fn confirm_future_candidate<'cx, 'tcx>(
1353 selcx: &mut SelectionContext<'cx, 'tcx>,
1354 obligation: &ProjectionTermObligation<'tcx>,
1355 nested: PredicateObligations<'tcx>,
1356) -> Progress<'tcx> {
1357 let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
1358 let ty::Coroutine(_, args) = self_ty.kind() else {
1359 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("expected coroutine self type for built-in async future candidate, found {0}",
self_ty)));
}unreachable!(
1360 "expected coroutine self type for built-in async future candidate, found {self_ty}"
1361 )
1362 };
1363 let coroutine_sig = args.as_coroutine().sig();
1364 let Normalized { value: coroutine_sig, obligations } = normalize_with_depth(
1365 selcx,
1366 obligation.param_env,
1367 obligation.cause.clone(),
1368 obligation.recursion_depth + 1,
1369 coroutine_sig,
1370 );
1371
1372 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:1372",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(1372u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message",
"obligation", "coroutine_sig", "obligations"],
::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!("confirm_future_candidate")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligation)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&coroutine_sig)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligations)
as &dyn Value))])
});
} else { ; }
};debug!(?obligation, ?coroutine_sig, ?obligations, "confirm_future_candidate");
1373
1374 let tcx = selcx.tcx();
1375 let fut_def_id = tcx.require_lang_item(LangItem::Future, obligation.cause.span);
1376
1377 let (trait_ref, return_ty) = super::util::future_trait_ref_and_outputs(
1378 tcx,
1379 fut_def_id,
1380 obligation.predicate.self_ty(),
1381 coroutine_sig,
1382 );
1383
1384 if true {
match (&tcx.associated_item(obligation.predicate.def_id()).name(),
&sym::Output) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
};debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id()).name(), sym::Output);
1385
1386 let predicate = ty::ProjectionPredicate {
1387 projection_term: obligation.predicate.with_args(tcx, trait_ref.args),
1388 term: return_ty.into(),
1389 };
1390
1391 confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
1392 .with_addl_obligations(nested)
1393 .with_addl_obligations(obligations)
1394}
1395
1396fn confirm_iterator_candidate<'cx, 'tcx>(
1397 selcx: &mut SelectionContext<'cx, 'tcx>,
1398 obligation: &ProjectionTermObligation<'tcx>,
1399 nested: PredicateObligations<'tcx>,
1400) -> Progress<'tcx> {
1401 let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
1402 let ty::Coroutine(_, args) = self_ty.kind() else {
1403 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("expected coroutine self type for built-in gen candidate, found {0}",
self_ty)));
}unreachable!("expected coroutine self type for built-in gen candidate, found {self_ty}")
1404 };
1405 let gen_sig = args.as_coroutine().sig();
1406 let Normalized { value: gen_sig, obligations } = normalize_with_depth(
1407 selcx,
1408 obligation.param_env,
1409 obligation.cause.clone(),
1410 obligation.recursion_depth + 1,
1411 gen_sig,
1412 );
1413
1414 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:1414",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(1414u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message",
"obligation", "gen_sig", "obligations"],
::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!("confirm_iterator_candidate")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligation)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&gen_sig) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligations)
as &dyn Value))])
});
} else { ; }
};debug!(?obligation, ?gen_sig, ?obligations, "confirm_iterator_candidate");
1415
1416 let tcx = selcx.tcx();
1417 let iter_def_id = tcx.require_lang_item(LangItem::Iterator, obligation.cause.span);
1418
1419 let (trait_ref, yield_ty) = super::util::iterator_trait_ref_and_outputs(
1420 tcx,
1421 iter_def_id,
1422 obligation.predicate.self_ty(),
1423 gen_sig,
1424 );
1425
1426 if true {
match (&tcx.associated_item(obligation.predicate.def_id()).name(),
&sym::Item) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
};debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id()).name(), sym::Item);
1427
1428 let predicate = ty::ProjectionPredicate {
1429 projection_term: obligation.predicate.with_args(tcx, trait_ref.args),
1430 term: yield_ty.into(),
1431 };
1432
1433 confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
1434 .with_addl_obligations(nested)
1435 .with_addl_obligations(obligations)
1436}
1437
1438fn confirm_async_iterator_candidate<'cx, 'tcx>(
1439 selcx: &mut SelectionContext<'cx, 'tcx>,
1440 obligation: &ProjectionTermObligation<'tcx>,
1441 nested: PredicateObligations<'tcx>,
1442) -> Progress<'tcx> {
1443 let ty::Coroutine(_, args) = selcx.infcx.shallow_resolve(obligation.predicate.self_ty()).kind()
1444 else {
1445 ::core::panicking::panic("internal error: entered unreachable code")unreachable!()
1446 };
1447 let gen_sig = args.as_coroutine().sig();
1448 let Normalized { value: gen_sig, obligations } = normalize_with_depth(
1449 selcx,
1450 obligation.param_env,
1451 obligation.cause.clone(),
1452 obligation.recursion_depth + 1,
1453 gen_sig,
1454 );
1455
1456 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:1456",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(1456u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message",
"obligation", "gen_sig", "obligations"],
::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!("confirm_async_iterator_candidate")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligation)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&gen_sig) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligations)
as &dyn Value))])
});
} else { ; }
};debug!(?obligation, ?gen_sig, ?obligations, "confirm_async_iterator_candidate");
1457
1458 let tcx = selcx.tcx();
1459 let iter_def_id = tcx.require_lang_item(LangItem::AsyncIterator, obligation.cause.span);
1460
1461 let (trait_ref, yield_ty) = super::util::async_iterator_trait_ref_and_outputs(
1462 tcx,
1463 iter_def_id,
1464 obligation.predicate.self_ty(),
1465 gen_sig,
1466 );
1467
1468 if true {
match (&tcx.associated_item(obligation.predicate.def_id()).name(),
&sym::Item) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
};debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id()).name(), sym::Item);
1469
1470 let ty::Adt(_poll_adt, args) = *yield_ty.kind() else {
1471 ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"));bug!();
1472 };
1473 let ty::Adt(_option_adt, args) = *args.type_at(0).kind() else {
1474 ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"));bug!();
1475 };
1476 let item_ty = args.type_at(0);
1477
1478 let predicate = ty::ProjectionPredicate {
1479 projection_term: obligation.predicate.with_args(tcx, trait_ref.args),
1480 term: item_ty.into(),
1481 };
1482
1483 confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
1484 .with_addl_obligations(nested)
1485 .with_addl_obligations(obligations)
1486}
1487
1488fn confirm_builtin_candidate<'cx, 'tcx>(
1489 selcx: &mut SelectionContext<'cx, 'tcx>,
1490 obligation: &ProjectionTermObligation<'tcx>,
1491 data: PredicateObligations<'tcx>,
1492) -> Progress<'tcx> {
1493 let tcx = selcx.tcx();
1494 let self_ty = obligation.predicate.self_ty();
1495 let item_def_id = obligation.predicate.def_id();
1496 let trait_def_id = tcx.parent(item_def_id);
1497 let args = tcx.mk_args(&[self_ty.into()]);
1498 let (term, obligations) = if tcx.is_lang_item(trait_def_id, LangItem::DiscriminantKind) {
1499 let discriminant_def_id =
1500 tcx.require_lang_item(LangItem::Discriminant, obligation.cause.span);
1501 match (&discriminant_def_id, &item_def_id) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(discriminant_def_id, item_def_id);
1502
1503 (self_ty.discriminant_ty(tcx).into(), PredicateObligations::new())
1504 } else if tcx.is_lang_item(trait_def_id, LangItem::PointeeTrait) {
1505 let metadata_def_id = tcx.require_lang_item(LangItem::Metadata, obligation.cause.span);
1506 match (&metadata_def_id, &item_def_id) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(metadata_def_id, item_def_id);
1507
1508 let mut obligations = PredicateObligations::new();
1509 let normalize = |ty| {
1510 normalize_with_depth_to(
1511 selcx,
1512 obligation.param_env,
1513 obligation.cause.clone(),
1514 obligation.recursion_depth + 1,
1515 ty,
1516 &mut obligations,
1517 )
1518 };
1519 let metadata_ty = self_ty.ptr_metadata_ty_or_tail(tcx, normalize).unwrap_or_else(|tail| {
1520 if tail == self_ty {
1521 let sized_predicate = ty::TraitRef::new(
1526 tcx,
1527 tcx.require_lang_item(LangItem::Sized, obligation.cause.span),
1528 [self_ty],
1529 );
1530 obligations.push(obligation.with(tcx, sized_predicate));
1531 tcx.types.unit
1532 } else {
1533 Ty::new_projection(tcx, metadata_def_id, [tail])
1536 }
1537 });
1538 (metadata_ty.into(), obligations)
1539 } else if tcx.is_lang_item(trait_def_id, LangItem::Field) {
1540 let ty::Adt(def, args) = self_ty.kind() else {
1541 ::rustc_middle::util::bug::bug_fmt(format_args!("only field representing types can implement `Field`"))bug!("only field representing types can implement `Field`")
1542 };
1543 let Some(FieldInfo { base, ty, .. }) = def.field_representing_type_info(tcx, args) else {
1544 ::rustc_middle::util::bug::bug_fmt(format_args!("only field representing types can implement `Field`"))bug!("only field representing types can implement `Field`")
1545 };
1546 if tcx.is_lang_item(item_def_id, LangItem::FieldBase) {
1547 (base.into(), PredicateObligations::new())
1548 } else if tcx.is_lang_item(item_def_id, LangItem::FieldType) {
1549 (ty.into(), PredicateObligations::new())
1550 } else {
1551 ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected associated type {0:?} in `Field`",
obligation.predicate));bug!("unexpected associated type {:?} in `Field`", obligation.predicate);
1552 }
1553 } else {
1554 ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected builtin trait with associated type: {0:?}",
obligation.predicate));bug!("unexpected builtin trait with associated type: {:?}", obligation.predicate);
1555 };
1556
1557 let predicate = ty::ProjectionPredicate {
1558 projection_term: ty::AliasTerm::new_from_args(
1559 tcx,
1560 ty::AliasTermKind::ProjectionTy { def_id: item_def_id },
1561 args,
1562 ),
1563 term,
1564 };
1565
1566 confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
1567 .with_addl_obligations(obligations)
1568 .with_addl_obligations(data)
1569}
1570
1571fn confirm_fn_pointer_candidate<'cx, 'tcx>(
1572 selcx: &mut SelectionContext<'cx, 'tcx>,
1573 obligation: &ProjectionTermObligation<'tcx>,
1574 nested: PredicateObligations<'tcx>,
1575) -> Progress<'tcx> {
1576 let tcx = selcx.tcx();
1577 let fn_type = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
1578 let sig = fn_type.fn_sig(tcx);
1579 let Normalized { value: sig, obligations } = normalize_with_depth(
1580 selcx,
1581 obligation.param_env,
1582 obligation.cause.clone(),
1583 obligation.recursion_depth + 1,
1584 sig,
1585 );
1586
1587 confirm_callable_candidate(selcx, obligation, sig, util::TupleArgumentsFlag::Yes)
1588 .with_addl_obligations(nested)
1589 .with_addl_obligations(obligations)
1590}
1591
1592fn confirm_closure_candidate<'cx, 'tcx>(
1593 selcx: &mut SelectionContext<'cx, 'tcx>,
1594 obligation: &ProjectionTermObligation<'tcx>,
1595 nested: PredicateObligations<'tcx>,
1596) -> Progress<'tcx> {
1597 let tcx = selcx.tcx();
1598 let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
1599 let closure_sig = match *self_ty.kind() {
1600 ty::Closure(_, args) => args.as_closure().sig(),
1601
1602 ty::CoroutineClosure(def_id, args) => {
1606 let args = args.as_coroutine_closure();
1607 let kind_ty = args.kind_ty();
1608 args.coroutine_closure_sig().map_bound(|sig| {
1609 let output_ty = if let Some(_) = kind_ty.to_opt_closure_kind()
1613 && !args.tupled_upvars_ty().is_ty_var()
1615 {
1616 sig.to_coroutine_given_kind_and_upvars(
1617 tcx,
1618 args.parent_args(),
1619 tcx.coroutine_for_closure(def_id),
1620 ty::ClosureKind::FnOnce,
1621 tcx.lifetimes.re_static,
1622 args.tupled_upvars_ty(),
1623 args.coroutine_captures_by_ref_ty(),
1624 )
1625 } else {
1626 let upvars_projection_def_id =
1627 tcx.require_lang_item(LangItem::AsyncFnKindUpvars, obligation.cause.span);
1628 let tupled_upvars_ty = Ty::new_projection(
1629 tcx,
1630 upvars_projection_def_id,
1631 [
1632 ty::GenericArg::from(kind_ty),
1633 Ty::from_closure_kind(tcx, ty::ClosureKind::FnOnce).into(),
1634 tcx.lifetimes.re_static.into(),
1635 sig.tupled_inputs_ty.into(),
1636 args.tupled_upvars_ty().into(),
1637 args.coroutine_captures_by_ref_ty().into(),
1638 ],
1639 );
1640 sig.to_coroutine(
1641 tcx,
1642 args.parent_args(),
1643 Ty::from_closure_kind(tcx, ty::ClosureKind::FnOnce),
1644 tcx.coroutine_for_closure(def_id),
1645 tupled_upvars_ty,
1646 )
1647 };
1648
1649 tcx.mk_fn_sig([sig.tupled_inputs_ty], output_ty, sig.fn_sig_kind)
1650 })
1651 }
1652
1653 _ => {
1654 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("expected closure self type for closure candidate, found {0}",
self_ty)));
};unreachable!("expected closure self type for closure candidate, found {self_ty}");
1655 }
1656 };
1657
1658 let Normalized { value: closure_sig, obligations } = normalize_with_depth(
1659 selcx,
1660 obligation.param_env,
1661 obligation.cause.clone(),
1662 obligation.recursion_depth + 1,
1663 closure_sig,
1664 );
1665
1666 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:1666",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(1666u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message",
"obligation", "closure_sig", "obligations"],
::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!("confirm_closure_candidate")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligation)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&closure_sig)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligations)
as &dyn Value))])
});
} else { ; }
};debug!(?obligation, ?closure_sig, ?obligations, "confirm_closure_candidate");
1667
1668 confirm_callable_candidate(selcx, obligation, closure_sig, util::TupleArgumentsFlag::No)
1669 .with_addl_obligations(nested)
1670 .with_addl_obligations(obligations)
1671}
1672
1673fn confirm_callable_candidate<'cx, 'tcx>(
1674 selcx: &mut SelectionContext<'cx, 'tcx>,
1675 obligation: &ProjectionTermObligation<'tcx>,
1676 fn_sig: ty::PolyFnSig<'tcx>,
1677 flag: util::TupleArgumentsFlag,
1678) -> Progress<'tcx> {
1679 let tcx = selcx.tcx();
1680
1681 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:1681",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(1681u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message",
"obligation", "fn_sig"],
::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!("confirm_callable_candidate")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligation)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&fn_sig) as
&dyn Value))])
});
} else { ; }
};debug!(?obligation, ?fn_sig, "confirm_callable_candidate");
1682
1683 let fn_once_def_id = tcx.require_lang_item(LangItem::FnOnce, obligation.cause.span);
1684 let fn_once_output_def_id =
1685 tcx.require_lang_item(LangItem::FnOnceOutput, obligation.cause.span);
1686
1687 let predicate = super::util::closure_trait_ref_and_return_type(
1688 tcx,
1689 fn_once_def_id,
1690 obligation.predicate.self_ty(),
1691 fn_sig,
1692 flag,
1693 )
1694 .map_bound(|(trait_ref, ret_type)| ty::ProjectionPredicate {
1695 projection_term: ty::AliasTerm::new_from_args(
1696 tcx,
1697 ty::AliasTermKind::ProjectionTy { def_id: fn_once_output_def_id },
1698 trait_ref.args,
1699 ),
1700 term: ret_type.into(),
1701 });
1702
1703 confirm_param_env_candidate(selcx, obligation, predicate, true)
1704}
1705
1706fn confirm_async_closure_candidate<'cx, 'tcx>(
1707 selcx: &mut SelectionContext<'cx, 'tcx>,
1708 obligation: &ProjectionTermObligation<'tcx>,
1709 nested: PredicateObligations<'tcx>,
1710) -> Progress<'tcx> {
1711 let tcx = selcx.tcx();
1712 let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
1713
1714 let goal_kind =
1715 tcx.async_fn_trait_kind_from_def_id(obligation.predicate.trait_def_id(tcx)).unwrap();
1716 let env_region = match goal_kind {
1717 ty::ClosureKind::Fn | ty::ClosureKind::FnMut => obligation.predicate.args.region_at(2),
1718 ty::ClosureKind::FnOnce => tcx.lifetimes.re_static,
1719 };
1720 let item_name = tcx.item_name(obligation.predicate.def_id());
1721
1722 let poly_cache_entry = match *self_ty.kind() {
1723 ty::CoroutineClosure(def_id, args) => {
1724 let args = args.as_coroutine_closure();
1725 let kind_ty = args.kind_ty();
1726 let sig = args.coroutine_closure_sig().skip_binder();
1727
1728 let term = match item_name {
1729 sym::CallOnceFuture | sym::CallRefFuture => {
1730 if let Some(closure_kind) = kind_ty.to_opt_closure_kind()
1731 && !args.tupled_upvars_ty().is_ty_var()
1733 {
1734 if !closure_kind.extends(goal_kind) {
1735 ::rustc_middle::util::bug::bug_fmt(format_args!("we should not be confirming if the closure kind is not met"));bug!("we should not be confirming if the closure kind is not met");
1736 }
1737 sig.to_coroutine_given_kind_and_upvars(
1738 tcx,
1739 args.parent_args(),
1740 tcx.coroutine_for_closure(def_id),
1741 goal_kind,
1742 env_region,
1743 args.tupled_upvars_ty(),
1744 args.coroutine_captures_by_ref_ty(),
1745 )
1746 } else {
1747 let upvars_projection_def_id = tcx
1748 .require_lang_item(LangItem::AsyncFnKindUpvars, obligation.cause.span);
1749 let tupled_upvars_ty = Ty::new_projection(
1758 tcx,
1759 upvars_projection_def_id,
1760 [
1761 ty::GenericArg::from(kind_ty),
1762 Ty::from_closure_kind(tcx, goal_kind).into(),
1763 env_region.into(),
1764 sig.tupled_inputs_ty.into(),
1765 args.tupled_upvars_ty().into(),
1766 args.coroutine_captures_by_ref_ty().into(),
1767 ],
1768 );
1769 sig.to_coroutine(
1770 tcx,
1771 args.parent_args(),
1772 Ty::from_closure_kind(tcx, goal_kind),
1773 tcx.coroutine_for_closure(def_id),
1774 tupled_upvars_ty,
1775 )
1776 }
1777 }
1778 sym::Output => sig.return_ty,
1779 name => ::rustc_middle::util::bug::bug_fmt(format_args!("no such associated type: {0}",
name))bug!("no such associated type: {name}"),
1780 };
1781 let projection_term = match item_name {
1782 sym::CallOnceFuture | sym::Output => ty::AliasTerm::new(
1783 tcx,
1784 obligation.predicate.kind,
1785 [self_ty, sig.tupled_inputs_ty],
1786 ),
1787 sym::CallRefFuture => ty::AliasTerm::new(
1788 tcx,
1789 obligation.predicate.kind,
1790 [ty::GenericArg::from(self_ty), sig.tupled_inputs_ty.into(), env_region.into()],
1791 ),
1792 name => ::rustc_middle::util::bug::bug_fmt(format_args!("no such associated type: {0}",
name))bug!("no such associated type: {name}"),
1793 };
1794
1795 args.coroutine_closure_sig()
1796 .rebind(ty::ProjectionPredicate { projection_term, term: term.into() })
1797 }
1798 ty::FnDef(..) | ty::FnPtr(..) => {
1799 let bound_sig = self_ty.fn_sig(tcx);
1800 let sig = bound_sig.skip_binder();
1801
1802 let term = match item_name {
1803 sym::CallOnceFuture | sym::CallRefFuture => sig.output(),
1804 sym::Output => {
1805 let future_output_def_id =
1806 tcx.require_lang_item(LangItem::FutureOutput, obligation.cause.span);
1807 Ty::new_projection(tcx, future_output_def_id, [sig.output()])
1808 }
1809 name => ::rustc_middle::util::bug::bug_fmt(format_args!("no such associated type: {0}",
name))bug!("no such associated type: {name}"),
1810 };
1811 let projection_term = match item_name {
1812 sym::CallOnceFuture | sym::Output => ty::AliasTerm::new(
1813 tcx,
1814 obligation.predicate.kind,
1815 [self_ty, Ty::new_tup(tcx, sig.inputs())],
1816 ),
1817 sym::CallRefFuture => ty::AliasTerm::new(
1818 tcx,
1819 obligation.predicate.kind,
1820 [
1821 ty::GenericArg::from(self_ty),
1822 Ty::new_tup(tcx, sig.inputs()).into(),
1823 env_region.into(),
1824 ],
1825 ),
1826 name => ::rustc_middle::util::bug::bug_fmt(format_args!("no such associated type: {0}",
name))bug!("no such associated type: {name}"),
1827 };
1828
1829 bound_sig.rebind(ty::ProjectionPredicate { projection_term, term: term.into() })
1830 }
1831 ty::Closure(_, args) => {
1832 let args = args.as_closure();
1833 let bound_sig = args.sig();
1834 let sig = bound_sig.skip_binder();
1835
1836 let term = match item_name {
1837 sym::CallOnceFuture | sym::CallRefFuture => sig.output(),
1838 sym::Output => {
1839 let future_output_def_id =
1840 tcx.require_lang_item(LangItem::FutureOutput, obligation.cause.span);
1841 Ty::new_projection(tcx, future_output_def_id, [sig.output()])
1842 }
1843 name => ::rustc_middle::util::bug::bug_fmt(format_args!("no such associated type: {0}",
name))bug!("no such associated type: {name}"),
1844 };
1845 let projection_term = match item_name {
1846 sym::CallOnceFuture | sym::Output => {
1847 ty::AliasTerm::new(tcx, obligation.predicate.kind, [self_ty, sig.inputs()[0]])
1848 }
1849 sym::CallRefFuture => ty::AliasTerm::new(
1850 tcx,
1851 obligation.predicate.kind,
1852 [ty::GenericArg::from(self_ty), sig.inputs()[0].into(), env_region.into()],
1853 ),
1854 name => ::rustc_middle::util::bug::bug_fmt(format_args!("no such associated type: {0}",
name))bug!("no such associated type: {name}"),
1855 };
1856
1857 bound_sig.rebind(ty::ProjectionPredicate { projection_term, term: term.into() })
1858 }
1859 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("expected callable type for AsyncFn candidate"))bug!("expected callable type for AsyncFn candidate"),
1860 };
1861
1862 confirm_param_env_candidate(selcx, obligation, poly_cache_entry, true)
1863 .with_addl_obligations(nested)
1864}
1865
1866fn confirm_async_fn_kind_helper_candidate<'cx, 'tcx>(
1867 selcx: &mut SelectionContext<'cx, 'tcx>,
1868 obligation: &ProjectionTermObligation<'tcx>,
1869 nested: PredicateObligations<'tcx>,
1870) -> Progress<'tcx> {
1871 let [
1872 _closure_kind_ty,
1874 goal_kind_ty,
1875 borrow_region,
1876 tupled_inputs_ty,
1877 tupled_upvars_ty,
1878 coroutine_captures_by_ref_ty,
1879 ] = **obligation.predicate.args
1880 else {
1881 ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"));bug!();
1882 };
1883
1884 let predicate = ty::ProjectionPredicate {
1885 projection_term: obligation.predicate.with_args(selcx.tcx(), obligation.predicate.args),
1886 term: ty::CoroutineClosureSignature::tupled_upvars_by_closure_kind(
1887 selcx.tcx(),
1888 goal_kind_ty.expect_ty().to_opt_closure_kind().unwrap(),
1889 tupled_inputs_ty.expect_ty(),
1890 tupled_upvars_ty.expect_ty(),
1891 coroutine_captures_by_ref_ty.expect_ty(),
1892 borrow_region.expect_region(),
1893 )
1894 .into(),
1895 };
1896
1897 confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
1898 .with_addl_obligations(nested)
1899}
1900
1901fn confirm_param_env_candidate<'cx, 'tcx>(
1903 selcx: &mut SelectionContext<'cx, 'tcx>,
1904 obligation: &ProjectionTermObligation<'tcx>,
1905 poly_cache_entry: ty::PolyProjectionPredicate<'tcx>,
1906 potentially_unnormalized_candidate: bool,
1907) -> Progress<'tcx> {
1908 let infcx = selcx.infcx;
1909 let cause = &obligation.cause;
1910 let param_env = obligation.param_env;
1911
1912 let cache_entry = infcx.instantiate_binder_with_fresh_vars(
1913 cause.span,
1914 BoundRegionConversionTime::HigherRankedType,
1915 poly_cache_entry,
1916 );
1917
1918 let cache_projection = cache_entry.projection_term;
1919 let mut nested_obligations = PredicateObligations::new();
1920 let obligation_projection = obligation.predicate;
1921 let obligation_projection = ensure_sufficient_stack(|| {
1922 normalize_with_depth_to(
1923 selcx,
1924 obligation.param_env,
1925 obligation.cause.clone(),
1926 obligation.recursion_depth + 1,
1927 obligation_projection,
1928 &mut nested_obligations,
1929 )
1930 });
1931 let cache_projection = if potentially_unnormalized_candidate {
1932 ensure_sufficient_stack(|| {
1933 normalize_with_depth_to(
1934 selcx,
1935 obligation.param_env,
1936 obligation.cause.clone(),
1937 obligation.recursion_depth + 1,
1938 cache_projection,
1939 &mut nested_obligations,
1940 )
1941 })
1942 } else {
1943 cache_projection
1944 };
1945
1946 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:1946",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(1946u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["cache_projection",
"obligation_projection"],
::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(&debug(&cache_projection)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligation_projection)
as &dyn Value))])
});
} else { ; }
};debug!(?cache_projection, ?obligation_projection);
1947
1948 match infcx.at(cause, param_env).eq(
1949 DefineOpaqueTypes::Yes,
1950 cache_projection,
1951 obligation_projection,
1952 ) {
1953 Ok(InferOk { value: _, obligations }) => {
1954 nested_obligations.extend(obligations);
1955 assoc_term_own_obligations(selcx, obligation, &mut nested_obligations);
1956 Progress { term: cache_entry.term, obligations: nested_obligations }
1957 }
1958 Err(e) => {
1959 let msg = ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("Failed to unify obligation `{0:?}` with poly_projection `{1:?}`: {2:?}",
obligation, poly_cache_entry, e))
})format!(
1960 "Failed to unify obligation `{obligation:?}` with poly_projection `{poly_cache_entry:?}`: {e:?}",
1961 );
1962 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:1962",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(1962u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::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!("confirm_param_env_candidate: {0}",
msg) as &dyn Value))])
});
} else { ; }
};debug!("confirm_param_env_candidate: {}", msg);
1963 let err = Ty::new_error_with_message(infcx.tcx, obligation.cause.span, msg);
1964 Progress { term: err.into(), obligations: PredicateObligations::new() }
1965 }
1966 }
1967}
1968
1969fn confirm_impl_candidate<'cx, 'tcx>(
1971 selcx: &mut SelectionContext<'cx, 'tcx>,
1972 obligation: &ProjectionTermObligation<'tcx>,
1973 impl_impl_source: ImplSourceUserDefinedData<'tcx, PredicateObligation<'tcx>>,
1974) -> Result<Projected<'tcx>, ProjectionError<'tcx>> {
1975 let tcx = selcx.tcx();
1976
1977 let ImplSourceUserDefinedData { impl_def_id, args, mut nested } = impl_impl_source;
1978
1979 let assoc_item_id = obligation.predicate.def_id();
1980 let trait_def_id = tcx.impl_trait_id(impl_def_id);
1981
1982 let param_env = obligation.param_env;
1983 let assoc_term = match specialization_graph::assoc_def(tcx, impl_def_id, assoc_item_id) {
1984 Ok(assoc_term) => assoc_term,
1985 Err(guar) => {
1986 return Ok(Projected::Progress(Progress::error_for_term(
1987 tcx,
1988 obligation.predicate,
1989 guar,
1990 )));
1991 }
1992 };
1993
1994 if !assoc_term.item.defaultness(tcx).has_value() {
2000 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/project.rs:2000",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(2000u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::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!("confirm_impl_candidate: no associated type {0:?} for {1:?}",
assoc_term.item.name(), obligation.predicate) as
&dyn Value))])
});
} else { ; }
};debug!(
2001 "confirm_impl_candidate: no associated type {:?} for {:?}",
2002 assoc_term.item.name(),
2003 obligation.predicate
2004 );
2005 if tcx.impl_self_is_guaranteed_unsized(impl_def_id) {
2006 return Ok(Projected::NoProgress(obligation.predicate.to_term(tcx)));
2011 } else {
2012 return Ok(Projected::Progress(Progress {
2013 term: if obligation.predicate.kind(tcx).is_type() {
2014 Ty::new_misc_error(tcx).into()
2015 } else {
2016 ty::Const::new_misc_error(tcx).into()
2017 },
2018 obligations: nested,
2019 }));
2020 }
2021 }
2022
2023 let args = obligation.predicate.args.rebase_onto(tcx, trait_def_id, args);
2030 let args = translate_args(selcx.infcx, param_env, impl_def_id, args, assoc_term.defining_node);
2031
2032 let term = if obligation.predicate.kind(tcx).is_type() {
2033 tcx.type_of(assoc_term.item.def_id).map_bound(|ty| ty.into())
2034 } else {
2035 tcx.const_of_item(assoc_term.item.def_id).map_bound(|ct| ct.into())
2036 };
2037
2038 let progress = if !tcx.check_args_compatible(assoc_term.item.def_id, args) {
2039 let msg = "impl item and trait item have different parameters";
2040 let span = obligation.cause.span;
2041 let err = if obligation.predicate.kind(tcx).is_type() {
2042 Ty::new_error_with_message(tcx, span, msg).into()
2043 } else {
2044 ty::Const::new_error_with_message(tcx, span, msg).into()
2045 };
2046 Progress { term: err, obligations: nested }
2047 } else {
2048 assoc_term_own_obligations(selcx, obligation, &mut nested);
2049 Progress { term: term.instantiate(tcx, args).skip_norm_wip(), obligations: nested }
2050 };
2051 Ok(Projected::Progress(progress))
2052}
2053
2054fn assoc_term_own_obligations<'cx, 'tcx>(
2061 selcx: &mut SelectionContext<'cx, 'tcx>,
2062 obligation: &ProjectionTermObligation<'tcx>,
2063 nested: &mut PredicateObligations<'tcx>,
2064) {
2065 let tcx = selcx.tcx();
2066 let predicates = tcx
2067 .predicates_of(obligation.predicate.def_id())
2068 .instantiate_own(tcx, obligation.predicate.args);
2069 for (predicate, span) in predicates {
2070 let normalized = normalize_with_depth_to(
2071 selcx,
2072 obligation.param_env,
2073 obligation.cause.clone(),
2074 obligation.recursion_depth + 1,
2075 predicate.skip_norm_wip(),
2076 nested,
2077 );
2078
2079 let nested_cause = if #[allow(non_exhaustive_omitted_patterns)] match obligation.cause.code() {
ObligationCauseCode::CompareImplItem { .. } |
ObligationCauseCode::CheckAssociatedTypeBounds { .. } |
ObligationCauseCode::AscribeUserTypeProvePredicate(..) => true,
_ => false,
}matches!(
2080 obligation.cause.code(),
2081 ObligationCauseCode::CompareImplItem { .. }
2082 | ObligationCauseCode::CheckAssociatedTypeBounds { .. }
2083 | ObligationCauseCode::AscribeUserTypeProvePredicate(..)
2084 ) {
2085 obligation.cause.clone()
2086 } else {
2087 ObligationCause::new(
2088 obligation.cause.span,
2089 obligation.cause.body_id,
2090 ObligationCauseCode::WhereClause(obligation.predicate.def_id(), span),
2091 )
2092 };
2093 nested.push(Obligation::with_depth(
2094 tcx,
2095 nested_cause,
2096 obligation.recursion_depth + 1,
2097 obligation.param_env,
2098 normalized,
2099 ));
2100 }
2101}
2102
2103pub(crate) trait ProjectionCacheKeyExt<'cx, 'tcx>: Sized {
2104 fn from_poly_projection_obligation(
2105 selcx: &mut SelectionContext<'cx, 'tcx>,
2106 obligation: &PolyProjectionObligation<'tcx>,
2107 ) -> Option<Self>;
2108}
2109
2110impl<'cx, 'tcx> ProjectionCacheKeyExt<'cx, 'tcx> for ProjectionCacheKey<'tcx> {
2111 fn from_poly_projection_obligation(
2112 selcx: &mut SelectionContext<'cx, 'tcx>,
2113 obligation: &PolyProjectionObligation<'tcx>,
2114 ) -> Option<Self> {
2115 let infcx = selcx.infcx;
2116 obligation.predicate.no_bound_vars().map(|predicate| {
2119 ProjectionCacheKey::new(
2120 infcx.resolve_vars_if_possible(predicate.projection_term),
2125 obligation.param_env,
2126 )
2127 })
2128 }
2129}