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 => selcx.infcx.next_const_var(cause.span).into(),
474 };
475 let mut obligations = PredicateObligations::new();
476 obligations.push(Obligation {
477 cause,
478 recursion_depth: depth,
479 param_env,
480 predicate: trait_ref.upcast(selcx.tcx()),
481 });
482 Normalized { value: new_value, obligations }
483}
484
485#[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(487u32),
::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, 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).into()
} else {
tcx.const_of_item(alias_term.def_id).instantiate(tcx,
args).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))]
488pub fn normalize_inherent_projection<'a, 'b, 'tcx>(
489 selcx: &'a mut SelectionContext<'b, 'tcx>,
490 param_env: ty::ParamEnv<'tcx>,
491 alias_term: ty::AliasTerm<'tcx>,
492 cause: ObligationCause<'tcx>,
493 depth: usize,
494 obligations: &mut PredicateObligations<'tcx>,
495) -> ty::Term<'tcx> {
496 let tcx = selcx.tcx();
497
498 if !tcx.recursion_limit().value_within_limit(depth) {
499 tcx.dcx().emit_fatal(InherentProjectionNormalizationOverflow {
501 span: cause.span,
502 ty: alias_term.to_string(),
503 });
504 }
505
506 let args = compute_inherent_assoc_term_args(
507 selcx,
508 param_env,
509 alias_term,
510 cause.clone(),
511 depth,
512 obligations,
513 );
514
515 let predicates = tcx.predicates_of(alias_term.def_id).instantiate(tcx, args);
517 for (predicate, span) in predicates {
518 let predicate = normalize_with_depth_to(
519 selcx,
520 param_env,
521 cause.clone(),
522 depth + 1,
523 predicate,
524 obligations,
525 );
526
527 let nested_cause = ObligationCause::new(
528 cause.span,
529 cause.body_id,
530 ObligationCauseCode::WhereClause(alias_term.def_id, span),
535 );
536
537 obligations.push(Obligation::with_depth(
538 tcx,
539 nested_cause,
540 depth + 1,
541 param_env,
542 predicate,
543 ));
544 }
545
546 let term: Term<'tcx> = if alias_term.kind(tcx).is_type() {
547 tcx.type_of(alias_term.def_id).instantiate(tcx, args).into()
548 } else {
549 tcx.const_of_item(alias_term.def_id).instantiate(tcx, args).into()
550 };
551
552 let mut term = selcx.infcx.resolve_vars_if_possible(term);
553 if term.has_aliases() {
554 term =
555 normalize_with_depth_to(selcx, param_env, cause.clone(), depth + 1, term, obligations);
556 }
557
558 term
559}
560
561pub fn compute_inherent_assoc_term_args<'a, 'b, 'tcx>(
563 selcx: &'a mut SelectionContext<'b, 'tcx>,
564 param_env: ty::ParamEnv<'tcx>,
565 alias_term: ty::AliasTerm<'tcx>,
566 cause: ObligationCause<'tcx>,
567 depth: usize,
568 obligations: &mut PredicateObligations<'tcx>,
569) -> ty::GenericArgsRef<'tcx> {
570 let tcx = selcx.tcx();
571
572 let impl_def_id = tcx.parent(alias_term.def_id);
573 let impl_args = selcx.infcx.fresh_args_for_item(cause.span, impl_def_id);
574
575 let mut impl_ty = tcx.type_of(impl_def_id).instantiate(tcx, impl_args);
576 if !selcx.infcx.next_trait_solver() {
577 impl_ty = normalize_with_depth_to(
578 selcx,
579 param_env,
580 cause.clone(),
581 depth + 1,
582 impl_ty,
583 obligations,
584 );
585 }
586
587 let mut self_ty = alias_term.self_ty();
590 if !selcx.infcx.next_trait_solver() {
591 self_ty = normalize_with_depth_to(
592 selcx,
593 param_env,
594 cause.clone(),
595 depth + 1,
596 self_ty,
597 obligations,
598 );
599 }
600
601 match selcx.infcx.at(&cause, param_env).eq(DefineOpaqueTypes::Yes, impl_ty, self_ty) {
602 Ok(mut ok) => obligations.append(&mut ok.obligations),
603 Err(_) => {
604 tcx.dcx().span_bug(
605 cause.span,
606 ::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"),
607 );
608 }
609 }
610
611 alias_term.rebase_inherent_args_onto_impl(impl_args, tcx)
612}
613
614enum Projected<'tcx> {
615 Progress(Progress<'tcx>),
616 NoProgress(ty::Term<'tcx>),
617}
618
619struct Progress<'tcx> {
620 term: ty::Term<'tcx>,
621 obligations: PredicateObligations<'tcx>,
622}
623
624impl<'tcx> Progress<'tcx> {
625 fn error_for_term(
626 tcx: TyCtxt<'tcx>,
627 alias_term: ty::AliasTerm<'tcx>,
628 guar: ErrorGuaranteed,
629 ) -> Self {
630 let err_term = if alias_term.kind(tcx).is_type() {
631 Ty::new_error(tcx, guar).into()
632 } else {
633 ty::Const::new_error(tcx, guar).into()
634 };
635 Progress { term: err_term, obligations: PredicateObligations::new() }
636 }
637
638 fn with_addl_obligations(mut self, mut obligations: PredicateObligations<'tcx>) -> Self {
639 self.obligations.append(&mut obligations);
640 self
641 }
642}
643
644#[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(649u32),
::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))]
650fn project<'cx, 'tcx>(
651 selcx: &mut SelectionContext<'cx, 'tcx>,
652 obligation: &ProjectionTermObligation<'tcx>,
653) -> Result<Projected<'tcx>, ProjectionError<'tcx>> {
654 if !selcx.tcx().recursion_limit().value_within_limit(obligation.recursion_depth) {
655 return Err(ProjectionError::TraitSelectionError(SelectionError::Overflow(
658 OverflowError::Canonical,
659 )));
660 }
661
662 if let Err(guar) = obligation.predicate.non_region_error_reported() {
665 return Ok(Projected::Progress(Progress::error_for_term(
666 selcx.tcx(),
667 obligation.predicate,
668 guar,
669 )));
670 }
671
672 let mut candidates = ProjectionCandidateSet::None;
673
674 assemble_candidates_from_param_env(selcx, obligation, &mut candidates);
678
679 assemble_candidates_from_trait_def(selcx, obligation, &mut candidates);
680
681 assemble_candidates_from_object_ty(selcx, obligation, &mut candidates);
682
683 if let ProjectionCandidateSet::Single(ProjectionCandidate::Object(_)) = candidates {
684 } else {
689 assemble_candidates_from_impls(selcx, obligation, &mut candidates);
690 };
691
692 match candidates {
693 ProjectionCandidateSet::Single(candidate) => {
694 confirm_candidate(selcx, obligation, candidate)
695 }
696 ProjectionCandidateSet::None => {
697 let tcx = selcx.tcx();
698 let term = obligation.predicate.to_term(tcx);
699 Ok(Projected::NoProgress(term))
700 }
701 ProjectionCandidateSet::Error(e) => Err(ProjectionError::TraitSelectionError(e)),
703 ProjectionCandidateSet::Ambiguous => Err(ProjectionError::TooManyCandidates),
706 }
707}
708
709fn assemble_candidates_from_param_env<'cx, 'tcx>(
713 selcx: &mut SelectionContext<'cx, 'tcx>,
714 obligation: &ProjectionTermObligation<'tcx>,
715 candidate_set: &mut ProjectionCandidateSet<'tcx>,
716) {
717 assemble_candidates_from_predicates(
718 selcx,
719 obligation,
720 candidate_set,
721 ProjectionCandidate::ParamEnv,
722 obligation.param_env.caller_bounds().iter(),
723 false,
724 );
725}
726
727fn assemble_candidates_from_trait_def<'cx, 'tcx>(
738 selcx: &mut SelectionContext<'cx, 'tcx>,
739 obligation: &ProjectionTermObligation<'tcx>,
740 candidate_set: &mut ProjectionCandidateSet<'tcx>,
741) {
742 {
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:742",
"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(742u32),
::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(..)");
743 let mut ambiguous = false;
744 let _ = selcx.for_each_item_bound(
745 obligation.predicate.self_ty(),
746 |selcx, clause, _, _| {
747 let Some(clause) = clause.as_projection_clause() else {
748 return ControlFlow::Continue(());
749 };
750 if clause.item_def_id() != obligation.predicate.def_id {
751 return ControlFlow::Continue(());
752 }
753
754 let is_match =
755 selcx.infcx.probe(|_| selcx.match_projection_projections(obligation, clause, true));
756
757 match is_match {
758 ProjectionMatchesProjection::Yes => {
759 candidate_set.push_candidate(ProjectionCandidate::TraitDef(clause));
760
761 if !obligation.predicate.has_non_region_infer() {
762 return ControlFlow::Break(());
766 }
767 }
768 ProjectionMatchesProjection::Ambiguous => {
769 candidate_set.mark_ambiguous();
770 }
771 ProjectionMatchesProjection::No => {}
772 }
773
774 ControlFlow::Continue(())
775 },
776 || ambiguous = true,
779 );
780
781 if ambiguous {
782 candidate_set.mark_ambiguous();
783 }
784}
785
786fn assemble_candidates_from_object_ty<'cx, 'tcx>(
796 selcx: &mut SelectionContext<'cx, 'tcx>,
797 obligation: &ProjectionTermObligation<'tcx>,
798 candidate_set: &mut ProjectionCandidateSet<'tcx>,
799) {
800 {
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:800",
"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(800u32),
::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(..)");
801
802 let tcx = selcx.tcx();
803
804 let self_ty = obligation.predicate.self_ty();
805 let object_ty = selcx.infcx.shallow_resolve(self_ty);
806 let data = match object_ty.kind() {
807 ty::Dynamic(data, ..) => data,
808 ty::Infer(ty::TyVar(_)) => {
809 candidate_set.mark_ambiguous();
812 return;
813 }
814 _ => return,
815 };
816 let env_predicates = data
817 .projection_bounds()
818 .filter(|bound| bound.item_def_id() == obligation.predicate.def_id)
819 .map(|p| p.with_self_ty(tcx, object_ty).upcast(tcx));
820
821 assemble_candidates_from_predicates(
822 selcx,
823 obligation,
824 candidate_set,
825 ProjectionCandidate::Object,
826 env_predicates,
827 false,
828 );
829}
830
831#[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(831u32),
::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(
832 level = "debug",
833 skip(selcx, candidate_set, ctor, env_predicates, potentially_unnormalized_candidates)
834)]
835fn assemble_candidates_from_predicates<'cx, 'tcx>(
836 selcx: &mut SelectionContext<'cx, 'tcx>,
837 obligation: &ProjectionTermObligation<'tcx>,
838 candidate_set: &mut ProjectionCandidateSet<'tcx>,
839 ctor: fn(ty::PolyProjectionPredicate<'tcx>) -> ProjectionCandidate<'tcx>,
840 env_predicates: impl Iterator<Item = ty::Clause<'tcx>>,
841 potentially_unnormalized_candidates: bool,
842) {
843 let infcx = selcx.infcx;
844 let drcx = DeepRejectCtxt::relate_rigid_rigid(selcx.tcx());
845 for predicate in env_predicates {
846 let bound_predicate = predicate.kind();
847 if let ty::ClauseKind::Projection(data) = predicate.kind().skip_binder() {
848 let data = bound_predicate.rebind(data);
849 if data.item_def_id() != obligation.predicate.def_id {
850 continue;
851 }
852
853 if !drcx
854 .args_may_unify(obligation.predicate.args, data.skip_binder().projection_term.args)
855 {
856 continue;
857 }
858
859 let is_match = infcx.probe(|_| {
860 selcx.match_projection_projections(
861 obligation,
862 data,
863 potentially_unnormalized_candidates,
864 )
865 });
866
867 match is_match {
868 ProjectionMatchesProjection::Yes => {
869 candidate_set.push_candidate(ctor(data));
870
871 if potentially_unnormalized_candidates
872 && !obligation.predicate.has_non_region_infer()
873 {
874 return;
878 }
879 }
880 ProjectionMatchesProjection::Ambiguous => {
881 candidate_set.mark_ambiguous();
882 }
883 ProjectionMatchesProjection::No => {}
884 }
885 }
886 }
887}
888
889#[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(889u32),
::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:907",
"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(907u32),
::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:956",
"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(956u32),
::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))]
890fn assemble_candidates_from_impls<'cx, 'tcx>(
891 selcx: &mut SelectionContext<'cx, 'tcx>,
892 obligation: &ProjectionTermObligation<'tcx>,
893 candidate_set: &mut ProjectionCandidateSet<'tcx>,
894) {
895 let trait_ref = obligation.predicate.trait_ref(selcx.tcx());
898 let trait_obligation = obligation.with(selcx.tcx(), trait_ref);
899 let _ = selcx.infcx.commit_if_ok(|_| {
900 let impl_source = match selcx.select(&trait_obligation) {
901 Ok(Some(impl_source)) => impl_source,
902 Ok(None) => {
903 candidate_set.mark_ambiguous();
904 return Err(());
905 }
906 Err(e) => {
907 debug!(error = ?e, "selection error");
908 candidate_set.mark_error(e);
909 return Err(());
910 }
911 };
912
913 let eligible = match &impl_source {
914 ImplSource::UserDefined(impl_data) => {
915 match specialization_graph::assoc_def(
938 selcx.tcx(),
939 impl_data.impl_def_id,
940 obligation.predicate.def_id,
941 ) {
942 Ok(node_item) => {
943 if node_item.is_final() {
944 true
946 } else {
947 match selcx.infcx.typing_mode() {
952 TypingMode::Coherence
953 | TypingMode::Analysis { .. }
954 | TypingMode::Borrowck { .. }
955 | TypingMode::PostBorrowckAnalysis { .. } => {
956 debug!(
957 assoc_ty = ?selcx.tcx().def_path_str(node_item.item.def_id),
958 ?obligation.predicate,
959 "not eligible due to default",
960 );
961 false
962 }
963 TypingMode::PostAnalysis => {
964 let poly_trait_ref =
967 selcx.infcx.resolve_vars_if_possible(trait_ref);
968 !poly_trait_ref.still_further_specializable()
969 }
970 }
971 }
972 }
973 Err(ErrorGuaranteed { .. }) => true,
977 }
978 }
979 ImplSource::Builtin(BuiltinImplSource::Misc | BuiltinImplSource::Trivial, _) => {
980 let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
984
985 let tcx = selcx.tcx();
986 match selcx.tcx().as_lang_item(trait_ref.def_id) {
987 Some(
988 LangItem::Coroutine
989 | LangItem::Future
990 | LangItem::Iterator
991 | LangItem::AsyncIterator
992 | LangItem::Field
993 | LangItem::Fn
994 | LangItem::FnMut
995 | LangItem::FnOnce
996 | LangItem::AsyncFn
997 | LangItem::AsyncFnMut
998 | LangItem::AsyncFnOnce,
999 ) => true,
1000 Some(LangItem::AsyncFnKindHelper) => {
1001 if obligation.predicate.args.type_at(0).is_ty_var()
1003 || obligation.predicate.args.type_at(4).is_ty_var()
1004 || obligation.predicate.args.type_at(5).is_ty_var()
1005 {
1006 candidate_set.mark_ambiguous();
1007 true
1008 } else {
1009 obligation.predicate.args.type_at(0).to_opt_closure_kind().is_some()
1010 && obligation
1011 .predicate
1012 .args
1013 .type_at(1)
1014 .to_opt_closure_kind()
1015 .is_some()
1016 }
1017 }
1018 Some(LangItem::DiscriminantKind) => match self_ty.kind() {
1019 ty::Bool
1020 | ty::Char
1021 | ty::Int(_)
1022 | ty::Uint(_)
1023 | ty::Float(_)
1024 | ty::Adt(..)
1025 | ty::Foreign(_)
1026 | ty::Str
1027 | ty::Array(..)
1028 | ty::Pat(..)
1029 | ty::Slice(_)
1030 | ty::RawPtr(..)
1031 | ty::Ref(..)
1032 | ty::FnDef(..)
1033 | ty::FnPtr(..)
1034 | ty::Dynamic(..)
1035 | ty::Closure(..)
1036 | ty::CoroutineClosure(..)
1037 | ty::Coroutine(..)
1038 | ty::CoroutineWitness(..)
1039 | ty::Never
1040 | ty::Tuple(..)
1041 | ty::Infer(ty::InferTy::IntVar(_) | ty::InferTy::FloatVar(..)) => true,
1043
1044 ty::UnsafeBinder(_) => todo!("FIXME(unsafe_binder)"),
1045
1046 ty::Param(_)
1050 | ty::Alias(..)
1051 | ty::Bound(..)
1052 | ty::Placeholder(..)
1053 | ty::Infer(..)
1054 | ty::Error(_) => false,
1055 },
1056 Some(LangItem::PointeeTrait) => {
1057 let tail = selcx.tcx().struct_tail_raw(
1058 self_ty,
1059 &obligation.cause,
1060 |ty| {
1061 normalize_with_depth(
1064 selcx,
1065 obligation.param_env,
1066 obligation.cause.clone(),
1067 obligation.recursion_depth + 1,
1068 ty,
1069 )
1070 .value
1071 },
1072 || {},
1073 );
1074
1075 match tail.kind() {
1076 ty::Bool
1077 | ty::Char
1078 | ty::Int(_)
1079 | ty::Uint(_)
1080 | ty::Float(_)
1081 | ty::Str
1082 | ty::Array(..)
1083 | ty::Pat(..)
1084 | ty::Slice(_)
1085 | ty::RawPtr(..)
1086 | ty::Ref(..)
1087 | ty::FnDef(..)
1088 | ty::FnPtr(..)
1089 | ty::Dynamic(..)
1090 | ty::Closure(..)
1091 | ty::CoroutineClosure(..)
1092 | ty::Coroutine(..)
1093 | ty::CoroutineWitness(..)
1094 | ty::Never
1095 | ty::Foreign(_)
1097 | ty::Adt(..)
1100 | ty::Tuple(..)
1102 | ty::Infer(ty::InferTy::IntVar(_) | ty::InferTy::FloatVar(..))
1104 | ty::Error(..) => true,
1106
1107 ty::Param(_) | ty::Alias(..)
1111 if self_ty != tail
1112 || selcx.infcx.predicate_must_hold_modulo_regions(
1113 &obligation.with(
1114 selcx.tcx(),
1115 ty::TraitRef::new(
1116 selcx.tcx(),
1117 selcx.tcx().require_lang_item(
1118 LangItem::Sized,
1119 obligation.cause.span,
1120 ),
1121 [self_ty],
1122 ),
1123 ),
1124 ) =>
1125 {
1126 true
1127 }
1128
1129 ty::UnsafeBinder(_) => todo!("FIXME(unsafe_binder)"),
1130
1131 ty::Param(_)
1133 | ty::Alias(..)
1134 | ty::Bound(..)
1135 | ty::Placeholder(..)
1136 | ty::Infer(..) => {
1137 if tail.has_infer_types() {
1138 candidate_set.mark_ambiguous();
1139 }
1140 false
1141 }
1142 }
1143 }
1144 _ if tcx.trait_is_auto(trait_ref.def_id) => {
1145 tcx.dcx().span_delayed_bug(
1146 tcx.def_span(obligation.predicate.def_id),
1147 "associated types not allowed on auto traits",
1148 );
1149 false
1150 }
1151 _ => {
1152 bug!("unexpected builtin trait with associated type: {trait_ref:?}")
1153 }
1154 }
1155 }
1156 ImplSource::Param(..) => {
1157 false
1183 }
1184 ImplSource::Builtin(BuiltinImplSource::Object { .. }, _) => {
1185 false
1189 }
1190 ImplSource::Builtin(BuiltinImplSource::TraitUpcasting { .. }, _) => {
1191 selcx.tcx().dcx().span_delayed_bug(
1193 obligation.cause.span,
1194 format!("Cannot project an associated type from `{impl_source:?}`"),
1195 );
1196 return Err(());
1197 }
1198 };
1199
1200 if eligible {
1201 if candidate_set.push_candidate(ProjectionCandidate::Select(impl_source)) {
1202 Ok(())
1203 } else {
1204 Err(())
1205 }
1206 } else {
1207 Err(())
1208 }
1209 });
1210}
1211
1212fn confirm_candidate<'cx, 'tcx>(
1214 selcx: &mut SelectionContext<'cx, 'tcx>,
1215 obligation: &ProjectionTermObligation<'tcx>,
1216 candidate: ProjectionCandidate<'tcx>,
1217) -> Result<Projected<'tcx>, ProjectionError<'tcx>> {
1218 {
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:1218",
"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(1218u32),
::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");
1219 let mut result = match candidate {
1220 ProjectionCandidate::ParamEnv(poly_projection)
1221 | ProjectionCandidate::Object(poly_projection) => Ok(Projected::Progress(
1222 confirm_param_env_candidate(selcx, obligation, poly_projection, false),
1223 )),
1224 ProjectionCandidate::TraitDef(poly_projection) => Ok(Projected::Progress(
1225 confirm_param_env_candidate(selcx, obligation, poly_projection, true),
1226 )),
1227 ProjectionCandidate::Select(impl_source) => {
1228 confirm_select_candidate(selcx, obligation, impl_source)
1229 }
1230 };
1231
1232 if let Ok(Projected::Progress(progress)) = &mut result
1238 && progress.term.has_infer_regions()
1239 {
1240 progress.term = progress.term.fold_with(&mut OpportunisticRegionResolver::new(selcx.infcx));
1241 }
1242
1243 result
1244}
1245
1246fn confirm_select_candidate<'cx, 'tcx>(
1248 selcx: &mut SelectionContext<'cx, 'tcx>,
1249 obligation: &ProjectionTermObligation<'tcx>,
1250 impl_source: Selection<'tcx>,
1251) -> Result<Projected<'tcx>, ProjectionError<'tcx>> {
1252 match impl_source {
1253 ImplSource::UserDefined(data) => confirm_impl_candidate(selcx, obligation, data),
1254 ImplSource::Builtin(BuiltinImplSource::Misc | BuiltinImplSource::Trivial, data) => {
1255 let tcx = selcx.tcx();
1256 let trait_def_id = obligation.predicate.trait_def_id(tcx);
1257 let progress = if tcx.is_lang_item(trait_def_id, LangItem::Coroutine) {
1258 confirm_coroutine_candidate(selcx, obligation, data)
1259 } else if tcx.is_lang_item(trait_def_id, LangItem::Future) {
1260 confirm_future_candidate(selcx, obligation, data)
1261 } else if tcx.is_lang_item(trait_def_id, LangItem::Iterator) {
1262 confirm_iterator_candidate(selcx, obligation, data)
1263 } else if tcx.is_lang_item(trait_def_id, LangItem::AsyncIterator) {
1264 confirm_async_iterator_candidate(selcx, obligation, data)
1265 } else if selcx.tcx().fn_trait_kind_from_def_id(trait_def_id).is_some() {
1266 if obligation.predicate.self_ty().is_closure()
1267 || obligation.predicate.self_ty().is_coroutine_closure()
1268 {
1269 confirm_closure_candidate(selcx, obligation, data)
1270 } else {
1271 confirm_fn_pointer_candidate(selcx, obligation, data)
1272 }
1273 } else if selcx.tcx().async_fn_trait_kind_from_def_id(trait_def_id).is_some() {
1274 confirm_async_closure_candidate(selcx, obligation, data)
1275 } else if tcx.is_lang_item(trait_def_id, LangItem::AsyncFnKindHelper) {
1276 confirm_async_fn_kind_helper_candidate(selcx, obligation, data)
1277 } else {
1278 confirm_builtin_candidate(selcx, obligation, data)
1279 };
1280 Ok(Projected::Progress(progress))
1281 }
1282 ImplSource::Builtin(BuiltinImplSource::Object { .. }, _)
1283 | ImplSource::Param(..)
1284 | ImplSource::Builtin(BuiltinImplSource::TraitUpcasting { .. }, _) => {
1285 ::rustc_middle::util::bug::span_bug_fmt(obligation.cause.span,
format_args!("Cannot project an associated type from `{0:?}`",
impl_source))span_bug!(
1287 obligation.cause.span,
1288 "Cannot project an associated type from `{:?}`",
1289 impl_source
1290 )
1291 }
1292 }
1293}
1294
1295fn confirm_coroutine_candidate<'cx, 'tcx>(
1296 selcx: &mut SelectionContext<'cx, 'tcx>,
1297 obligation: &ProjectionTermObligation<'tcx>,
1298 nested: PredicateObligations<'tcx>,
1299) -> Progress<'tcx> {
1300 let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
1301 let ty::Coroutine(_, args) = self_ty.kind() else {
1302 {
::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!(
1303 "expected coroutine self type for built-in coroutine candidate, found {self_ty}"
1304 )
1305 };
1306 let coroutine_sig = args.as_coroutine().sig();
1307 let Normalized { value: coroutine_sig, obligations } = normalize_with_depth(
1308 selcx,
1309 obligation.param_env,
1310 obligation.cause.clone(),
1311 obligation.recursion_depth + 1,
1312 coroutine_sig,
1313 );
1314
1315 {
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:1315",
"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(1315u32),
::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");
1316
1317 let tcx = selcx.tcx();
1318
1319 let coroutine_def_id = tcx.require_lang_item(LangItem::Coroutine, obligation.cause.span);
1320
1321 let (trait_ref, yield_ty, return_ty) = super::util::coroutine_trait_ref_and_outputs(
1322 tcx,
1323 coroutine_def_id,
1324 obligation.predicate.self_ty(),
1325 coroutine_sig,
1326 );
1327
1328 let ty = if tcx.is_lang_item(obligation.predicate.def_id, LangItem::CoroutineReturn) {
1329 return_ty
1330 } else if tcx.is_lang_item(obligation.predicate.def_id, LangItem::CoroutineYield) {
1331 yield_ty
1332 } else {
1333 ::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!(
1334 tcx.def_span(obligation.predicate.def_id),
1335 "unexpected associated type: `Coroutine::{}`",
1336 tcx.item_name(obligation.predicate.def_id),
1337 );
1338 };
1339
1340 let predicate = ty::ProjectionPredicate {
1341 projection_term: ty::AliasTerm::new_from_args(
1342 tcx,
1343 obligation.predicate.def_id,
1344 trait_ref.args,
1345 ),
1346 term: ty.into(),
1347 };
1348
1349 confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
1350 .with_addl_obligations(nested)
1351 .with_addl_obligations(obligations)
1352}
1353
1354fn confirm_future_candidate<'cx, 'tcx>(
1355 selcx: &mut SelectionContext<'cx, 'tcx>,
1356 obligation: &ProjectionTermObligation<'tcx>,
1357 nested: PredicateObligations<'tcx>,
1358) -> Progress<'tcx> {
1359 let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
1360 let ty::Coroutine(_, args) = self_ty.kind() else {
1361 {
::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!(
1362 "expected coroutine self type for built-in async future candidate, found {self_ty}"
1363 )
1364 };
1365 let coroutine_sig = args.as_coroutine().sig();
1366 let Normalized { value: coroutine_sig, obligations } = normalize_with_depth(
1367 selcx,
1368 obligation.param_env,
1369 obligation.cause.clone(),
1370 obligation.recursion_depth + 1,
1371 coroutine_sig,
1372 );
1373
1374 {
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:1374",
"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(1374u32),
::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");
1375
1376 let tcx = selcx.tcx();
1377 let fut_def_id = tcx.require_lang_item(LangItem::Future, obligation.cause.span);
1378
1379 let (trait_ref, return_ty) = super::util::future_trait_ref_and_outputs(
1380 tcx,
1381 fut_def_id,
1382 obligation.predicate.self_ty(),
1383 coroutine_sig,
1384 );
1385
1386 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);
1387
1388 let predicate = ty::ProjectionPredicate {
1389 projection_term: ty::AliasTerm::new_from_args(
1390 tcx,
1391 obligation.predicate.def_id,
1392 trait_ref.args,
1393 ),
1394 term: return_ty.into(),
1395 };
1396
1397 confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
1398 .with_addl_obligations(nested)
1399 .with_addl_obligations(obligations)
1400}
1401
1402fn confirm_iterator_candidate<'cx, 'tcx>(
1403 selcx: &mut SelectionContext<'cx, 'tcx>,
1404 obligation: &ProjectionTermObligation<'tcx>,
1405 nested: PredicateObligations<'tcx>,
1406) -> Progress<'tcx> {
1407 let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
1408 let ty::Coroutine(_, args) = self_ty.kind() else {
1409 {
::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}")
1410 };
1411 let gen_sig = args.as_coroutine().sig();
1412 let Normalized { value: gen_sig, obligations } = normalize_with_depth(
1413 selcx,
1414 obligation.param_env,
1415 obligation.cause.clone(),
1416 obligation.recursion_depth + 1,
1417 gen_sig,
1418 );
1419
1420 {
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:1420",
"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(1420u32),
::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");
1421
1422 let tcx = selcx.tcx();
1423 let iter_def_id = tcx.require_lang_item(LangItem::Iterator, obligation.cause.span);
1424
1425 let (trait_ref, yield_ty) = super::util::iterator_trait_ref_and_outputs(
1426 tcx,
1427 iter_def_id,
1428 obligation.predicate.self_ty(),
1429 gen_sig,
1430 );
1431
1432 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);
1433
1434 let predicate = ty::ProjectionPredicate {
1435 projection_term: ty::AliasTerm::new_from_args(
1436 tcx,
1437 obligation.predicate.def_id,
1438 trait_ref.args,
1439 ),
1440 term: yield_ty.into(),
1441 };
1442
1443 confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
1444 .with_addl_obligations(nested)
1445 .with_addl_obligations(obligations)
1446}
1447
1448fn confirm_async_iterator_candidate<'cx, 'tcx>(
1449 selcx: &mut SelectionContext<'cx, 'tcx>,
1450 obligation: &ProjectionTermObligation<'tcx>,
1451 nested: PredicateObligations<'tcx>,
1452) -> Progress<'tcx> {
1453 let ty::Coroutine(_, args) = selcx.infcx.shallow_resolve(obligation.predicate.self_ty()).kind()
1454 else {
1455 ::core::panicking::panic("internal error: entered unreachable code")unreachable!()
1456 };
1457 let gen_sig = args.as_coroutine().sig();
1458 let Normalized { value: gen_sig, obligations } = normalize_with_depth(
1459 selcx,
1460 obligation.param_env,
1461 obligation.cause.clone(),
1462 obligation.recursion_depth + 1,
1463 gen_sig,
1464 );
1465
1466 {
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:1466",
"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(1466u32),
::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");
1467
1468 let tcx = selcx.tcx();
1469 let iter_def_id = tcx.require_lang_item(LangItem::AsyncIterator, obligation.cause.span);
1470
1471 let (trait_ref, yield_ty) = super::util::async_iterator_trait_ref_and_outputs(
1472 tcx,
1473 iter_def_id,
1474 obligation.predicate.self_ty(),
1475 gen_sig,
1476 );
1477
1478 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);
1479
1480 let ty::Adt(_poll_adt, args) = *yield_ty.kind() else {
1481 ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"));bug!();
1482 };
1483 let ty::Adt(_option_adt, args) = *args.type_at(0).kind() else {
1484 ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"));bug!();
1485 };
1486 let item_ty = args.type_at(0);
1487
1488 let predicate = ty::ProjectionPredicate {
1489 projection_term: ty::AliasTerm::new_from_args(
1490 tcx,
1491 obligation.predicate.def_id,
1492 trait_ref.args,
1493 ),
1494 term: item_ty.into(),
1495 };
1496
1497 confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
1498 .with_addl_obligations(nested)
1499 .with_addl_obligations(obligations)
1500}
1501
1502fn confirm_builtin_candidate<'cx, 'tcx>(
1503 selcx: &mut SelectionContext<'cx, 'tcx>,
1504 obligation: &ProjectionTermObligation<'tcx>,
1505 data: PredicateObligations<'tcx>,
1506) -> Progress<'tcx> {
1507 let tcx = selcx.tcx();
1508 let self_ty = obligation.predicate.self_ty();
1509 let item_def_id = obligation.predicate.def_id;
1510 let trait_def_id = tcx.parent(item_def_id);
1511 let args = tcx.mk_args(&[self_ty.into()]);
1512 let (term, obligations) = if tcx.is_lang_item(trait_def_id, LangItem::DiscriminantKind) {
1513 let discriminant_def_id =
1514 tcx.require_lang_item(LangItem::Discriminant, obligation.cause.span);
1515 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);
1516
1517 (self_ty.discriminant_ty(tcx).into(), PredicateObligations::new())
1518 } else if tcx.is_lang_item(trait_def_id, LangItem::PointeeTrait) {
1519 let metadata_def_id = tcx.require_lang_item(LangItem::Metadata, obligation.cause.span);
1520 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);
1521
1522 let mut obligations = PredicateObligations::new();
1523 let normalize = |ty| {
1524 normalize_with_depth_to(
1525 selcx,
1526 obligation.param_env,
1527 obligation.cause.clone(),
1528 obligation.recursion_depth + 1,
1529 ty,
1530 &mut obligations,
1531 )
1532 };
1533 let metadata_ty = self_ty.ptr_metadata_ty_or_tail(tcx, normalize).unwrap_or_else(|tail| {
1534 if tail == self_ty {
1535 let sized_predicate = ty::TraitRef::new(
1540 tcx,
1541 tcx.require_lang_item(LangItem::Sized, obligation.cause.span),
1542 [self_ty],
1543 );
1544 obligations.push(obligation.with(tcx, sized_predicate));
1545 tcx.types.unit
1546 } else {
1547 Ty::new_projection(tcx, metadata_def_id, [tail])
1550 }
1551 });
1552 (metadata_ty.into(), obligations)
1553 } else if tcx.is_lang_item(trait_def_id, LangItem::Field) {
1554 let ty::Adt(def, args) = self_ty.kind() else {
1555 ::rustc_middle::util::bug::bug_fmt(format_args!("only field representing types can implement `Field`"))bug!("only field representing types can implement `Field`")
1556 };
1557 let Some(FieldInfo { base, ty, .. }) = def.field_representing_type_info(tcx, args) else {
1558 ::rustc_middle::util::bug::bug_fmt(format_args!("only field representing types can implement `Field`"))bug!("only field representing types can implement `Field`")
1559 };
1560 if tcx.is_lang_item(item_def_id, LangItem::FieldBase) {
1561 (base.into(), PredicateObligations::new())
1562 } else if tcx.is_lang_item(item_def_id, LangItem::FieldType) {
1563 (ty.into(), PredicateObligations::new())
1564 } else {
1565 ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected associated type {0:?} in `Field`",
obligation.predicate));bug!("unexpected associated type {:?} in `Field`", obligation.predicate);
1566 }
1567 } else {
1568 ::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);
1569 };
1570
1571 let predicate = ty::ProjectionPredicate {
1572 projection_term: ty::AliasTerm::new_from_args(tcx, item_def_id, args),
1573 term,
1574 };
1575
1576 confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
1577 .with_addl_obligations(obligations)
1578 .with_addl_obligations(data)
1579}
1580
1581fn confirm_fn_pointer_candidate<'cx, 'tcx>(
1582 selcx: &mut SelectionContext<'cx, 'tcx>,
1583 obligation: &ProjectionTermObligation<'tcx>,
1584 nested: PredicateObligations<'tcx>,
1585) -> Progress<'tcx> {
1586 let tcx = selcx.tcx();
1587 let fn_type = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
1588 let sig = fn_type.fn_sig(tcx);
1589 let Normalized { value: sig, obligations } = normalize_with_depth(
1590 selcx,
1591 obligation.param_env,
1592 obligation.cause.clone(),
1593 obligation.recursion_depth + 1,
1594 sig,
1595 );
1596
1597 confirm_callable_candidate(selcx, obligation, sig, util::TupleArgumentsFlag::Yes)
1598 .with_addl_obligations(nested)
1599 .with_addl_obligations(obligations)
1600}
1601
1602fn confirm_closure_candidate<'cx, 'tcx>(
1603 selcx: &mut SelectionContext<'cx, 'tcx>,
1604 obligation: &ProjectionTermObligation<'tcx>,
1605 nested: PredicateObligations<'tcx>,
1606) -> Progress<'tcx> {
1607 let tcx = selcx.tcx();
1608 let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
1609 let closure_sig = match *self_ty.kind() {
1610 ty::Closure(_, args) => args.as_closure().sig(),
1611
1612 ty::CoroutineClosure(def_id, args) => {
1616 let args = args.as_coroutine_closure();
1617 let kind_ty = args.kind_ty();
1618 args.coroutine_closure_sig().map_bound(|sig| {
1619 let output_ty = if let Some(_) = kind_ty.to_opt_closure_kind()
1623 && !args.tupled_upvars_ty().is_ty_var()
1625 {
1626 sig.to_coroutine_given_kind_and_upvars(
1627 tcx,
1628 args.parent_args(),
1629 tcx.coroutine_for_closure(def_id),
1630 ty::ClosureKind::FnOnce,
1631 tcx.lifetimes.re_static,
1632 args.tupled_upvars_ty(),
1633 args.coroutine_captures_by_ref_ty(),
1634 )
1635 } else {
1636 let upvars_projection_def_id =
1637 tcx.require_lang_item(LangItem::AsyncFnKindUpvars, obligation.cause.span);
1638 let tupled_upvars_ty = Ty::new_projection(
1639 tcx,
1640 upvars_projection_def_id,
1641 [
1642 ty::GenericArg::from(kind_ty),
1643 Ty::from_closure_kind(tcx, ty::ClosureKind::FnOnce).into(),
1644 tcx.lifetimes.re_static.into(),
1645 sig.tupled_inputs_ty.into(),
1646 args.tupled_upvars_ty().into(),
1647 args.coroutine_captures_by_ref_ty().into(),
1648 ],
1649 );
1650 sig.to_coroutine(
1651 tcx,
1652 args.parent_args(),
1653 Ty::from_closure_kind(tcx, ty::ClosureKind::FnOnce),
1654 tcx.coroutine_for_closure(def_id),
1655 tupled_upvars_ty,
1656 )
1657 };
1658 tcx.mk_fn_sig(
1659 [sig.tupled_inputs_ty],
1660 output_ty,
1661 sig.c_variadic,
1662 sig.safety,
1663 sig.abi,
1664 )
1665 })
1666 }
1667
1668 _ => {
1669 {
::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}");
1670 }
1671 };
1672
1673 let Normalized { value: closure_sig, obligations } = normalize_with_depth(
1674 selcx,
1675 obligation.param_env,
1676 obligation.cause.clone(),
1677 obligation.recursion_depth + 1,
1678 closure_sig,
1679 );
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", "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");
1682
1683 confirm_callable_candidate(selcx, obligation, closure_sig, util::TupleArgumentsFlag::No)
1684 .with_addl_obligations(nested)
1685 .with_addl_obligations(obligations)
1686}
1687
1688fn confirm_callable_candidate<'cx, 'tcx>(
1689 selcx: &mut SelectionContext<'cx, 'tcx>,
1690 obligation: &ProjectionTermObligation<'tcx>,
1691 fn_sig: ty::PolyFnSig<'tcx>,
1692 flag: util::TupleArgumentsFlag,
1693) -> Progress<'tcx> {
1694 let tcx = selcx.tcx();
1695
1696 {
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:1696",
"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(1696u32),
::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");
1697
1698 let fn_once_def_id = tcx.require_lang_item(LangItem::FnOnce, obligation.cause.span);
1699 let fn_once_output_def_id =
1700 tcx.require_lang_item(LangItem::FnOnceOutput, obligation.cause.span);
1701
1702 let predicate = super::util::closure_trait_ref_and_return_type(
1703 tcx,
1704 fn_once_def_id,
1705 obligation.predicate.self_ty(),
1706 fn_sig,
1707 flag,
1708 )
1709 .map_bound(|(trait_ref, ret_type)| ty::ProjectionPredicate {
1710 projection_term: ty::AliasTerm::new_from_args(tcx, fn_once_output_def_id, trait_ref.args),
1711 term: ret_type.into(),
1712 });
1713
1714 confirm_param_env_candidate(selcx, obligation, predicate, true)
1715}
1716
1717fn confirm_async_closure_candidate<'cx, 'tcx>(
1718 selcx: &mut SelectionContext<'cx, 'tcx>,
1719 obligation: &ProjectionTermObligation<'tcx>,
1720 nested: PredicateObligations<'tcx>,
1721) -> Progress<'tcx> {
1722 let tcx = selcx.tcx();
1723 let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
1724
1725 let goal_kind =
1726 tcx.async_fn_trait_kind_from_def_id(obligation.predicate.trait_def_id(tcx)).unwrap();
1727 let env_region = match goal_kind {
1728 ty::ClosureKind::Fn | ty::ClosureKind::FnMut => obligation.predicate.args.region_at(2),
1729 ty::ClosureKind::FnOnce => tcx.lifetimes.re_static,
1730 };
1731 let item_name = tcx.item_name(obligation.predicate.def_id);
1732
1733 let poly_cache_entry = match *self_ty.kind() {
1734 ty::CoroutineClosure(def_id, args) => {
1735 let args = args.as_coroutine_closure();
1736 let kind_ty = args.kind_ty();
1737 let sig = args.coroutine_closure_sig().skip_binder();
1738
1739 let term = match item_name {
1740 sym::CallOnceFuture | sym::CallRefFuture => {
1741 if let Some(closure_kind) = kind_ty.to_opt_closure_kind()
1742 && !args.tupled_upvars_ty().is_ty_var()
1744 {
1745 if !closure_kind.extends(goal_kind) {
1746 ::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");
1747 }
1748 sig.to_coroutine_given_kind_and_upvars(
1749 tcx,
1750 args.parent_args(),
1751 tcx.coroutine_for_closure(def_id),
1752 goal_kind,
1753 env_region,
1754 args.tupled_upvars_ty(),
1755 args.coroutine_captures_by_ref_ty(),
1756 )
1757 } else {
1758 let upvars_projection_def_id = tcx
1759 .require_lang_item(LangItem::AsyncFnKindUpvars, obligation.cause.span);
1760 let tupled_upvars_ty = Ty::new_projection(
1769 tcx,
1770 upvars_projection_def_id,
1771 [
1772 ty::GenericArg::from(kind_ty),
1773 Ty::from_closure_kind(tcx, goal_kind).into(),
1774 env_region.into(),
1775 sig.tupled_inputs_ty.into(),
1776 args.tupled_upvars_ty().into(),
1777 args.coroutine_captures_by_ref_ty().into(),
1778 ],
1779 );
1780 sig.to_coroutine(
1781 tcx,
1782 args.parent_args(),
1783 Ty::from_closure_kind(tcx, goal_kind),
1784 tcx.coroutine_for_closure(def_id),
1785 tupled_upvars_ty,
1786 )
1787 }
1788 }
1789 sym::Output => sig.return_ty,
1790 name => ::rustc_middle::util::bug::bug_fmt(format_args!("no such associated type: {0}",
name))bug!("no such associated type: {name}"),
1791 };
1792 let projection_term = match item_name {
1793 sym::CallOnceFuture | sym::Output => ty::AliasTerm::new(
1794 tcx,
1795 obligation.predicate.def_id,
1796 [self_ty, sig.tupled_inputs_ty],
1797 ),
1798 sym::CallRefFuture => ty::AliasTerm::new(
1799 tcx,
1800 obligation.predicate.def_id,
1801 [ty::GenericArg::from(self_ty), sig.tupled_inputs_ty.into(), env_region.into()],
1802 ),
1803 name => ::rustc_middle::util::bug::bug_fmt(format_args!("no such associated type: {0}",
name))bug!("no such associated type: {name}"),
1804 };
1805
1806 args.coroutine_closure_sig()
1807 .rebind(ty::ProjectionPredicate { projection_term, term: term.into() })
1808 }
1809 ty::FnDef(..) | ty::FnPtr(..) => {
1810 let bound_sig = self_ty.fn_sig(tcx);
1811 let sig = bound_sig.skip_binder();
1812
1813 let term = match item_name {
1814 sym::CallOnceFuture | sym::CallRefFuture => sig.output(),
1815 sym::Output => {
1816 let future_output_def_id =
1817 tcx.require_lang_item(LangItem::FutureOutput, obligation.cause.span);
1818 Ty::new_projection(tcx, future_output_def_id, [sig.output()])
1819 }
1820 name => ::rustc_middle::util::bug::bug_fmt(format_args!("no such associated type: {0}",
name))bug!("no such associated type: {name}"),
1821 };
1822 let projection_term = match item_name {
1823 sym::CallOnceFuture | sym::Output => ty::AliasTerm::new(
1824 tcx,
1825 obligation.predicate.def_id,
1826 [self_ty, Ty::new_tup(tcx, sig.inputs())],
1827 ),
1828 sym::CallRefFuture => ty::AliasTerm::new(
1829 tcx,
1830 obligation.predicate.def_id,
1831 [
1832 ty::GenericArg::from(self_ty),
1833 Ty::new_tup(tcx, sig.inputs()).into(),
1834 env_region.into(),
1835 ],
1836 ),
1837 name => ::rustc_middle::util::bug::bug_fmt(format_args!("no such associated type: {0}",
name))bug!("no such associated type: {name}"),
1838 };
1839
1840 bound_sig.rebind(ty::ProjectionPredicate { projection_term, term: term.into() })
1841 }
1842 ty::Closure(_, args) => {
1843 let args = args.as_closure();
1844 let bound_sig = args.sig();
1845 let sig = bound_sig.skip_binder();
1846
1847 let term = match item_name {
1848 sym::CallOnceFuture | sym::CallRefFuture => sig.output(),
1849 sym::Output => {
1850 let future_output_def_id =
1851 tcx.require_lang_item(LangItem::FutureOutput, obligation.cause.span);
1852 Ty::new_projection(tcx, future_output_def_id, [sig.output()])
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 let projection_term = match item_name {
1857 sym::CallOnceFuture | sym::Output => {
1858 ty::AliasTerm::new(tcx, obligation.predicate.def_id, [self_ty, sig.inputs()[0]])
1859 }
1860 sym::CallRefFuture => ty::AliasTerm::new(
1861 tcx,
1862 obligation.predicate.def_id,
1863 [ty::GenericArg::from(self_ty), sig.inputs()[0].into(), env_region.into()],
1864 ),
1865 name => ::rustc_middle::util::bug::bug_fmt(format_args!("no such associated type: {0}",
name))bug!("no such associated type: {name}"),
1866 };
1867
1868 bound_sig.rebind(ty::ProjectionPredicate { projection_term, term: term.into() })
1869 }
1870 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("expected callable type for AsyncFn candidate"))bug!("expected callable type for AsyncFn candidate"),
1871 };
1872
1873 confirm_param_env_candidate(selcx, obligation, poly_cache_entry, true)
1874 .with_addl_obligations(nested)
1875}
1876
1877fn confirm_async_fn_kind_helper_candidate<'cx, 'tcx>(
1878 selcx: &mut SelectionContext<'cx, 'tcx>,
1879 obligation: &ProjectionTermObligation<'tcx>,
1880 nested: PredicateObligations<'tcx>,
1881) -> Progress<'tcx> {
1882 let [
1883 _closure_kind_ty,
1885 goal_kind_ty,
1886 borrow_region,
1887 tupled_inputs_ty,
1888 tupled_upvars_ty,
1889 coroutine_captures_by_ref_ty,
1890 ] = **obligation.predicate.args
1891 else {
1892 ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"));bug!();
1893 };
1894
1895 let predicate = ty::ProjectionPredicate {
1896 projection_term: ty::AliasTerm::new_from_args(
1897 selcx.tcx(),
1898 obligation.predicate.def_id,
1899 obligation.predicate.args,
1900 ),
1901 term: ty::CoroutineClosureSignature::tupled_upvars_by_closure_kind(
1902 selcx.tcx(),
1903 goal_kind_ty.expect_ty().to_opt_closure_kind().unwrap(),
1904 tupled_inputs_ty.expect_ty(),
1905 tupled_upvars_ty.expect_ty(),
1906 coroutine_captures_by_ref_ty.expect_ty(),
1907 borrow_region.expect_region(),
1908 )
1909 .into(),
1910 };
1911
1912 confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
1913 .with_addl_obligations(nested)
1914}
1915
1916fn confirm_param_env_candidate<'cx, 'tcx>(
1918 selcx: &mut SelectionContext<'cx, 'tcx>,
1919 obligation: &ProjectionTermObligation<'tcx>,
1920 poly_cache_entry: ty::PolyProjectionPredicate<'tcx>,
1921 potentially_unnormalized_candidate: bool,
1922) -> Progress<'tcx> {
1923 let infcx = selcx.infcx;
1924 let cause = &obligation.cause;
1925 let param_env = obligation.param_env;
1926
1927 let cache_entry = infcx.instantiate_binder_with_fresh_vars(
1928 cause.span,
1929 BoundRegionConversionTime::HigherRankedType,
1930 poly_cache_entry,
1931 );
1932
1933 let cache_projection = cache_entry.projection_term;
1934 let mut nested_obligations = PredicateObligations::new();
1935 let obligation_projection = obligation.predicate;
1936 let obligation_projection = ensure_sufficient_stack(|| {
1937 normalize_with_depth_to(
1938 selcx,
1939 obligation.param_env,
1940 obligation.cause.clone(),
1941 obligation.recursion_depth + 1,
1942 obligation_projection,
1943 &mut nested_obligations,
1944 )
1945 });
1946 let cache_projection = if potentially_unnormalized_candidate {
1947 ensure_sufficient_stack(|| {
1948 normalize_with_depth_to(
1949 selcx,
1950 obligation.param_env,
1951 obligation.cause.clone(),
1952 obligation.recursion_depth + 1,
1953 cache_projection,
1954 &mut nested_obligations,
1955 )
1956 })
1957 } else {
1958 cache_projection
1959 };
1960
1961 {
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:1961",
"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(1961u32),
::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);
1962
1963 match infcx.at(cause, param_env).eq(
1964 DefineOpaqueTypes::Yes,
1965 cache_projection,
1966 obligation_projection,
1967 ) {
1968 Ok(InferOk { value: _, obligations }) => {
1969 nested_obligations.extend(obligations);
1970 assoc_term_own_obligations(selcx, obligation, &mut nested_obligations);
1971 Progress { term: cache_entry.term, obligations: nested_obligations }
1972 }
1973 Err(e) => {
1974 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!(
1975 "Failed to unify obligation `{obligation:?}` with poly_projection `{poly_cache_entry:?}`: {e:?}",
1976 );
1977 {
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:1977",
"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(1977u32),
::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);
1978 let err = Ty::new_error_with_message(infcx.tcx, obligation.cause.span, msg);
1979 Progress { term: err.into(), obligations: PredicateObligations::new() }
1980 }
1981 }
1982}
1983
1984fn confirm_impl_candidate<'cx, 'tcx>(
1986 selcx: &mut SelectionContext<'cx, 'tcx>,
1987 obligation: &ProjectionTermObligation<'tcx>,
1988 impl_impl_source: ImplSourceUserDefinedData<'tcx, PredicateObligation<'tcx>>,
1989) -> Result<Projected<'tcx>, ProjectionError<'tcx>> {
1990 let tcx = selcx.tcx();
1991
1992 let ImplSourceUserDefinedData { impl_def_id, args, mut nested } = impl_impl_source;
1993
1994 let assoc_item_id = obligation.predicate.def_id;
1995 let trait_def_id = tcx.impl_trait_id(impl_def_id);
1996
1997 let param_env = obligation.param_env;
1998 let assoc_term = match specialization_graph::assoc_def(tcx, impl_def_id, assoc_item_id) {
1999 Ok(assoc_term) => assoc_term,
2000 Err(guar) => {
2001 return Ok(Projected::Progress(Progress::error_for_term(
2002 tcx,
2003 obligation.predicate,
2004 guar,
2005 )));
2006 }
2007 };
2008
2009 if !assoc_term.item.defaultness(tcx).has_value() {
2015 {
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:2015",
"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(2015u32),
::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!(
2016 "confirm_impl_candidate: no associated type {:?} for {:?}",
2017 assoc_term.item.name(),
2018 obligation.predicate
2019 );
2020 if tcx.impl_self_is_guaranteed_unsized(impl_def_id) {
2021 return Ok(Projected::NoProgress(obligation.predicate.to_term(tcx)));
2026 } else {
2027 return Ok(Projected::Progress(Progress {
2028 term: if obligation.predicate.kind(tcx).is_type() {
2029 Ty::new_misc_error(tcx).into()
2030 } else {
2031 ty::Const::new_misc_error(tcx).into()
2032 },
2033 obligations: nested,
2034 }));
2035 }
2036 }
2037
2038 let args = obligation.predicate.args.rebase_onto(tcx, trait_def_id, args);
2045 let args = translate_args(selcx.infcx, param_env, impl_def_id, args, assoc_term.defining_node);
2046
2047 let term = if obligation.predicate.kind(tcx).is_type() {
2048 tcx.type_of(assoc_term.item.def_id).map_bound(|ty| ty.into())
2049 } else {
2050 tcx.const_of_item(assoc_term.item.def_id).map_bound(|ct| ct.into())
2051 };
2052
2053 let progress = if !tcx.check_args_compatible(assoc_term.item.def_id, args) {
2054 let msg = "impl item and trait item have different parameters";
2055 let span = obligation.cause.span;
2056 let err = if obligation.predicate.kind(tcx).is_type() {
2057 Ty::new_error_with_message(tcx, span, msg).into()
2058 } else {
2059 ty::Const::new_error_with_message(tcx, span, msg).into()
2060 };
2061 Progress { term: err, obligations: nested }
2062 } else {
2063 assoc_term_own_obligations(selcx, obligation, &mut nested);
2064 Progress { term: term.instantiate(tcx, args), obligations: nested }
2065 };
2066 Ok(Projected::Progress(progress))
2067}
2068
2069fn assoc_term_own_obligations<'cx, 'tcx>(
2076 selcx: &mut SelectionContext<'cx, 'tcx>,
2077 obligation: &ProjectionTermObligation<'tcx>,
2078 nested: &mut PredicateObligations<'tcx>,
2079) {
2080 let tcx = selcx.tcx();
2081 let predicates = tcx
2082 .predicates_of(obligation.predicate.def_id)
2083 .instantiate_own(tcx, obligation.predicate.args);
2084 for (predicate, span) in predicates {
2085 let normalized = normalize_with_depth_to(
2086 selcx,
2087 obligation.param_env,
2088 obligation.cause.clone(),
2089 obligation.recursion_depth + 1,
2090 predicate,
2091 nested,
2092 );
2093
2094 let nested_cause = if #[allow(non_exhaustive_omitted_patterns)] match obligation.cause.code() {
ObligationCauseCode::CompareImplItem { .. } |
ObligationCauseCode::CheckAssociatedTypeBounds { .. } |
ObligationCauseCode::AscribeUserTypeProvePredicate(..) => true,
_ => false,
}matches!(
2095 obligation.cause.code(),
2096 ObligationCauseCode::CompareImplItem { .. }
2097 | ObligationCauseCode::CheckAssociatedTypeBounds { .. }
2098 | ObligationCauseCode::AscribeUserTypeProvePredicate(..)
2099 ) {
2100 obligation.cause.clone()
2101 } else {
2102 ObligationCause::new(
2103 obligation.cause.span,
2104 obligation.cause.body_id,
2105 ObligationCauseCode::WhereClause(obligation.predicate.def_id, span),
2106 )
2107 };
2108 nested.push(Obligation::with_depth(
2109 tcx,
2110 nested_cause,
2111 obligation.recursion_depth + 1,
2112 obligation.param_env,
2113 normalized,
2114 ));
2115 }
2116}
2117
2118pub(crate) trait ProjectionCacheKeyExt<'cx, 'tcx>: Sized {
2119 fn from_poly_projection_obligation(
2120 selcx: &mut SelectionContext<'cx, 'tcx>,
2121 obligation: &PolyProjectionObligation<'tcx>,
2122 ) -> Option<Self>;
2123}
2124
2125impl<'cx, 'tcx> ProjectionCacheKeyExt<'cx, 'tcx> for ProjectionCacheKey<'tcx> {
2126 fn from_poly_projection_obligation(
2127 selcx: &mut SelectionContext<'cx, 'tcx>,
2128 obligation: &PolyProjectionObligation<'tcx>,
2129 ) -> Option<Self> {
2130 let infcx = selcx.infcx;
2131 obligation.predicate.no_bound_vars().map(|predicate| {
2134 ProjectionCacheKey::new(
2135 infcx.resolve_vars_if_possible(predicate.projection_term),
2140 obligation.param_env,
2141 )
2142 })
2143 }
2144}