1use std::ops::ControlFlow;
4
5use rustc_data_structures::sso::SsoHashSet;
6use rustc_errors::ErrorGuaranteed;
7use rustc_hir::attrs::lang_items::LangItem;
8use rustc_hir::def_id::DefId;
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, Unnormalized,
17 Upcast,
18};
19use rustc_middle::{bug, span_bug};
20use rustc_span::sym;
21use tracing::{debug, instrument};
22
23use super::{
24 MismatchedProjectionTypes, Normalized, NormalizedTerm, Obligation, ObligationCause,
25 PredicateObligation, ProjectionCacheEntry, ProjectionCacheKey, Selection, SelectionContext,
26 SelectionError, specialization_graph, translate_args, util,
27};
28use crate::diagnostics::InherentProjectionNormalizationOverflow;
29use crate::error_reporting::traits::report_dyn_incompatibility;
30use crate::infer::{BoundRegionConversionTime, InferOk};
31use crate::traits::normalize::{normalize_with_depth, normalize_with_depth_to};
32use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
33use crate::traits::select::ProjectionMatchesProjection;
34
35pub type PolyProjectionObligation<'tcx> = Obligation<'tcx, ty::PolyProjectionClause<'tcx>>;
36
37pub type ProjectionObligation<'tcx> = Obligation<'tcx, ty::ProjectionClause<'tcx>>;
38
39pub type ProjectionTermObligation<'tcx> = Obligation<'tcx, ty::AliasTerm<'tcx>>;
40
41pub(super) struct InProgress;
42
43#[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)]
45pub enum ProjectionError<'tcx> {
46 TooManyCandidates,
48
49 TraitSelectionError(SelectionError<'tcx>),
51}
52
53#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::StructuralPartialEq for ProjectionCandidate<'tcx> {
}
#[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::PolyProjectionClause<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<ty::PolyProjectionClause<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<ty::PolyProjectionClause<'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)]
54enum ProjectionCandidate<'tcx> {
55 ParamEnv(ty::PolyProjectionClause<'tcx>),
57
58 TraitDef(ty::PolyProjectionClause<'tcx>),
61
62 Object(ty::PolyProjectionClause<'tcx>),
64
65 Select(Selection<'tcx>),
67}
68
69enum ProjectionCandidateSet<'tcx> {
70 None,
71 Single(ProjectionCandidate<'tcx>),
72 Ambiguous,
73 Error(SelectionError<'tcx>),
74}
75
76impl<'tcx> ProjectionCandidateSet<'tcx> {
77 fn mark_ambiguous(&mut self) {
78 *self = ProjectionCandidateSet::Ambiguous;
79 }
80
81 fn mark_error(&mut self, err: SelectionError<'tcx>) {
82 *self = ProjectionCandidateSet::Error(err);
83 }
84
85 fn push_candidate(&mut self, candidate: ProjectionCandidate<'tcx>) -> bool {
89 let convert_to_ambiguous;
98
99 match self {
100 ProjectionCandidateSet::None => {
101 *self = ProjectionCandidateSet::Single(candidate);
102 return true;
103 }
104
105 ProjectionCandidateSet::Single(current) => {
106 if current == &candidate {
109 return false;
110 }
111
112 match (current, candidate) {
120 (ProjectionCandidate::ParamEnv(..), ProjectionCandidate::ParamEnv(..)) => {
121 convert_to_ambiguous = ()
122 }
123 (ProjectionCandidate::ParamEnv(..), _) => return false,
124 (_, ProjectionCandidate::ParamEnv(..)) => ::rustc_middle::util::bug::bug_fmt(format_args!("should never prefer non-param-env candidates over param-env candidates"))bug!(
125 "should never prefer non-param-env candidates over param-env candidates"
126 ),
127 (_, _) => convert_to_ambiguous = (),
128 }
129 }
130
131 ProjectionCandidateSet::Ambiguous | ProjectionCandidateSet::Error(..) => {
132 return false;
133 }
134 }
135
136 let () = convert_to_ambiguous;
139 *self = ProjectionCandidateSet::Ambiguous;
140 false
141 }
142}
143
144pub(super) enum ProjectAndUnifyResult<'tcx> {
153 Holds(PredicateObligations<'tcx>),
158 FailedNormalization,
161 Recursive,
164 MismatchedProjectionTypes(MismatchedProjectionTypes<'tcx>),
167}
168
169{}
#[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("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(176u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligation")
}> =
::tracing::__macro_support::FieldName::new("obligation");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::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))]
177pub(super) fn poly_project_and_unify_term<'cx, 'tcx>(
178 selcx: &mut SelectionContext<'cx, 'tcx>,
179 obligation: &PolyProjectionObligation<'tcx>,
180) -> ProjectAndUnifyResult<'tcx> {
181 let infcx = selcx.infcx;
182 let r = infcx.commit_if_ok(|_snapshot| {
183 let placeholder_predicate = infcx.enter_forall_and_leak_universe(obligation.predicate);
184
185 let placeholder_obligation = obligation.with(infcx.tcx, placeholder_predicate);
186 match project_and_unify_term(selcx, &placeholder_obligation) {
187 ProjectAndUnifyResult::MismatchedProjectionTypes(e) => Err(e),
188 other => Ok(other),
189 }
190 });
191
192 match r {
193 Ok(inner) => inner,
194 Err(err) => ProjectAndUnifyResult::MismatchedProjectionTypes(err),
195 }
196}
197
198{}
#[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("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(206u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligation")
}> =
::tracing::__macro_support::FieldName::new("obligation");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::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 /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:226",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(226u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("normalized")
}> =
::tracing::__macro_support::FieldName::new("normalized");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligations")
}> =
::tracing::__macro_support::FieldName::new("obligations");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("project_and_unify_type result")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&normalized)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligations)
as &dyn ::tracing::field::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_def_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 /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:251",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(251u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("equating types encountered error {0:?}",
err) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
ProjectAndUnifyResult::MismatchedProjectionTypes(MismatchedProjectionTypes {
err,
})
}
}
}
}
}#[instrument(level = "debug", skip(selcx))]
207fn project_and_unify_term<'cx, 'tcx>(
208 selcx: &mut SelectionContext<'cx, 'tcx>,
209 obligation: &ProjectionObligation<'tcx>,
210) -> ProjectAndUnifyResult<'tcx> {
211 let mut obligations = PredicateObligations::new();
212
213 let infcx = selcx.infcx;
214 let normalized = match opt_normalize_projection_term(
215 selcx,
216 obligation.param_env,
217 obligation.predicate.projection_term,
218 obligation.cause.clone(),
219 obligation.recursion_depth,
220 &mut obligations,
221 ) {
222 Ok(Some(n)) => n,
223 Ok(None) => return ProjectAndUnifyResult::FailedNormalization,
224 Err(InProgress) => return ProjectAndUnifyResult::Recursive,
225 };
226 debug!(?normalized, ?obligations, "project_and_unify_type result");
227 let actual = obligation.predicate.term;
228 let InferOk { value: actual, obligations: new } =
232 selcx.infcx.replace_opaque_types_with_inference_vars(
233 actual,
234 obligation.cause.body_def_id,
235 obligation.cause.span,
236 obligation.param_env,
237 );
238 obligations.extend(new);
239
240 match infcx.at(&obligation.cause, obligation.param_env).eq(
242 DefineOpaqueTypes::Yes,
243 normalized,
244 actual,
245 ) {
246 Ok(InferOk { obligations: inferred_obligations, value: () }) => {
247 obligations.extend(inferred_obligations);
248 ProjectAndUnifyResult::Holds(obligations)
249 }
250 Err(err) => {
251 debug!("equating types encountered error {:?}", err);
252 ProjectAndUnifyResult::MismatchedProjectionTypes(MismatchedProjectionTypes { err })
253 }
254 }
255}
256
257pub fn normalize_projection_term<'a, 'b, 'tcx>(
265 selcx: &'a mut SelectionContext<'b, 'tcx>,
266 param_env: ty::ParamEnv<'tcx>,
267 alias_term: ty::AliasTerm<'tcx>,
268 cause: ObligationCause<'tcx>,
269 depth: usize,
270 obligations: &mut PredicateObligations<'tcx>,
271) -> Term<'tcx> {
272 opt_normalize_projection_term(selcx, param_env, alias_term, cause.clone(), depth, obligations)
273 .ok()
274 .flatten()
275 .unwrap_or_else(move || {
276 selcx.infcx.projection_term_to_infer(
281 param_env,
282 alias_term,
283 cause,
284 depth + 1,
285 obligations,
286 )
287 })
288}
289
290{}
#[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("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(301u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("projection_term")
}> =
::tracing::__macro_support::FieldName::new("projection_term");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("depth")
}> =
::tracing::__macro_support::FieldName::new("depth");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&projection_term)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&depth as
&dyn ::tracing::field::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 /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:324",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("no cache")
as &dyn ::tracing::field::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 /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:329",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(329u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("found cache entry: ambiguous")
as &dyn ::tracing::field::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 /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:341",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(341u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("found cache entry: in-progress")
as &dyn ::tracing::field::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 /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:350",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(350u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("recur cache")
as &dyn ::tracing::field::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 /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:365",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/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",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ty")
}> =
::tracing::__macro_support::FieldName::new("ty");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("found normalized ty")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty)
as &dyn ::tracing::field::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 /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:370",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(370u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("opt_normalize_projection_type: found error")
as &dyn ::tracing::field::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 /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:385",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(385u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("opt_normalize_projection_type: progress")
as &dyn ::tracing::field::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.skip_normalization(),
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 /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:419",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("opt_normalize_projection_type: no progress")
as &dyn ::tracing::field::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 /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:427",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(427u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("opt_normalize_projection_type: too many candidates")
as &dyn ::tracing::field::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 /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:432",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(432u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("opt_normalize_projection_type: ERROR")
as &dyn ::tracing::field::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))]
302pub(super) fn opt_normalize_projection_term<'a, 'b, 'tcx>(
303 selcx: &'a mut SelectionContext<'b, 'tcx>,
304 param_env: ty::ParamEnv<'tcx>,
305 projection_term: ty::AliasTerm<'tcx>,
306 cause: ObligationCause<'tcx>,
307 depth: usize,
308 obligations: &mut PredicateObligations<'tcx>,
309) -> Result<Option<Term<'tcx>>, InProgress> {
310 let infcx = selcx.infcx;
311 debug_assert!(!selcx.infcx.next_trait_solver());
312 let projection_term = infcx.resolve_vars_if_possible(projection_term);
313 let cache_key = ProjectionCacheKey::new(projection_term, param_env);
314
315 let cache_entry = infcx.inner.borrow_mut().projection_cache().try_start(cache_key);
323 match cache_entry {
324 Ok(()) => debug!("no cache"),
325 Err(ProjectionCacheEntry::Ambiguous) => {
326 debug!("found cache entry: ambiguous");
330 return Ok(None);
331 }
332 Err(ProjectionCacheEntry::InProgress) => {
333 debug!("found cache entry: in-progress");
342
343 infcx.inner.borrow_mut().projection_cache().recur(cache_key);
347 return Err(InProgress);
348 }
349 Err(ProjectionCacheEntry::Recur) => {
350 debug!("recur cache");
351 return Err(InProgress);
352 }
353 Err(ProjectionCacheEntry::NormalizedTerm { ty, complete: _ }) => {
354 debug!(?ty, "found normalized ty");
366 obligations.extend(ty.obligations);
367 return Ok(Some(ty.value));
368 }
369 Err(ProjectionCacheEntry::Error) => {
370 debug!("opt_normalize_projection_type: found error");
371 let result = normalize_to_error(selcx, param_env, projection_term, cause, depth);
372 obligations.extend(result.obligations);
373 return Ok(Some(result.value));
374 }
375 }
376
377 let obligation =
378 Obligation::with_depth(selcx.tcx(), cause.clone(), depth, param_env, projection_term);
379
380 match project(selcx, &obligation) {
381 Ok(Projected::Progress(Progress {
382 term: projected_term,
383 obligations: mut projected_obligations,
384 })) => {
385 debug!("opt_normalize_projection_type: progress");
386 let projected_term = selcx.infcx.resolve_vars_if_possible(projected_term);
392
393 let mut result = if projected_term.has_aliases() {
394 let normalized_ty = normalize_with_depth_to(
395 selcx,
396 param_env,
397 cause,
398 depth + 1,
399 projected_term,
400 &mut projected_obligations,
401 );
402
403 Normalized { value: normalized_ty, obligations: projected_obligations }
404 } else {
405 Normalized {
406 value: projected_term.skip_normalization(),
407 obligations: projected_obligations,
408 }
409 };
410
411 let mut deduped = SsoHashSet::with_capacity(result.obligations.len());
412 result.obligations.retain(|obligation| deduped.insert(obligation.clone()));
413
414 infcx.inner.borrow_mut().projection_cache().insert_term(cache_key, result.clone());
415 obligations.extend(result.obligations);
416 Ok(Some(result.value))
417 }
418 Ok(Projected::NoProgress(projected_ty)) => {
419 debug!("opt_normalize_projection_type: no progress");
420 let result =
421 Normalized { value: projected_ty, obligations: PredicateObligations::new() };
422 infcx.inner.borrow_mut().projection_cache().insert_term(cache_key, result.clone());
423 Ok(Some(result.value))
425 }
426 Err(ProjectionError::TooManyCandidates) => {
427 debug!("opt_normalize_projection_type: too many candidates");
428 infcx.inner.borrow_mut().projection_cache().ambiguous(cache_key);
429 Ok(None)
430 }
431 Err(ProjectionError::TraitSelectionError(_)) => {
432 debug!("opt_normalize_projection_type: ERROR");
433 infcx.inner.borrow_mut().projection_cache().error(cache_key);
438 let result = normalize_to_error(selcx, param_env, projection_term, cause, depth);
439 obligations.extend(result.obligations);
440 Ok(Some(result.value))
441 }
442 }
443}
444
445fn normalize_to_error<'a, 'tcx>(
466 selcx: &SelectionContext<'a, 'tcx>,
467 param_env: ty::ParamEnv<'tcx>,
468 projection_term: ty::AliasTerm<'tcx>,
469 cause: ObligationCause<'tcx>,
470 depth: usize,
471) -> NormalizedTerm<'tcx> {
472 let trait_ref = ty::Binder::dummy(projection_term.trait_ref(selcx.tcx()));
473 let new_value = selcx.infcx.next_term_var_of_alias_kind(projection_term, cause.span);
474 let mut obligations = PredicateObligations::new();
475 obligations.push(Obligation {
476 cause,
477 recursion_depth: depth,
478 param_env,
479 predicate: trait_ref.upcast(selcx.tcx()),
480 });
481 Normalized { value: new_value, obligations }
482}
483
484fn push_const_arg_has_type_obligation<'tcx>(
487 tcx: TyCtxt<'tcx>,
488 obligations: &mut PredicateObligations<'tcx>,
489 cause: &ObligationCause<'tcx>,
490 depth: usize,
491 param_env: ty::ParamEnv<'tcx>,
492 term: Term<'tcx>,
493 def_id: DefId,
494 args: ty::GenericArgsRef<'tcx>,
495) {
496 if let Some(ct) = term.as_const() {
497 let expected_ty = tcx.type_of(def_id).instantiate(tcx, args).skip_norm_wip();
498 obligations.push(Obligation::with_depth(
499 tcx,
500 cause.clone(),
501 depth,
502 param_env,
503 ty::ClauseKind::ConstArgHasType(ct, expected_ty),
504 ));
505 }
506}
507
508pub fn const_of_item_or_delayed_bug<'tcx>(
512 tcx: TyCtxt<'tcx>,
513 def_id: DefId,
514) -> ty::EarlyBinder<'tcx, ty::Const<'tcx>> {
515 tcx.const_of_item(def_id).unwrap_or_else(|| {
516 let e = tcx.dcx().span_delayed_bug(
517 tcx.def_span(def_id),
518 "encountered regular consts in the old solver's const normalization",
519 );
520 ty::EarlyBinder::bind(tcx, ty::Const::new_error(tcx, e))
521 })
522}
523
524{}
#[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("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(526u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("alias_term")
}> =
::tracing::__macro_support::FieldName::new("alias_term");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("depth")
}> =
::tracing::__macro_support::FieldName::new("depth");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&alias_term)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&depth as
&dyn ::tracing::field::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;
}
{
if true {
if !!selcx.infcx.next_trait_solver() {
::core::panicking::panic("assertion failed: !selcx.infcx.next_trait_solver()")
};
};
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 def_id = alias_term.expect_inherent_def_id();
let clauses = tcx.clauses_of(def_id).instantiate(tcx, args);
for (clause, span) in clauses {
let clause =
normalize_with_depth_to(selcx, param_env, cause.clone(),
depth + 1, clause, obligations);
let nested_cause =
ObligationCause::new(cause.span, cause.body_def_id,
ObligationCauseCode::WhereClause(def_id, span));
obligations.push(Obligation::with_depth(tcx, nested_cause,
depth + 1, param_env, clause));
}
let term =
if alias_term.kind.is_type() {
tcx.type_of(def_id).instantiate(tcx, args).map(Into::into)
} else {
const_of_item_or_delayed_bug(tcx,
def_id).instantiate(tcx, args).map(Into::into)
};
let term = selcx.infcx.resolve_vars_if_possible(term);
let term =
normalize_with_depth_to(selcx, param_env, cause.clone(),
depth + 1, term, obligations);
push_const_arg_has_type_obligation(tcx, obligations, &cause,
depth + 1, param_env, term, def_id, args);
term
}
}
}#[instrument(level = "debug", skip(selcx, param_env, cause, obligations))]
527pub fn normalize_inherent_projection<'a, 'b, 'tcx>(
528 selcx: &'a mut SelectionContext<'b, 'tcx>,
529 param_env: ty::ParamEnv<'tcx>,
530 alias_term: ty::AliasTerm<'tcx>,
531 cause: ObligationCause<'tcx>,
532 depth: usize,
533 obligations: &mut PredicateObligations<'tcx>,
534) -> ty::Term<'tcx> {
535 debug_assert!(!selcx.infcx.next_trait_solver());
536 let tcx = selcx.tcx();
537
538 if !tcx.recursion_limit().value_within_limit(depth) {
539 tcx.dcx().emit_fatal(InherentProjectionNormalizationOverflow {
541 span: cause.span,
542 ty: alias_term.to_string(),
543 });
544 }
545
546 let args = compute_inherent_assoc_term_args(
547 selcx,
548 param_env,
549 alias_term,
550 cause.clone(),
551 depth,
552 obligations,
553 );
554
555 let def_id = alias_term.expect_inherent_def_id();
557 let clauses = tcx.clauses_of(def_id).instantiate(tcx, args);
558 for (clause, span) in clauses {
559 let clause = normalize_with_depth_to(
560 selcx,
561 param_env,
562 cause.clone(),
563 depth + 1,
564 clause,
565 obligations,
566 );
567
568 let nested_cause = ObligationCause::new(
569 cause.span,
570 cause.body_def_id,
571 ObligationCauseCode::WhereClause(def_id, span),
576 );
577
578 obligations.push(Obligation::with_depth(tcx, nested_cause, depth + 1, param_env, clause));
579 }
580
581 let term = if alias_term.kind.is_type() {
582 tcx.type_of(def_id).instantiate(tcx, args).map(Into::into)
583 } else {
584 const_of_item_or_delayed_bug(tcx, def_id).instantiate(tcx, args).map(Into::into)
585 };
586
587 let term = selcx.infcx.resolve_vars_if_possible(term);
588 let term =
589 normalize_with_depth_to(selcx, param_env, cause.clone(), depth + 1, term, obligations);
590
591 push_const_arg_has_type_obligation(
592 tcx,
593 obligations,
594 &cause,
595 depth + 1,
596 param_env,
597 term,
598 def_id,
599 args,
600 );
601
602 term
603}
604
605pub fn compute_inherent_assoc_term_args<'a, 'b, 'tcx>(
607 selcx: &'a mut SelectionContext<'b, 'tcx>,
608 param_env: ty::ParamEnv<'tcx>,
609 alias_term: ty::AliasTerm<'tcx>,
610 cause: ObligationCause<'tcx>,
611 depth: usize,
612 obligations: &mut PredicateObligations<'tcx>,
613) -> ty::GenericArgsRef<'tcx> {
614 let tcx = selcx.tcx();
615
616 let alias_def_id = match alias_term.kind {
617 ty::AliasTermKind::InherentTy { def_id } => def_id,
618 ty::AliasTermKind::InherentConstSelf { def_id } => def_id,
619 ty::AliasTermKind::InherentConstImpl { .. } => return alias_term.args,
620 kind => {
::core::panicking::panic_fmt(format_args!("expected inherent alias, found {0:?}",
kind));
}panic!("expected inherent alias, found {kind:?}"),
621 };
622
623 let impl_def_id = tcx.parent(alias_def_id);
624 let impl_args = selcx.infcx.fresh_args_for_item(cause.span, impl_def_id);
625
626 let impl_ty = tcx.type_of(impl_def_id).instantiate(tcx, impl_args);
627 let impl_ty = if !selcx.infcx.next_trait_solver() {
628 normalize_with_depth_to(selcx, param_env, cause.clone(), depth + 1, impl_ty, obligations)
629 } else {
630 impl_ty.skip_norm_wip()
631 };
632
633 let self_ty = ty::Unnormalized::new_wip(alias_term.self_ty());
636 let self_ty = if !selcx.infcx.next_trait_solver() {
637 normalize_with_depth_to(selcx, param_env, cause.clone(), depth + 1, self_ty, obligations)
638 } else {
639 self_ty.skip_normalization()
640 };
641
642 match selcx.infcx.at(&cause, param_env).eq(DefineOpaqueTypes::Yes, impl_ty, self_ty) {
643 Ok(mut ok) => obligations.append(&mut ok.obligations),
644 Err(_) => {
645 tcx.dcx().span_bug(
646 cause.span,
647 ::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"),
648 );
649 }
650 }
651
652 alias_term.rebase_inherent_args_onto_impl(impl_args, tcx)
653}
654
655enum Projected<'tcx> {
656 Progress(Progress<'tcx>),
657 NoProgress(ty::Term<'tcx>),
658}
659
660struct Progress<'tcx> {
661 term: ty::Unnormalized<'tcx, ty::Term<'tcx>>,
662 obligations: PredicateObligations<'tcx>,
663}
664
665impl<'tcx> Progress<'tcx> {
666 fn error_for_term(
667 tcx: TyCtxt<'tcx>,
668 alias_term: ty::AliasTerm<'tcx>,
669 guar: ErrorGuaranteed,
670 ) -> Self {
671 let err_term = if alias_term.kind.is_type() {
672 Ty::new_error(tcx, guar).into()
673 } else {
674 ty::Const::new_error(tcx, guar).into()
675 };
676 Progress {
677 term: ty::Unnormalized::dummy(err_term),
678 obligations: PredicateObligations::new(),
679 }
680 }
681
682 fn with_addl_obligations(mut self, mut obligations: PredicateObligations<'tcx>) -> Self {
683 self.obligations.append(&mut obligations);
684 self
685 }
686}
687
688{}
#[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("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(693u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligation")
}> =
::tracing::__macro_support::FieldName::new("obligation");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::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 self_ty =
selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
if let ty::Dynamic(data, ..) = self_ty.kind() {
if let Some(def_id) = data.principal_def_id() {
let tcx = selcx.tcx();
if !tcx.is_dyn_compatible(def_id) {
let span = obligation.cause.span;
let guar =
if span.is_dummy() ||
#[allow(non_exhaustive_omitted_patterns)] match obligation.cause.code()
{
ObligationCauseCode::CheckAssociatedTypeBounds { .. } =>
true,
_ => false,
} {
tcx.dcx().span_delayed_bug(span,
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("projection from non-dyn-compatible trait `{0}`",
tcx.def_path_str(def_id)))
}))
} else {
let violations = tcx.dyn_compatibility_violations(def_id);
report_dyn_incompatibility(tcx, span, None, def_id,
&violations).emit()
};
return Ok(Projected::Progress(Progress::error_for_term(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, ty::IsRigid::No);
Ok(Projected::NoProgress(term))
}
ProjectionCandidateSet::Error(e) =>
Err(ProjectionError::TraitSelectionError(e)),
ProjectionCandidateSet::Ambiguous =>
Err(ProjectionError::TooManyCandidates),
}
}
}
}#[instrument(level = "info", skip(selcx))]
694fn project<'cx, 'tcx>(
695 selcx: &mut SelectionContext<'cx, 'tcx>,
696 obligation: &ProjectionTermObligation<'tcx>,
697) -> Result<Projected<'tcx>, ProjectionError<'tcx>> {
698 if !selcx.tcx().recursion_limit().value_within_limit(obligation.recursion_depth) {
699 return Err(ProjectionError::TraitSelectionError(SelectionError::Overflow(
702 OverflowError::Canonical,
703 )));
704 }
705
706 if let Err(guar) = obligation.predicate.non_region_error_reported() {
709 return Ok(Projected::Progress(Progress::error_for_term(
710 selcx.tcx(),
711 obligation.predicate,
712 guar,
713 )));
714 }
715
716 let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
719 if let ty::Dynamic(data, ..) = self_ty.kind() {
720 if let Some(def_id) = data.principal_def_id() {
721 let tcx = selcx.tcx();
722 if !tcx.is_dyn_compatible(def_id) {
728 let span = obligation.cause.span;
729 let guar = if span.is_dummy()
730 || matches!(
731 obligation.cause.code(),
732 ObligationCauseCode::CheckAssociatedTypeBounds { .. }
733 ) {
734 tcx.dcx().span_delayed_bug(
735 span,
736 format!(
737 "projection from non-dyn-compatible trait `{}`",
738 tcx.def_path_str(def_id)
739 ),
740 )
741 } else {
742 let violations = tcx.dyn_compatibility_violations(def_id);
743 report_dyn_incompatibility(tcx, span, None, def_id, &violations).emit()
744 };
745 return Ok(Projected::Progress(Progress::error_for_term(
746 tcx,
747 obligation.predicate,
748 guar,
749 )));
750 }
751 }
752 }
753
754 let mut candidates = ProjectionCandidateSet::None;
755
756 assemble_candidates_from_param_env(selcx, obligation, &mut candidates);
760
761 assemble_candidates_from_trait_def(selcx, obligation, &mut candidates);
762
763 assemble_candidates_from_object_ty(selcx, obligation, &mut candidates);
764
765 if let ProjectionCandidateSet::Single(ProjectionCandidate::Object(_)) = candidates {
766 } else {
771 assemble_candidates_from_impls(selcx, obligation, &mut candidates);
772 };
773
774 match candidates {
775 ProjectionCandidateSet::Single(candidate) => {
776 confirm_candidate(selcx, obligation, candidate)
777 }
778 ProjectionCandidateSet::None => {
779 let tcx = selcx.tcx();
780 let term = obligation.predicate.to_term(tcx, ty::IsRigid::No);
781 Ok(Projected::NoProgress(term))
782 }
783 ProjectionCandidateSet::Error(e) => Err(ProjectionError::TraitSelectionError(e)),
785 ProjectionCandidateSet::Ambiguous => Err(ProjectionError::TooManyCandidates),
788 }
789}
790
791fn assemble_candidates_from_param_env<'cx, 'tcx>(
795 selcx: &mut SelectionContext<'cx, 'tcx>,
796 obligation: &ProjectionTermObligation<'tcx>,
797 candidate_set: &mut ProjectionCandidateSet<'tcx>,
798) {
799 assemble_candidates_from_clauses(
800 selcx,
801 obligation,
802 candidate_set,
803 ProjectionCandidate::ParamEnv,
804 obligation.param_env.caller_bounds(),
805 false,
806 );
807}
808
809fn assemble_candidates_from_trait_def<'cx, 'tcx>(
820 selcx: &mut SelectionContext<'cx, 'tcx>,
821 obligation: &ProjectionTermObligation<'tcx>,
822 candidate_set: &mut ProjectionCandidateSet<'tcx>,
823) {
824 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:824",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(824u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("assemble_candidates_from_trait_def(..)")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("assemble_candidates_from_trait_def(..)");
825 let mut ambiguous = false;
826 let _ = selcx.for_each_item_bound(
827 obligation.predicate.self_ty(),
828 |selcx, clause, _, _| {
829 let Some(clause) = clause.as_projection_clause() else {
830 return ControlFlow::Continue(());
831 };
832 if clause.item_def_id() != obligation.predicate.expect_projection_def_id() {
833 return ControlFlow::Continue(());
834 }
835
836 let is_match =
837 selcx.infcx.probe(|_| selcx.match_projection_projections(obligation, clause, true));
838
839 match is_match {
840 ProjectionMatchesProjection::Yes => {
841 candidate_set.push_candidate(ProjectionCandidate::TraitDef(clause));
842
843 if !obligation.predicate.has_non_region_infer() {
844 return ControlFlow::Break(());
848 }
849 }
850 ProjectionMatchesProjection::Ambiguous => {
851 candidate_set.mark_ambiguous();
852 }
853 ProjectionMatchesProjection::No => {}
854 }
855
856 ControlFlow::Continue(())
857 },
858 || ambiguous = true,
861 );
862
863 if ambiguous {
864 candidate_set.mark_ambiguous();
865 }
866}
867
868fn assemble_candidates_from_object_ty<'cx, 'tcx>(
878 selcx: &mut SelectionContext<'cx, 'tcx>,
879 obligation: &ProjectionTermObligation<'tcx>,
880 candidate_set: &mut ProjectionCandidateSet<'tcx>,
881) {
882 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:882",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(882u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("assemble_candidates_from_object_ty(..)")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("assemble_candidates_from_object_ty(..)");
883
884 let tcx = selcx.tcx();
885
886 let self_ty = obligation.predicate.self_ty();
887 let object_ty = selcx.infcx.shallow_resolve(self_ty);
888 let data = match object_ty.kind() {
889 ty::Dynamic(data, ..) => data,
890 ty::Infer(ty::TyVar(_)) => {
891 candidate_set.mark_ambiguous();
894 return;
895 }
896 _ => return,
897 };
898
899 if data.principal_def_id().is_some_and(|def_id| !tcx.is_dyn_compatible(def_id)) {
901 return;
902 }
903
904 let env_predicates = data
905 .projection_bounds()
906 .filter(|bound| bound.item_def_id() == obligation.predicate.expect_projection_def_id())
907 .map(|p| p.with_self_ty(tcx, object_ty).upcast(tcx));
908
909 assemble_candidates_from_clauses(
910 selcx,
911 obligation,
912 candidate_set,
913 ProjectionCandidate::Object,
914 env_predicates,
915 false,
916 );
917}
918
919{}
#[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_clauses",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(919u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligation")
}> =
::tracing::__macro_support::FieldName::new("obligation");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::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 clause in env_clauses {
let bound_clause = clause.kind();
if let ty::ClauseKind::Projection(data) =
clause.kind().skip_binder() {
let data = bound_clause.rebind(data);
if data.item_def_id() !=
obligation.predicate.expect_projection_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(
920 level = "debug",
921 skip(selcx, candidate_set, ctor, env_clauses, potentially_unnormalized_candidates)
922)]
923fn assemble_candidates_from_clauses<'cx, 'tcx>(
924 selcx: &mut SelectionContext<'cx, 'tcx>,
925 obligation: &ProjectionTermObligation<'tcx>,
926 candidate_set: &mut ProjectionCandidateSet<'tcx>,
927 ctor: fn(ty::PolyProjectionClause<'tcx>) -> ProjectionCandidate<'tcx>,
928 env_clauses: impl Iterator<Item = ty::Clause<'tcx>>,
929 potentially_unnormalized_candidates: bool,
930) {
931 let infcx = selcx.infcx;
932 let drcx = DeepRejectCtxt::relate_rigid_rigid(selcx.tcx());
933 for clause in env_clauses {
934 let bound_clause = clause.kind();
935 if let ty::ClauseKind::Projection(data) = clause.kind().skip_binder() {
936 let data = bound_clause.rebind(data);
937 if data.item_def_id() != obligation.predicate.expect_projection_def_id() {
938 continue;
939 }
940
941 if !drcx
942 .args_may_unify(obligation.predicate.args, data.skip_binder().projection_term.args)
943 {
944 continue;
945 }
946
947 let is_match = infcx.probe(|_| {
948 selcx.match_projection_projections(
949 obligation,
950 data,
951 potentially_unnormalized_candidates,
952 )
953 });
954
955 match is_match {
956 ProjectionMatchesProjection::Yes => {
957 candidate_set.push_candidate(ctor(data));
958
959 if potentially_unnormalized_candidates
960 && !obligation.predicate.has_non_region_infer()
961 {
962 return;
966 }
967 }
968 ProjectionMatchesProjection::Ambiguous => {
969 candidate_set.mark_ambiguous();
970 }
971 ProjectionMatchesProjection::No => {}
972 }
973 }
974 }
975}
976
977{}
#[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("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(977u32),
::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_all(&[]) })
} 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 /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:995",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(995u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("error")
}> =
::tracing::__macro_support::FieldName::new("error");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("selection error")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&e)
as &dyn ::tracing::field::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.expect_projection_def_id()) {
Ok(node_item) => {
if node_item.is_final() {
true
} else {
match selcx.typing_mode() {
TypingMode::Coherence | TypingMode::Typeck { .. } |
TypingMode::PostTypeckUntilBorrowck { .. } |
TypingMode::Reflection | TypingMode::PostBorrowck { .. } =>
{
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:1045",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(1045u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("assoc_ty")
}> =
::tracing::__macro_support::FieldName::new("assoc_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligation.predicate")
}> =
::tracing::__macro_support::FieldName::new("obligation.predicate");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("not eligible due to default")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&selcx.tcx().def_path_str(node_item.item.def_id))
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation.predicate)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
false
}
TypingMode::PostAnalysis | TypingMode::Codegen => {
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 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 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.expect_projection_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))]
978fn assemble_candidates_from_impls<'cx, 'tcx>(
979 selcx: &mut SelectionContext<'cx, 'tcx>,
980 obligation: &ProjectionTermObligation<'tcx>,
981 candidate_set: &mut ProjectionCandidateSet<'tcx>,
982) {
983 let trait_ref = obligation.predicate.trait_ref(selcx.tcx());
986 let trait_obligation = obligation.with(selcx.tcx(), trait_ref);
987 let _ = selcx.infcx.commit_if_ok(|_| {
988 let impl_source = match selcx.select(&trait_obligation) {
989 Ok(Some(impl_source)) => impl_source,
990 Ok(None) => {
991 candidate_set.mark_ambiguous();
992 return Err(());
993 }
994 Err(e) => {
995 debug!(error = ?e, "selection error");
996 candidate_set.mark_error(e);
997 return Err(());
998 }
999 };
1000
1001 let eligible = match &impl_source {
1002 ImplSource::UserDefined(impl_data) => {
1003 match specialization_graph::assoc_def(
1026 selcx.tcx(),
1027 impl_data.impl_def_id,
1028 obligation.predicate.expect_projection_def_id(),
1029 ) {
1030 Ok(node_item) => {
1031 if node_item.is_final() {
1032 true
1034 } else {
1035 match selcx.typing_mode() {
1040 TypingMode::Coherence
1041 | TypingMode::Typeck { .. }
1042 | TypingMode::PostTypeckUntilBorrowck { .. }
1043 | TypingMode::Reflection
1044 | TypingMode::PostBorrowck { .. } => {
1045 debug!(
1046 assoc_ty = ?selcx.tcx().def_path_str(node_item.item.def_id),
1047 ?obligation.predicate,
1048 "not eligible due to default",
1049 );
1050 false
1051 }
1052 TypingMode::PostAnalysis | TypingMode::Codegen => {
1053 let poly_trait_ref =
1056 selcx.infcx.resolve_vars_if_possible(trait_ref);
1057 !poly_trait_ref.still_further_specializable()
1058 }
1059 }
1060 }
1061 }
1062 Err(ErrorGuaranteed { .. }) => true,
1066 }
1067 }
1068 ImplSource::Builtin(BuiltinImplSource::Misc | BuiltinImplSource::Trivial, _) => {
1069 let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
1073
1074 let tcx = selcx.tcx();
1075 match selcx.tcx().as_lang_item(trait_ref.def_id) {
1076 Some(
1077 LangItem::Coroutine
1078 | LangItem::Future
1079 | LangItem::Iterator
1080 | LangItem::AsyncIterator
1081 | LangItem::Field
1082 | LangItem::Fn
1083 | LangItem::FnMut
1084 | LangItem::FnOnce
1085 | LangItem::AsyncFn
1086 | LangItem::AsyncFnMut
1087 | LangItem::AsyncFnOnce,
1088 ) => true,
1089 Some(LangItem::AsyncFnKindHelper) => {
1090 if obligation.predicate.args.type_at(0).is_ty_var()
1092 || obligation.predicate.args.type_at(4).is_ty_var()
1093 || obligation.predicate.args.type_at(5).is_ty_var()
1094 {
1095 candidate_set.mark_ambiguous();
1096 true
1097 } else {
1098 obligation.predicate.args.type_at(0).to_opt_closure_kind().is_some()
1099 && obligation
1100 .predicate
1101 .args
1102 .type_at(1)
1103 .to_opt_closure_kind()
1104 .is_some()
1105 }
1106 }
1107 Some(LangItem::DiscriminantKind) => match self_ty.kind() {
1108 ty::Bool
1109 | ty::Char
1110 | ty::Int(_)
1111 | ty::Uint(_)
1112 | ty::Float(_)
1113 | ty::Adt(..)
1114 | ty::Foreign(_)
1115 | ty::Str
1116 | ty::Array(..)
1117 | ty::Pat(..)
1118 | ty::Slice(_)
1119 | ty::RawPtr(..)
1120 | ty::Ref(..)
1121 | ty::FnDef(..)
1122 | ty::FnPtr(..)
1123 | ty::Dynamic(..)
1124 | ty::Closure(..)
1125 | ty::CoroutineClosure(..)
1126 | ty::Coroutine(..)
1127 | ty::CoroutineWitness(..)
1128 | ty::Never
1129 | ty::Tuple(..)
1130 | ty::Infer(ty::InferTy::IntVar(_) | ty::InferTy::FloatVar(..)) => true,
1132
1133 ty::UnsafeBinder(_) => unimplemented!("FIXME(unsafe_binder)"),
1134
1135 ty::Param(_)
1139 | ty::Alias(..)
1140 | ty::Bound(..)
1141 | ty::Placeholder(..)
1142 | ty::Infer(..)
1143 | ty::Error(_) => false,
1144 },
1145 Some(LangItem::PointeeTrait) => {
1146 let tail = selcx.tcx().struct_tail_raw(
1147 self_ty,
1148 &obligation.cause,
1149 |ty| {
1150 normalize_with_depth(
1153 selcx,
1154 obligation.param_env,
1155 obligation.cause.clone(),
1156 obligation.recursion_depth + 1,
1157 ty,
1158 )
1159 .value
1160 },
1161 || {},
1162 );
1163
1164 match tail.kind() {
1165 ty::Bool
1166 | ty::Char
1167 | ty::Int(_)
1168 | ty::Uint(_)
1169 | ty::Float(_)
1170 | ty::Str
1171 | ty::Array(..)
1172 | ty::Pat(..)
1173 | ty::Slice(_)
1174 | ty::RawPtr(..)
1175 | ty::Ref(..)
1176 | ty::FnDef(..)
1177 | ty::FnPtr(..)
1178 | ty::Dynamic(..)
1179 | ty::Closure(..)
1180 | ty::CoroutineClosure(..)
1181 | ty::Coroutine(..)
1182 | ty::CoroutineWitness(..)
1183 | ty::Never
1184 | ty::Foreign(_)
1186 | ty::Adt(..)
1189 | ty::Tuple(..)
1191 | ty::Infer(ty::InferTy::IntVar(_) | ty::InferTy::FloatVar(..))
1193 | ty::Error(..) => true,
1195
1196 ty::Param(_) | ty::Alias(..)
1200 if self_ty != tail
1201 || selcx.infcx.predicate_must_hold_modulo_regions(
1202 &obligation.with(
1203 selcx.tcx(),
1204 ty::TraitRef::new(
1205 selcx.tcx(),
1206 selcx.tcx().require_lang_item(
1207 LangItem::Sized,
1208 obligation.cause.span,
1209 ),
1210 [self_ty],
1211 ),
1212 ),
1213 ) =>
1214 {
1215 true
1216 }
1217
1218 ty::UnsafeBinder(_) => unimplemented!("FIXME(unsafe_binder)"),
1219
1220 ty::Param(_)
1222 | ty::Alias(..)
1223 | ty::Bound(..)
1224 | ty::Placeholder(..)
1225 | ty::Infer(..) => {
1226 if tail.has_infer_types() {
1227 candidate_set.mark_ambiguous();
1228 }
1229 false
1230 }
1231 }
1232 }
1233 _ if tcx.trait_is_auto(trait_ref.def_id) => {
1234 tcx.dcx().span_delayed_bug(
1235 tcx.def_span(obligation.predicate.expect_projection_def_id()),
1236 "associated types not allowed on auto traits",
1237 );
1238 false
1239 }
1240 _ => {
1241 bug!("unexpected builtin trait with associated type: {trait_ref:?}")
1242 }
1243 }
1244 }
1245 ImplSource::Param(..) => {
1246 false
1272 }
1273 ImplSource::Builtin(BuiltinImplSource::Object { .. }, _) => {
1274 false
1278 }
1279 ImplSource::Builtin(BuiltinImplSource::TraitUpcasting { .. }, _) => {
1280 selcx.tcx().dcx().span_delayed_bug(
1282 obligation.cause.span,
1283 format!("Cannot project an associated type from `{impl_source:?}`"),
1284 );
1285 return Err(());
1286 }
1287 };
1288
1289 if eligible {
1290 if candidate_set.push_candidate(ProjectionCandidate::Select(impl_source)) {
1291 Ok(())
1292 } else {
1293 Err(())
1294 }
1295 } else {
1296 Err(())
1297 }
1298 });
1299}
1300
1301fn confirm_candidate<'cx, 'tcx>(
1303 selcx: &mut SelectionContext<'cx, 'tcx>,
1304 obligation: &ProjectionTermObligation<'tcx>,
1305 candidate: ProjectionCandidate<'tcx>,
1306) -> Result<Projected<'tcx>, ProjectionError<'tcx>> {
1307 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:1307",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(1307u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligation")
}> =
::tracing::__macro_support::FieldName::new("obligation");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("candidate")
}> =
::tracing::__macro_support::FieldName::new("candidate");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("confirm_candidate")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidate)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?obligation, ?candidate, "confirm_candidate");
1308 let mut result = match candidate {
1309 ProjectionCandidate::ParamEnv(poly_projection)
1310 | ProjectionCandidate::Object(poly_projection) => Ok(Projected::Progress(
1311 confirm_param_env_candidate(selcx, obligation, poly_projection, false),
1312 )),
1313 ProjectionCandidate::TraitDef(poly_projection) => Ok(Projected::Progress(
1314 confirm_param_env_candidate(selcx, obligation, poly_projection, true),
1315 )),
1316 ProjectionCandidate::Select(impl_source) => {
1317 confirm_select_candidate(selcx, obligation, impl_source)
1318 }
1319 };
1320
1321 if let Ok(Projected::Progress(progress)) = &mut result
1327 && progress.term.has_infer_regions()
1328 {
1329 progress.term = progress.term.fold_with(&mut OpportunisticRegionResolver::new(selcx.infcx));
1330 }
1331
1332 result
1333}
1334
1335fn confirm_select_candidate<'cx, 'tcx>(
1337 selcx: &mut SelectionContext<'cx, 'tcx>,
1338 obligation: &ProjectionTermObligation<'tcx>,
1339 impl_source: Selection<'tcx>,
1340) -> Result<Projected<'tcx>, ProjectionError<'tcx>> {
1341 match impl_source {
1342 ImplSource::UserDefined(data) => confirm_impl_candidate(selcx, obligation, data),
1343 ImplSource::Builtin(BuiltinImplSource::Misc | BuiltinImplSource::Trivial, data) => {
1344 let tcx = selcx.tcx();
1345 let trait_def_id = obligation.predicate.trait_def_id(tcx);
1346 let progress = if tcx.is_lang_item(trait_def_id, LangItem::Coroutine) {
1347 confirm_coroutine_candidate(selcx, obligation, data)
1348 } else if tcx.is_lang_item(trait_def_id, LangItem::Future) {
1349 confirm_future_candidate(selcx, obligation, data)
1350 } else if tcx.is_lang_item(trait_def_id, LangItem::Iterator) {
1351 confirm_iterator_candidate(selcx, obligation, data)
1352 } else if tcx.is_lang_item(trait_def_id, LangItem::AsyncIterator) {
1353 confirm_async_iterator_candidate(selcx, obligation, data)
1354 } else if selcx.tcx().fn_trait_kind_from_def_id(trait_def_id).is_some() {
1355 if obligation.predicate.self_ty().is_closure()
1356 || obligation.predicate.self_ty().is_coroutine_closure()
1357 {
1358 confirm_closure_candidate(selcx, obligation, data)
1359 } else {
1360 confirm_fn_pointer_candidate(selcx, obligation, data)
1361 }
1362 } else if selcx.tcx().async_fn_trait_kind_from_def_id(trait_def_id).is_some() {
1363 confirm_async_closure_candidate(selcx, obligation, data)
1364 } else if tcx.is_lang_item(trait_def_id, LangItem::AsyncFnKindHelper) {
1365 confirm_async_fn_kind_helper_candidate(selcx, obligation, data)
1366 } else {
1367 confirm_builtin_candidate(selcx, obligation, data)
1368 };
1369 Ok(Projected::Progress(progress))
1370 }
1371 ImplSource::Builtin(BuiltinImplSource::Object { .. }, _)
1372 | ImplSource::Param(..)
1373 | ImplSource::Builtin(BuiltinImplSource::TraitUpcasting { .. }, _) => {
1374 ::rustc_middle::util::bug::span_bug_fmt(obligation.cause.span,
format_args!("Cannot project an associated type from `{0:?}`",
impl_source))span_bug!(
1376 obligation.cause.span,
1377 "Cannot project an associated type from `{:?}`",
1378 impl_source
1379 )
1380 }
1381 }
1382}
1383
1384fn confirm_coroutine_candidate<'cx, 'tcx>(
1385 selcx: &mut SelectionContext<'cx, 'tcx>,
1386 obligation: &ProjectionTermObligation<'tcx>,
1387 nested: PredicateObligations<'tcx>,
1388) -> Progress<'tcx> {
1389 let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
1390 let ty::Coroutine(_, args) = self_ty.kind() else {
1391 {
::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!(
1392 "expected coroutine self type for built-in coroutine candidate, found {self_ty}"
1393 )
1394 };
1395 let coroutine_sig = Unnormalized::new_wip(args.as_coroutine().sig());
1396 let Normalized { value: coroutine_sig, obligations } = normalize_with_depth(
1397 selcx,
1398 obligation.param_env,
1399 obligation.cause.clone(),
1400 obligation.recursion_depth + 1,
1401 coroutine_sig,
1402 );
1403
1404 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:1404",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(1404u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligation")
}> =
::tracing::__macro_support::FieldName::new("obligation");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("coroutine_sig")
}> =
::tracing::__macro_support::FieldName::new("coroutine_sig");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligations")
}> =
::tracing::__macro_support::FieldName::new("obligations");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("confirm_coroutine_candidate")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&coroutine_sig)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligations)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?obligation, ?coroutine_sig, ?obligations, "confirm_coroutine_candidate");
1405
1406 let tcx = selcx.tcx();
1407
1408 let coroutine_def_id = tcx.require_lang_item(LangItem::Coroutine, obligation.cause.span);
1409
1410 let (trait_ref, yield_ty, return_ty) = super::util::coroutine_trait_ref_and_outputs(
1411 tcx,
1412 coroutine_def_id,
1413 obligation.predicate.self_ty(),
1414 coroutine_sig,
1415 );
1416
1417 let def_id = obligation.predicate.expect_projection_def_id();
1418 let ty = if tcx.is_lang_item(def_id, LangItem::CoroutineReturn) {
1419 return_ty
1420 } else if tcx.is_lang_item(def_id, LangItem::CoroutineYield) {
1421 yield_ty
1422 } else {
1423 ::rustc_middle::util::bug::span_bug_fmt(tcx.def_span(def_id),
format_args!("unexpected associated type: `Coroutine::{0}`",
tcx.item_name(def_id)));span_bug!(
1424 tcx.def_span(def_id),
1425 "unexpected associated type: `Coroutine::{}`",
1426 tcx.item_name(def_id),
1427 );
1428 };
1429
1430 let predicate = ty::ProjectionClause {
1431 projection_term: obligation.predicate.with_args(tcx, trait_ref.args),
1432 term: ty.into(),
1433 };
1434
1435 confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
1436 .with_addl_obligations(nested)
1437 .with_addl_obligations(obligations)
1438}
1439
1440fn confirm_future_candidate<'cx, 'tcx>(
1441 selcx: &mut SelectionContext<'cx, 'tcx>,
1442 obligation: &ProjectionTermObligation<'tcx>,
1443 nested: PredicateObligations<'tcx>,
1444) -> Progress<'tcx> {
1445 let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
1446 let ty::Coroutine(_, args) = self_ty.kind() else {
1447 {
::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!(
1448 "expected coroutine self type for built-in async future candidate, found {self_ty}"
1449 )
1450 };
1451 let coroutine_sig = Unnormalized::new_wip(args.as_coroutine().sig());
1452 let Normalized { value: coroutine_sig, obligations } = normalize_with_depth(
1453 selcx,
1454 obligation.param_env,
1455 obligation.cause.clone(),
1456 obligation.recursion_depth + 1,
1457 coroutine_sig,
1458 );
1459
1460 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:1460",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(1460u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligation")
}> =
::tracing::__macro_support::FieldName::new("obligation");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("coroutine_sig")
}> =
::tracing::__macro_support::FieldName::new("coroutine_sig");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligations")
}> =
::tracing::__macro_support::FieldName::new("obligations");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("confirm_future_candidate")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&coroutine_sig)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligations)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?obligation, ?coroutine_sig, ?obligations, "confirm_future_candidate");
1461
1462 let tcx = selcx.tcx();
1463 let fut_def_id = tcx.require_lang_item(LangItem::Future, obligation.cause.span);
1464
1465 let (trait_ref, return_ty) = super::util::future_trait_ref_and_outputs(
1466 tcx,
1467 fut_def_id,
1468 obligation.predicate.self_ty(),
1469 coroutine_sig,
1470 );
1471
1472 if true {
{
match (&tcx.associated_item(obligation.predicate.expect_projection_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!(
1473 tcx.associated_item(obligation.predicate.expect_projection_def_id()).name(),
1474 sym::Output
1475 );
1476
1477 let predicate = ty::ProjectionClause {
1478 projection_term: obligation.predicate.with_args(tcx, trait_ref.args),
1479 term: return_ty.into(),
1480 };
1481
1482 confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
1483 .with_addl_obligations(nested)
1484 .with_addl_obligations(obligations)
1485}
1486
1487fn confirm_iterator_candidate<'cx, 'tcx>(
1488 selcx: &mut SelectionContext<'cx, 'tcx>,
1489 obligation: &ProjectionTermObligation<'tcx>,
1490 nested: PredicateObligations<'tcx>,
1491) -> Progress<'tcx> {
1492 let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
1493 let ty::Coroutine(_, args) = self_ty.kind() else {
1494 {
::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}")
1495 };
1496 let gen_sig = Unnormalized::new_wip(args.as_coroutine().sig());
1497 let Normalized { value: gen_sig, obligations } = normalize_with_depth(
1498 selcx,
1499 obligation.param_env,
1500 obligation.cause.clone(),
1501 obligation.recursion_depth + 1,
1502 gen_sig,
1503 );
1504
1505 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:1505",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(1505u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligation")
}> =
::tracing::__macro_support::FieldName::new("obligation");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("gen_sig")
}> =
::tracing::__macro_support::FieldName::new("gen_sig");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligations")
}> =
::tracing::__macro_support::FieldName::new("obligations");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("confirm_iterator_candidate")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&gen_sig)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligations)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?obligation, ?gen_sig, ?obligations, "confirm_iterator_candidate");
1506
1507 let tcx = selcx.tcx();
1508 let iter_def_id = tcx.require_lang_item(LangItem::Iterator, obligation.cause.span);
1509
1510 let (trait_ref, yield_ty) = super::util::iterator_trait_ref_and_outputs(
1511 tcx,
1512 iter_def_id,
1513 obligation.predicate.self_ty(),
1514 gen_sig,
1515 );
1516
1517 if true {
{
match (&tcx.associated_item(obligation.predicate.expect_projection_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!(
1518 tcx.associated_item(obligation.predicate.expect_projection_def_id()).name(),
1519 sym::Item
1520 );
1521
1522 let predicate = ty::ProjectionClause {
1523 projection_term: obligation.predicate.with_args(tcx, trait_ref.args),
1524 term: yield_ty.into(),
1525 };
1526
1527 confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
1528 .with_addl_obligations(nested)
1529 .with_addl_obligations(obligations)
1530}
1531
1532fn confirm_async_iterator_candidate<'cx, 'tcx>(
1533 selcx: &mut SelectionContext<'cx, 'tcx>,
1534 obligation: &ProjectionTermObligation<'tcx>,
1535 nested: PredicateObligations<'tcx>,
1536) -> Progress<'tcx> {
1537 let ty::Coroutine(_, args) = selcx.infcx.shallow_resolve(obligation.predicate.self_ty()).kind()
1538 else {
1539 ::core::panicking::panic("internal error: entered unreachable code")unreachable!()
1540 };
1541 let gen_sig = Unnormalized::new_wip(args.as_coroutine().sig());
1542 let Normalized { value: gen_sig, obligations } = normalize_with_depth(
1543 selcx,
1544 obligation.param_env,
1545 obligation.cause.clone(),
1546 obligation.recursion_depth + 1,
1547 gen_sig,
1548 );
1549
1550 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:1550",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(1550u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligation")
}> =
::tracing::__macro_support::FieldName::new("obligation");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("gen_sig")
}> =
::tracing::__macro_support::FieldName::new("gen_sig");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligations")
}> =
::tracing::__macro_support::FieldName::new("obligations");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("confirm_async_iterator_candidate")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&gen_sig)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligations)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?obligation, ?gen_sig, ?obligations, "confirm_async_iterator_candidate");
1551
1552 let tcx = selcx.tcx();
1553 let iter_def_id = tcx.require_lang_item(LangItem::AsyncIterator, obligation.cause.span);
1554
1555 let (trait_ref, yield_ty) = super::util::async_iterator_trait_ref_and_outputs(
1556 tcx,
1557 iter_def_id,
1558 obligation.predicate.self_ty(),
1559 gen_sig,
1560 );
1561
1562 if true {
{
match (&tcx.associated_item(obligation.predicate.expect_projection_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!(
1563 tcx.associated_item(obligation.predicate.expect_projection_def_id()).name(),
1564 sym::Item
1565 );
1566
1567 let ty::Adt(_poll_adt, args) = *yield_ty.kind() else {
1568 ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"));bug!();
1569 };
1570 let ty::Adt(_option_adt, args) = *args.type_at(0).kind() else {
1571 ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"));bug!();
1572 };
1573 let item_ty = args.type_at(0);
1574
1575 let predicate = ty::ProjectionClause {
1576 projection_term: obligation.predicate.with_args(tcx, trait_ref.args),
1577 term: item_ty.into(),
1578 };
1579
1580 confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
1581 .with_addl_obligations(nested)
1582 .with_addl_obligations(obligations)
1583}
1584
1585fn confirm_builtin_candidate<'cx, 'tcx>(
1586 selcx: &mut SelectionContext<'cx, 'tcx>,
1587 obligation: &ProjectionTermObligation<'tcx>,
1588 data: PredicateObligations<'tcx>,
1589) -> Progress<'tcx> {
1590 let tcx = selcx.tcx();
1591 let self_ty = obligation.predicate.self_ty();
1592 let item_def_id = obligation.predicate.expect_projection_def_id();
1593 let trait_def_id = tcx.parent(item_def_id);
1594 let args = tcx.mk_args(&[self_ty.into()]);
1595 let (term, obligations) = if tcx.is_lang_item(trait_def_id, LangItem::DiscriminantKind) {
1596 let discriminant_def_id =
1597 tcx.require_lang_item(LangItem::Discriminant, obligation.cause.span);
1598 {
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);
1599
1600 (self_ty.discriminant_ty(tcx).into(), PredicateObligations::new())
1601 } else if tcx.is_lang_item(trait_def_id, LangItem::PointeeTrait) {
1602 let metadata_def_id = tcx.require_lang_item(LangItem::Metadata, obligation.cause.span);
1603 {
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);
1604
1605 let mut obligations = PredicateObligations::new();
1606 let normalize = |ty: ty::Unnormalized<'tcx, Ty<'tcx>>| {
1607 normalize_with_depth_to(
1608 selcx,
1609 obligation.param_env,
1610 obligation.cause.clone(),
1611 obligation.recursion_depth + 1,
1612 ty,
1613 &mut obligations,
1614 )
1615 };
1616 let metadata_ty = self_ty.ptr_metadata_ty_or_tail(tcx, normalize).unwrap_or_else(|tail| {
1617 if tail == self_ty {
1618 let sized_predicate = ty::TraitRef::new(
1623 tcx,
1624 tcx.require_lang_item(LangItem::Sized, obligation.cause.span),
1625 [self_ty],
1626 );
1627 obligations.push(obligation.with(tcx, sized_predicate));
1628 tcx.types.unit
1629 } else {
1630 Ty::new_projection(tcx, ty::IsRigid::No, metadata_def_id, [tail])
1633 }
1634 });
1635 (metadata_ty.into(), obligations)
1636 } else if tcx.is_lang_item(trait_def_id, LangItem::Field) {
1637 let ty::Adt(def, args) = self_ty.kind() else {
1638 ::rustc_middle::util::bug::bug_fmt(format_args!("only field representing types can implement `Field`"))bug!("only field representing types can implement `Field`")
1639 };
1640 let Some(FieldInfo { base, ty, .. }) = def.field_representing_type_info(tcx, args) else {
1641 ::rustc_middle::util::bug::bug_fmt(format_args!("only field representing types can implement `Field`"))bug!("only field representing types can implement `Field`")
1642 };
1643 if tcx.is_lang_item(item_def_id, LangItem::FieldBase) {
1644 (base.into(), PredicateObligations::new())
1645 } else if tcx.is_lang_item(item_def_id, LangItem::FieldType) {
1646 (ty.into(), PredicateObligations::new())
1647 } else {
1648 ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected associated type {0:?} in `Field`",
obligation.predicate));bug!("unexpected associated type {:?} in `Field`", obligation.predicate);
1649 }
1650 } else {
1651 ::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);
1652 };
1653
1654 let predicate = ty::ProjectionClause {
1655 projection_term: ty::AliasTerm::new_from_args(
1656 tcx,
1657 ty::AliasTermKind::ProjectionTy { def_id: item_def_id },
1658 args,
1659 ),
1660 term,
1661 };
1662
1663 confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
1664 .with_addl_obligations(obligations)
1665 .with_addl_obligations(data)
1666}
1667
1668fn confirm_fn_pointer_candidate<'cx, 'tcx>(
1669 selcx: &mut SelectionContext<'cx, 'tcx>,
1670 obligation: &ProjectionTermObligation<'tcx>,
1671 nested: PredicateObligations<'tcx>,
1672) -> Progress<'tcx> {
1673 let tcx = selcx.tcx();
1674 let fn_type = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
1675 let sig = fn_type.unnormalized_fn_sig(tcx);
1676 let Normalized { value: sig, obligations } = normalize_with_depth(
1677 selcx,
1678 obligation.param_env,
1679 obligation.cause.clone(),
1680 obligation.recursion_depth + 1,
1681 sig,
1682 );
1683
1684 confirm_callable_candidate(selcx, obligation, sig, util::TupleArgumentsFlag::Yes)
1685 .with_addl_obligations(nested)
1686 .with_addl_obligations(obligations)
1687}
1688
1689fn confirm_closure_candidate<'cx, 'tcx>(
1690 selcx: &mut SelectionContext<'cx, 'tcx>,
1691 obligation: &ProjectionTermObligation<'tcx>,
1692 nested: PredicateObligations<'tcx>,
1693) -> Progress<'tcx> {
1694 let tcx = selcx.tcx();
1695 let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
1696 let closure_sig = match *self_ty.kind() {
1697 ty::Closure(_, args) => Unnormalized::new_wip(args.as_closure().sig()),
1698
1699 ty::CoroutineClosure(def_id, args) => {
1703 let args = args.as_coroutine_closure();
1704 Unnormalized::new_wip(args.coroutine_closure_sig().map_bound(|sig| {
1705 let output_ty = coroutine_closure_output_coroutine(
1706 tcx,
1707 obligation,
1708 ty::ClosureKind::FnOnce,
1709 tcx.lifetimes.re_static,
1710 def_id,
1711 args,
1712 );
1713 tcx.mk_fn_sig([sig.tupled_inputs_ty], output_ty, sig.fn_sig_kind)
1714 }))
1715 }
1716
1717 _ => {
1718 {
::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}");
1719 }
1720 };
1721
1722 let Normalized { value: closure_sig, obligations } = normalize_with_depth(
1723 selcx,
1724 obligation.param_env,
1725 obligation.cause.clone(),
1726 obligation.recursion_depth + 1,
1727 closure_sig,
1728 );
1729
1730 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:1730",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(1730u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligation")
}> =
::tracing::__macro_support::FieldName::new("obligation");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("closure_sig")
}> =
::tracing::__macro_support::FieldName::new("closure_sig");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligations")
}> =
::tracing::__macro_support::FieldName::new("obligations");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("confirm_closure_candidate")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&closure_sig)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligations)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?obligation, ?closure_sig, ?obligations, "confirm_closure_candidate");
1731
1732 confirm_callable_candidate(selcx, obligation, closure_sig, util::TupleArgumentsFlag::No)
1733 .with_addl_obligations(nested)
1734 .with_addl_obligations(obligations)
1735}
1736
1737fn confirm_callable_candidate<'cx, 'tcx>(
1738 selcx: &mut SelectionContext<'cx, 'tcx>,
1739 obligation: &ProjectionTermObligation<'tcx>,
1740 fn_sig: ty::PolyFnSig<'tcx>,
1741 flag: util::TupleArgumentsFlag,
1742) -> Progress<'tcx> {
1743 let tcx = selcx.tcx();
1744
1745 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:1745",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(1745u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligation")
}> =
::tracing::__macro_support::FieldName::new("obligation");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fn_sig")
}> =
::tracing::__macro_support::FieldName::new("fn_sig");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("confirm_callable_candidate")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_sig)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?obligation, ?fn_sig, "confirm_callable_candidate");
1746
1747 let fn_once_def_id = tcx.require_lang_item(LangItem::FnOnce, obligation.cause.span);
1748 let fn_once_output_def_id =
1749 tcx.require_lang_item(LangItem::FnOnceOutput, obligation.cause.span);
1750
1751 let predicate = super::util::closure_trait_ref_and_return_type(
1752 tcx,
1753 fn_once_def_id,
1754 obligation.predicate.self_ty(),
1755 fn_sig,
1756 flag,
1757 )
1758 .map_bound(|(trait_ref, ret_type)| ty::ProjectionClause {
1759 projection_term: ty::AliasTerm::new_from_args(
1760 tcx,
1761 ty::AliasTermKind::ProjectionTy { def_id: fn_once_output_def_id },
1762 trait_ref.args,
1763 ),
1764 term: ret_type.into(),
1765 });
1766
1767 confirm_param_env_candidate(selcx, obligation, predicate, true)
1768}
1769
1770fn confirm_async_closure_candidate<'cx, 'tcx>(
1771 selcx: &mut SelectionContext<'cx, 'tcx>,
1772 obligation: &ProjectionTermObligation<'tcx>,
1773 nested: PredicateObligations<'tcx>,
1774) -> Progress<'tcx> {
1775 let tcx = selcx.tcx();
1776 let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
1777
1778 let goal_kind =
1779 tcx.async_fn_trait_kind_from_def_id(obligation.predicate.trait_def_id(tcx)).unwrap();
1780 let env_region = match goal_kind {
1781 ty::ClosureKind::Fn | ty::ClosureKind::FnMut => obligation.predicate.args.region_at(2),
1782 ty::ClosureKind::FnOnce => tcx.lifetimes.re_static,
1783 };
1784 let item_name = tcx.item_name(obligation.predicate.expect_projection_def_id());
1785
1786 let poly_cache_entry = match *self_ty.kind() {
1787 ty::CoroutineClosure(def_id, args) => {
1788 let args = args.as_coroutine_closure();
1789 let sig = args.coroutine_closure_sig().skip_binder();
1790
1791 let term = match item_name {
1792 sym::CallOnceFuture | sym::CallRefFuture => coroutine_closure_output_coroutine(
1793 tcx, obligation, goal_kind, env_region, def_id, args,
1794 ),
1795 sym::Output => sig.return_ty,
1796 name => ::rustc_middle::util::bug::bug_fmt(format_args!("no such associated type: {0}",
name))bug!("no such associated type: {name}"),
1797 };
1798 let projection_term = match item_name {
1799 sym::CallOnceFuture | sym::Output => ty::AliasTerm::new(
1800 tcx,
1801 obligation.predicate.kind,
1802 [self_ty, sig.tupled_inputs_ty],
1803 ),
1804 sym::CallRefFuture => ty::AliasTerm::new(
1805 tcx,
1806 obligation.predicate.kind,
1807 [ty::GenericArg::from(self_ty), sig.tupled_inputs_ty.into(), env_region.into()],
1808 ),
1809 name => ::rustc_middle::util::bug::bug_fmt(format_args!("no such associated type: {0}",
name))bug!("no such associated type: {name}"),
1810 };
1811
1812 args.coroutine_closure_sig()
1813 .rebind(ty::ProjectionClause { projection_term, term: term.into() })
1814 }
1815 ty::FnDef(..) | ty::FnPtr(..) => {
1816 let bound_sig = self_ty.fn_sig(tcx);
1817 let sig = bound_sig.skip_binder();
1818
1819 let term = match item_name {
1820 sym::CallOnceFuture | sym::CallRefFuture => sig.output(),
1821 sym::Output => {
1822 let future_output_def_id =
1823 tcx.require_lang_item(LangItem::FutureOutput, obligation.cause.span);
1824 Ty::new_projection(tcx, ty::IsRigid::No, future_output_def_id, [sig.output()])
1825 }
1826 name => ::rustc_middle::util::bug::bug_fmt(format_args!("no such associated type: {0}",
name))bug!("no such associated type: {name}"),
1827 };
1828 let projection_term = match item_name {
1829 sym::CallOnceFuture | sym::Output => ty::AliasTerm::new(
1830 tcx,
1831 obligation.predicate.kind,
1832 [self_ty, Ty::new_tup(tcx, sig.inputs())],
1833 ),
1834 sym::CallRefFuture => ty::AliasTerm::new(
1835 tcx,
1836 obligation.predicate.kind,
1837 [
1838 ty::GenericArg::from(self_ty),
1839 Ty::new_tup(tcx, sig.inputs()).into(),
1840 env_region.into(),
1841 ],
1842 ),
1843 name => ::rustc_middle::util::bug::bug_fmt(format_args!("no such associated type: {0}",
name))bug!("no such associated type: {name}"),
1844 };
1845
1846 bound_sig.rebind(ty::ProjectionClause { projection_term, term: term.into() })
1847 }
1848 ty::Closure(_, args) => {
1849 let args = args.as_closure();
1850 let bound_sig = args.sig();
1851 let sig = bound_sig.skip_binder();
1852
1853 let term = match item_name {
1854 sym::CallOnceFuture | sym::CallRefFuture => sig.output(),
1855 sym::Output => {
1856 let future_output_def_id =
1857 tcx.require_lang_item(LangItem::FutureOutput, obligation.cause.span);
1858 Ty::new_projection(tcx, ty::IsRigid::No, future_output_def_id, [sig.output()])
1859 }
1860 name => ::rustc_middle::util::bug::bug_fmt(format_args!("no such associated type: {0}",
name))bug!("no such associated type: {name}"),
1861 };
1862 let projection_term = match item_name {
1863 sym::CallOnceFuture | sym::Output => {
1864 ty::AliasTerm::new(tcx, obligation.predicate.kind, [self_ty, sig.inputs()[0]])
1865 }
1866 sym::CallRefFuture => ty::AliasTerm::new(
1867 tcx,
1868 obligation.predicate.kind,
1869 [ty::GenericArg::from(self_ty), sig.inputs()[0].into(), env_region.into()],
1870 ),
1871 name => ::rustc_middle::util::bug::bug_fmt(format_args!("no such associated type: {0}",
name))bug!("no such associated type: {name}"),
1872 };
1873
1874 bound_sig.rebind(ty::ProjectionClause { projection_term, term: term.into() })
1875 }
1876 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("expected callable type for AsyncFn candidate"))bug!("expected callable type for AsyncFn candidate"),
1877 };
1878
1879 confirm_param_env_candidate(selcx, obligation, poly_cache_entry, true)
1880 .with_addl_obligations(nested)
1881}
1882
1883fn coroutine_closure_output_coroutine<'tcx>(
1886 tcx: TyCtxt<'tcx>,
1887 obligation: &ProjectionTermObligation<'tcx>,
1888 goal_kind: ty::ClosureKind,
1889 env_region: ty::Region<'tcx>,
1890 def_id: DefId,
1891 args: ty::CoroutineClosureArgs<TyCtxt<'tcx>>,
1892) -> Ty<'tcx> {
1893 let kind_ty = args.kind_ty();
1894 let sig = args.coroutine_closure_sig().skip_binder();
1895
1896 if let Some(closure_kind) = kind_ty.to_opt_closure_kind()
1900 && !args.tupled_upvars_ty().is_ty_var()
1902 {
1903 if !closure_kind.extends(goal_kind) {
1904 ::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");
1905 }
1906 sig.to_coroutine_given_kind_and_upvars(
1907 tcx,
1908 args.parent_args(),
1909 tcx.coroutine_for_closure(def_id),
1910 goal_kind,
1911 env_region,
1912 args.tupled_upvars_ty(),
1913 args.coroutine_captures_by_ref_ty(),
1914 )
1915 } else {
1916 let upvars_projection_def_id =
1917 tcx.require_lang_item(LangItem::AsyncFnKindUpvars, obligation.cause.span);
1918 let tupled_upvars_ty = Ty::new_projection(
1927 tcx,
1928 ty::IsRigid::No,
1929 upvars_projection_def_id,
1930 [
1931 ty::GenericArg::from(kind_ty),
1932 Ty::from_closure_kind(tcx, goal_kind).into(),
1933 env_region.into(),
1934 sig.tupled_inputs_ty.into(),
1935 args.tupled_upvars_ty().into(),
1936 args.coroutine_captures_by_ref_ty().into(),
1937 ],
1938 );
1939 sig.to_coroutine(
1940 tcx,
1941 args.parent_args(),
1942 Ty::from_closure_kind(tcx, goal_kind),
1943 tcx.coroutine_for_closure(def_id),
1944 tupled_upvars_ty,
1945 )
1946 }
1947}
1948
1949fn confirm_async_fn_kind_helper_candidate<'cx, 'tcx>(
1950 selcx: &mut SelectionContext<'cx, 'tcx>,
1951 obligation: &ProjectionTermObligation<'tcx>,
1952 nested: PredicateObligations<'tcx>,
1953) -> Progress<'tcx> {
1954 let [
1955 _closure_kind_ty,
1957 goal_kind_ty,
1958 borrow_region,
1959 tupled_inputs_ty,
1960 tupled_upvars_ty,
1961 coroutine_captures_by_ref_ty,
1962 ] = **obligation.predicate.args
1963 else {
1964 ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"));bug!();
1965 };
1966
1967 let predicate = ty::ProjectionClause {
1968 projection_term: obligation.predicate.with_args(selcx.tcx(), obligation.predicate.args),
1969 term: ty::CoroutineClosureSignature::tupled_upvars_by_closure_kind(
1970 selcx.tcx(),
1971 goal_kind_ty.expect_ty().to_opt_closure_kind().unwrap(),
1972 tupled_inputs_ty.expect_ty(),
1973 tupled_upvars_ty.expect_ty(),
1974 coroutine_captures_by_ref_ty.expect_ty(),
1975 borrow_region.expect_region(),
1976 )
1977 .into(),
1978 };
1979
1980 confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
1981 .with_addl_obligations(nested)
1982}
1983
1984fn confirm_param_env_candidate<'cx, 'tcx>(
1986 selcx: &mut SelectionContext<'cx, 'tcx>,
1987 obligation: &ProjectionTermObligation<'tcx>,
1988 poly_cache_entry: ty::PolyProjectionClause<'tcx>,
1989 potentially_unnormalized_candidate: bool,
1990) -> Progress<'tcx> {
1991 let infcx = selcx.infcx;
1992 let cause = &obligation.cause;
1993 let param_env = obligation.param_env;
1994
1995 let cache_entry = infcx.instantiate_binder_with_fresh_vars(
1996 cause.span,
1997 BoundRegionConversionTime::HigherRankedType,
1998 poly_cache_entry,
1999 );
2000
2001 let mut cache_projection = cache_entry.projection_term;
2002 let mut nested_obligations = PredicateObligations::new();
2003 let obligation_projection = obligation.predicate;
2004 let obligation_projection = normalize_with_depth_to(
2005 selcx,
2006 obligation.param_env,
2007 obligation.cause.clone(),
2008 obligation.recursion_depth + 1,
2009 ty::Unnormalized::new_wip(obligation_projection),
2010 &mut nested_obligations,
2011 );
2012 if potentially_unnormalized_candidate {
2013 cache_projection = normalize_with_depth_to(
2014 selcx,
2015 obligation.param_env,
2016 obligation.cause.clone(),
2017 obligation.recursion_depth + 1,
2018 ty::Unnormalized::new_wip(cache_projection),
2019 &mut nested_obligations,
2020 );
2021 }
2022
2023 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:2023",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(2023u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::project"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("cache_projection")
}> =
::tracing::__macro_support::FieldName::new("cache_projection");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligation_projection")
}> =
::tracing::__macro_support::FieldName::new("obligation_projection");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&cache_projection)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation_projection)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?cache_projection, ?obligation_projection);
2024
2025 match infcx.at(cause, param_env).eq(
2026 DefineOpaqueTypes::Yes,
2027 cache_projection,
2028 obligation_projection,
2029 ) {
2030 Ok(InferOk { value: _, obligations }) => {
2031 nested_obligations.extend(obligations);
2032 assoc_term_own_obligations(selcx, obligation, &mut nested_obligations);
2033 Progress {
2034 term: ty::Unnormalized::new(cache_entry.term),
2035 obligations: nested_obligations,
2036 }
2037 }
2038 Err(e) => {
2039 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!(
2040 "Failed to unify obligation `{obligation:?}` with poly_projection `{poly_cache_entry:?}`: {e:?}",
2041 );
2042 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:2042",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(2042u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("confirm_param_env_candidate: {0}",
msg) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("confirm_param_env_candidate: {}", msg);
2043 let err = Ty::new_error_with_message(infcx.tcx, obligation.cause.span, msg);
2044 Progress {
2045 term: ty::Unnormalized::dummy(err.into()),
2046 obligations: PredicateObligations::new(),
2047 }
2048 }
2049 }
2050}
2051
2052fn confirm_impl_candidate<'cx, 'tcx>(
2054 selcx: &mut SelectionContext<'cx, 'tcx>,
2055 obligation: &ProjectionTermObligation<'tcx>,
2056 impl_impl_source: ImplSourceUserDefinedData<'tcx, PredicateObligation<'tcx>>,
2057) -> Result<Projected<'tcx>, ProjectionError<'tcx>> {
2058 let tcx = selcx.tcx();
2059
2060 let ImplSourceUserDefinedData { impl_def_id, args, mut nested } = impl_impl_source;
2061
2062 let assoc_item_id = obligation.predicate.expect_projection_def_id();
2063 let trait_def_id = tcx.impl_trait_id(impl_def_id);
2064
2065 let param_env = obligation.param_env;
2066 let assoc_term = match specialization_graph::assoc_def(tcx, impl_def_id, assoc_item_id) {
2067 Ok(assoc_term) => assoc_term,
2068 Err(guar) => {
2069 return Ok(Projected::Progress(Progress::error_for_term(
2070 tcx,
2071 obligation.predicate,
2072 guar,
2073 )));
2074 }
2075 };
2076
2077 if !assoc_term.item.defaultness(tcx).has_value() {
2083 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs:2083",
"rustc_trait_selection::traits::project",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/4aa1fbcf467cf38ce58abfa8eb9213a789c5381c/compiler/rustc_trait_selection/src/traits/project.rs"),
::tracing_core::__macro_support::Option::Some(2083u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("confirm_impl_candidate: no associated type {0:?} for {1:?}",
assoc_term.item.name(), obligation.predicate) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
2084 "confirm_impl_candidate: no associated type {:?} for {:?}",
2085 assoc_term.item.name(),
2086 obligation.predicate
2087 );
2088 if tcx.impl_self_is_guaranteed_unsized(impl_def_id) {
2089 return Ok(Projected::NoProgress(obligation.predicate.to_term(tcx, ty::IsRigid::No)));
2094 } else {
2095 return Ok(Projected::Progress(Progress {
2096 term: ty::Unnormalized::dummy(if obligation.predicate.kind.is_type() {
2097 Ty::new_misc_error(tcx).into()
2098 } else {
2099 ty::Const::new_misc_error(tcx).into()
2100 }),
2101 obligations: nested,
2102 }));
2103 }
2104 }
2105
2106 let args = obligation.predicate.args.rebase_onto(tcx, trait_def_id, args);
2113 let args = translate_args(selcx.infcx, param_env, impl_def_id, args, assoc_term.defining_node);
2114
2115 let term_kind = if obligation.predicate.kind.is_type() {
2116 ty::AliasTermKind::ProjectionTy { def_id: assoc_term.item.def_id }
2117 } else {
2118 ty::AliasTermKind::ProjectionConst { def_id: assoc_term.item.def_id }
2119 };
2120
2121 let progress = if !tcx.check_alias_term_args_compatible(term_kind, args) {
2122 let msg = "impl item and trait item have different parameters";
2123 let span = obligation.cause.span;
2124 let err = if obligation.predicate.kind.is_type() {
2125 Ty::new_error_with_message(tcx, span, msg).into()
2126 } else {
2127 ty::Const::new_error_with_message(tcx, span, msg).into()
2128 };
2129 Progress { term: ty::Unnormalized::dummy(err), obligations: nested }
2130 } else {
2131 let term = if obligation.predicate.kind.is_type() {
2132 tcx.type_of(assoc_term.item.def_id).map_bound(|ty| ty.into())
2133 } else {
2134 const_of_item_or_delayed_bug(tcx, assoc_term.item.def_id).map_bound(|ct| ct.into())
2135 };
2136
2137 assoc_term_own_obligations(selcx, obligation, &mut nested);
2138 let instantiated_term = term.instantiate(tcx, args);
2139 let term_for_obligation = instantiated_term.skip_norm_wip();
2140 push_const_arg_has_type_obligation(
2141 tcx,
2142 &mut nested,
2143 &obligation.cause,
2144 obligation.recursion_depth + 1,
2145 obligation.param_env,
2146 term_for_obligation,
2147 assoc_term.item.def_id,
2148 args,
2149 );
2150 Progress { term: instantiated_term, obligations: nested }
2151 };
2152 Ok(Projected::Progress(progress))
2153}
2154
2155fn assoc_term_own_obligations<'cx, 'tcx>(
2162 selcx: &mut SelectionContext<'cx, 'tcx>,
2163 obligation: &ProjectionTermObligation<'tcx>,
2164 nested: &mut PredicateObligations<'tcx>,
2165) {
2166 let tcx = selcx.tcx();
2167 let def_id = obligation.predicate.expect_projection_def_id();
2168 let clauses = tcx.clauses_of(def_id).instantiate_own(tcx, obligation.predicate.args);
2169 for (clause, span) in clauses {
2170 let normalized = normalize_with_depth_to(
2171 selcx,
2172 obligation.param_env,
2173 obligation.cause.clone(),
2174 obligation.recursion_depth + 1,
2175 clause,
2176 nested,
2177 );
2178
2179 let nested_cause = if #[allow(non_exhaustive_omitted_patterns)] match obligation.cause.code() {
ObligationCauseCode::CompareImplItem { .. } |
ObligationCauseCode::CheckAssociatedTypeBounds { .. } |
ObligationCauseCode::AscribeUserTypeProvePredicate(..) => true,
_ => false,
}matches!(
2180 obligation.cause.code(),
2181 ObligationCauseCode::CompareImplItem { .. }
2182 | ObligationCauseCode::CheckAssociatedTypeBounds { .. }
2183 | ObligationCauseCode::AscribeUserTypeProvePredicate(..)
2184 ) {
2185 obligation.cause.clone()
2186 } else {
2187 ObligationCause::new(
2188 obligation.cause.span,
2189 obligation.cause.body_def_id,
2190 ObligationCauseCode::WhereClause(def_id, span),
2191 )
2192 };
2193 nested.push(Obligation::with_depth(
2194 tcx,
2195 nested_cause,
2196 obligation.recursion_depth + 1,
2197 obligation.param_env,
2198 normalized,
2199 ));
2200 }
2201}
2202
2203pub(crate) trait ProjectionCacheKeyExt<'cx, 'tcx>: Sized {
2204 fn from_poly_projection_obligation(
2205 selcx: &mut SelectionContext<'cx, 'tcx>,
2206 obligation: &PolyProjectionObligation<'tcx>,
2207 ) -> Option<Self>;
2208}
2209
2210impl<'cx, 'tcx> ProjectionCacheKeyExt<'cx, 'tcx> for ProjectionCacheKey<'tcx> {
2211 fn from_poly_projection_obligation(
2212 selcx: &mut SelectionContext<'cx, 'tcx>,
2213 obligation: &PolyProjectionObligation<'tcx>,
2214 ) -> Option<Self> {
2215 let infcx = selcx.infcx;
2216 obligation.predicate.no_bound_vars().map(|predicate| {
2219 ProjectionCacheKey::new(
2220 infcx.resolve_vars_if_possible(predicate.projection_term),
2225 obligation.param_env,
2226 )
2227 })
2228 }
2229}