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