1use std::ops::ControlFlow;
11
12use rustc_data_structures::stack::ensure_sufficient_stack;
13use rustc_hir::lang_items::LangItem;
14use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk};
15use rustc_infer::traits::ObligationCauseCode;
16use rustc_middle::traits::{BuiltinImplSource, SignatureMismatchData};
17use rustc_middle::ty::{
18 self, GenericArgsRef, Region, SizedTraitKind, Ty, TyCtxt, Unnormalized, Upcast,
19};
20use rustc_middle::{bug, span_bug};
21use rustc_span::def_id::DefId;
22use thin_vec::thin_vec;
23use tracing::{debug, instrument};
24
25use super::SelectionCandidate::{self, *};
26use super::{PredicateObligations, SelectionContext};
27use crate::traits::normalize::{normalize_with_depth, normalize_with_depth_to};
28use crate::traits::util::{self, closure_trait_ref_and_return_type};
29use crate::traits::{
30 ImplSource, ImplSourceUserDefinedData, Normalized, Obligation, ObligationCause,
31 PolyTraitObligation, PredicateObligation, Selection, SelectionError, TraitObligation,
32};
33
34impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
35 #[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("confirm_candidate",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(35u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::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()
},
{
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::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)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&candidate)
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<Selection<'tcx>, SelectionError<'tcx>> = loop {};
return __tracing_attr_fake_return;
}
{
Ok(match candidate {
SizedCandidate => {
let data = self.confirm_builtin_candidate(obligation);
ImplSource::Builtin(BuiltinImplSource::Misc, data)
}
BuiltinCandidate => {
let data = self.confirm_builtin_candidate(obligation);
ImplSource::Builtin(BuiltinImplSource::Misc, data)
}
TransmutabilityCandidate => {
let data =
self.confirm_transmutability_candidate(obligation)?;
ImplSource::Builtin(BuiltinImplSource::Misc, data)
}
ParamCandidate(param) => {
let obligations =
self.confirm_param_candidate(obligation,
param.map_bound(|t| t.trait_ref));
ImplSource::Param(obligations)
}
ImplCandidate(impl_def_id) => {
ImplSource::UserDefined(self.confirm_impl_candidate(obligation,
impl_def_id))
}
AutoImplCandidate => {
let data = self.confirm_auto_impl_candidate(obligation)?;
ImplSource::Builtin(BuiltinImplSource::Misc, data)
}
ProjectionCandidate { idx, .. } => {
let obligations =
self.confirm_projection_candidate(obligation, idx)?;
ImplSource::Param(obligations)
}
ObjectCandidate(idx) =>
self.confirm_object_candidate(obligation, idx)?,
ClosureCandidate { .. } => {
let vtable_closure =
self.confirm_closure_candidate(obligation)?;
ImplSource::Builtin(BuiltinImplSource::Misc, vtable_closure)
}
AsyncClosureCandidate => {
let vtable_closure =
self.confirm_async_closure_candidate(obligation)?;
ImplSource::Builtin(BuiltinImplSource::Misc, vtable_closure)
}
AsyncFnKindHelperCandidate => {
ImplSource::Builtin(BuiltinImplSource::Misc,
PredicateObligations::new())
}
CoroutineCandidate => {
let vtable_coroutine =
self.confirm_coroutine_candidate(obligation)?;
ImplSource::Builtin(BuiltinImplSource::Misc,
vtable_coroutine)
}
FutureCandidate => {
let vtable_future =
self.confirm_future_candidate(obligation)?;
ImplSource::Builtin(BuiltinImplSource::Misc, vtable_future)
}
IteratorCandidate => {
let vtable_iterator =
self.confirm_iterator_candidate(obligation)?;
ImplSource::Builtin(BuiltinImplSource::Misc,
vtable_iterator)
}
AsyncIteratorCandidate => {
let vtable_iterator =
self.confirm_async_iterator_candidate(obligation)?;
ImplSource::Builtin(BuiltinImplSource::Misc,
vtable_iterator)
}
FnPointerCandidate => {
let data = self.confirm_fn_pointer_candidate(obligation)?;
ImplSource::Builtin(BuiltinImplSource::Misc, data)
}
TraitAliasCandidate => {
let data = self.confirm_trait_alias_candidate(obligation);
ImplSource::Builtin(BuiltinImplSource::Misc, data)
}
BuiltinObjectCandidate => {
ImplSource::Builtin(BuiltinImplSource::Misc,
PredicateObligations::new())
}
BuiltinUnsizeCandidate =>
self.confirm_builtin_unsize_candidate(obligation)?,
TraitUpcastingUnsizeCandidate(idx) => {
self.confirm_trait_upcasting_unsize_candidate(obligation,
idx)?
}
BikeshedGuaranteedNoDropCandidate => {
self.confirm_bikeshed_guaranteed_no_drop_candidate(obligation)
}
TryAsDynCandidate =>
self.confirm_try_as_dyn_candidate(obligation),
})
}
}
}#[instrument(level = "debug", skip(self))]
36 pub(super) fn confirm_candidate(
37 &mut self,
38 obligation: &PolyTraitObligation<'tcx>,
39 candidate: SelectionCandidate<'tcx>,
40 ) -> Result<Selection<'tcx>, SelectionError<'tcx>> {
41 Ok(match candidate {
42 SizedCandidate => {
43 let data = self.confirm_builtin_candidate(obligation);
44 ImplSource::Builtin(BuiltinImplSource::Misc, data)
45 }
46
47 BuiltinCandidate => {
48 let data = self.confirm_builtin_candidate(obligation);
49 ImplSource::Builtin(BuiltinImplSource::Misc, data)
50 }
51
52 TransmutabilityCandidate => {
53 let data = self.confirm_transmutability_candidate(obligation)?;
54 ImplSource::Builtin(BuiltinImplSource::Misc, data)
55 }
56
57 ParamCandidate(param) => {
58 let obligations =
59 self.confirm_param_candidate(obligation, param.map_bound(|t| t.trait_ref));
60 ImplSource::Param(obligations)
61 }
62
63 ImplCandidate(impl_def_id) => {
64 ImplSource::UserDefined(self.confirm_impl_candidate(obligation, impl_def_id))
65 }
66
67 AutoImplCandidate => {
68 let data = self.confirm_auto_impl_candidate(obligation)?;
69 ImplSource::Builtin(BuiltinImplSource::Misc, data)
70 }
71
72 ProjectionCandidate { idx, .. } => {
73 let obligations = self.confirm_projection_candidate(obligation, idx)?;
74 ImplSource::Param(obligations)
75 }
76
77 ObjectCandidate(idx) => self.confirm_object_candidate(obligation, idx)?,
78
79 ClosureCandidate { .. } => {
80 let vtable_closure = self.confirm_closure_candidate(obligation)?;
81 ImplSource::Builtin(BuiltinImplSource::Misc, vtable_closure)
82 }
83
84 AsyncClosureCandidate => {
85 let vtable_closure = self.confirm_async_closure_candidate(obligation)?;
86 ImplSource::Builtin(BuiltinImplSource::Misc, vtable_closure)
87 }
88
89 AsyncFnKindHelperCandidate => {
92 ImplSource::Builtin(BuiltinImplSource::Misc, PredicateObligations::new())
93 }
94
95 CoroutineCandidate => {
96 let vtable_coroutine = self.confirm_coroutine_candidate(obligation)?;
97 ImplSource::Builtin(BuiltinImplSource::Misc, vtable_coroutine)
98 }
99
100 FutureCandidate => {
101 let vtable_future = self.confirm_future_candidate(obligation)?;
102 ImplSource::Builtin(BuiltinImplSource::Misc, vtable_future)
103 }
104
105 IteratorCandidate => {
106 let vtable_iterator = self.confirm_iterator_candidate(obligation)?;
107 ImplSource::Builtin(BuiltinImplSource::Misc, vtable_iterator)
108 }
109
110 AsyncIteratorCandidate => {
111 let vtable_iterator = self.confirm_async_iterator_candidate(obligation)?;
112 ImplSource::Builtin(BuiltinImplSource::Misc, vtable_iterator)
113 }
114
115 FnPointerCandidate => {
116 let data = self.confirm_fn_pointer_candidate(obligation)?;
117 ImplSource::Builtin(BuiltinImplSource::Misc, data)
118 }
119
120 TraitAliasCandidate => {
121 let data = self.confirm_trait_alias_candidate(obligation);
122 ImplSource::Builtin(BuiltinImplSource::Misc, data)
123 }
124
125 BuiltinObjectCandidate => {
126 ImplSource::Builtin(BuiltinImplSource::Misc, PredicateObligations::new())
130 }
131
132 BuiltinUnsizeCandidate => self.confirm_builtin_unsize_candidate(obligation)?,
133
134 TraitUpcastingUnsizeCandidate(idx) => {
135 self.confirm_trait_upcasting_unsize_candidate(obligation, idx)?
136 }
137
138 BikeshedGuaranteedNoDropCandidate => {
139 self.confirm_bikeshed_guaranteed_no_drop_candidate(obligation)
140 }
141
142 TryAsDynCandidate => self.confirm_try_as_dyn_candidate(obligation),
143 })
144 }
145
146 fn confirm_projection_candidate(
147 &mut self,
148 obligation: &PolyTraitObligation<'tcx>,
149 idx: usize,
150 ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
151 let placeholder_trait_predicate =
152 self.infcx.enter_forall_and_leak_universe(obligation.predicate).trait_ref;
153 let placeholder_self_ty = self.infcx.shallow_resolve(placeholder_trait_predicate.self_ty());
154 let candidate_predicate = self
155 .for_each_item_bound(
156 placeholder_self_ty,
157 |_, clause, clause_idx, _| {
158 if clause_idx == idx {
159 ControlFlow::Break(clause)
160 } else {
161 ControlFlow::Continue(())
162 }
163 },
164 || ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
165 )
166 .break_value()
167 .expect("expected to index into clause that exists");
168 let candidate_predicate = candidate_predicate
169 .as_trait_clause()
170 .expect("projection candidate is not a trait predicate");
171 let candidate_predicate =
172 util::lazily_elaborate_sizedness_candidate(self.infcx, obligation, candidate_predicate);
173
174 let candidate = candidate_predicate.map_bound(|t| t.trait_ref);
175
176 let candidate = self.infcx.instantiate_binder_with_fresh_vars(
177 obligation.cause.span,
178 BoundRegionConversionTime::HigherRankedType,
179 candidate,
180 );
181 let mut obligations = PredicateObligations::new();
182 let candidate = normalize_with_depth_to(
183 self,
184 obligation.param_env,
185 obligation.cause.clone(),
186 obligation.recursion_depth + 1,
187 ty::Unnormalized::new_wip(candidate),
188 &mut obligations,
189 );
190
191 obligations.extend(
192 self.infcx
193 .at(&obligation.cause, obligation.param_env)
194 .eq(DefineOpaqueTypes::No, placeholder_trait_predicate, candidate)
195 .map(|InferOk { obligations, .. }| obligations)
196 .map_err(|_| SelectionError::Unimplemented)?,
197 );
198
199 Ok(obligations)
200 }
201
202 fn confirm_param_candidate(
203 &mut self,
204 obligation: &PolyTraitObligation<'tcx>,
205 param: ty::PolyTraitRef<'tcx>,
206 ) -> PredicateObligations<'tcx> {
207 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:207",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(207u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::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("param")
}> =
::tracing::__macro_support::FieldName::new("param");
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_param_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(¶m)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?obligation, ?param, "confirm_param_candidate");
208
209 let param = util::lazily_elaborate_sizedness_candidate(
210 self.infcx,
211 obligation,
212 param.upcast(self.infcx.tcx),
213 )
214 .map_bound(|p| p.trait_ref);
215
216 match self.match_where_clause_trait_ref(obligation, param) {
221 Ok(obligations) => obligations,
222 Err(()) => {
223 ::rustc_middle::util::bug::bug_fmt(format_args!("Where clause `{0:?}` was applicable to `{1:?}` but now is not",
param, obligation));bug!(
224 "Where clause `{:?}` was applicable to `{:?}` but now is not",
225 param,
226 obligation
227 );
228 }
229 }
230 }
231
232 x;#[instrument(level = "debug", skip(self), ret)]
233 fn confirm_builtin_candidate(
234 &mut self,
235 obligation: &PolyTraitObligation<'tcx>,
236 ) -> PredicateObligations<'tcx> {
237 debug!(?obligation, "confirm_builtin_candidate");
238 let tcx = self.tcx();
239 let trait_def = obligation.predicate.def_id();
240 let self_ty = self.infcx.shallow_resolve(
241 self.infcx.enter_forall_and_leak_universe(obligation.predicate.self_ty()),
242 );
243 let types = match tcx.as_lang_item(trait_def) {
244 Some(LangItem::Sized) => self.sizedness_conditions(self_ty, SizedTraitKind::Sized),
245 Some(LangItem::MetaSized) => {
246 self.sizedness_conditions(self_ty, SizedTraitKind::MetaSized)
247 }
248 Some(LangItem::PointeeSized) => {
249 bug!("`PointeeSized` is removing during lowering");
250 }
251 Some(LangItem::Copy | LangItem::Clone | LangItem::TrivialClone) => {
252 self.copy_clone_conditions(self_ty)
253 }
254 Some(LangItem::FusedIterator) => {
255 if self.coroutine_is_gen(self_ty) {
256 ty::Binder::dummy(vec![])
257 } else {
258 unreachable!("tried to assemble `FusedIterator` for non-gen coroutine");
259 }
260 }
261 Some(
262 LangItem::Destruct
263 | LangItem::DiscriminantKind
264 | LangItem::Field
265 | LangItem::FnPtrTrait
266 | LangItem::PointeeTrait
267 | LangItem::Tuple
268 | LangItem::Unpin,
269 ) => ty::Binder::dummy(vec![]),
270 other => bug!("unexpected builtin trait {trait_def:?} ({other:?})"),
271 };
272 let types = self.infcx.enter_forall_and_leak_universe(types);
273
274 let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerived);
275 self.collect_predicates_for_types(
276 obligation.param_env,
277 cause,
278 obligation.recursion_depth + 1,
279 trait_def,
280 types,
281 )
282 }
283
284 #[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("confirm_transmutability_candidate",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(284u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::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:
Result<PredicateObligations<'tcx>, SelectionError<'tcx>> =
loop {};
return __tracing_attr_fake_return;
}
{
use rustc_transmute::{Answer, Assume, Condition};
#[doc =
" Flatten the `Condition` tree into a conjunction of obligations."]
fn flatten_answer_tree<'tcx>(tcx: TyCtxt<'tcx>,
obligation: &PolyTraitObligation<'tcx>,
cond: Condition<Region<'tcx>, Ty<'tcx>>, assume: Assume)
-> PredicateObligations<'tcx> {
{}
#[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("flatten_answer_tree",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(292u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("cond")
}> =
::tracing::__macro_support::FieldName::new("cond");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("assume")
}> =
::tracing::__macro_support::FieldName::new("assume");
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(&cond)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&assume)
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: PredicateObligations<'tcx> =
loop {};
return __tracing_attr_fake_return;
}
{
match cond {
Condition::IfAll(conds) | Condition::IfAny(conds) =>
conds.into_iter().flat_map(|cond|
flatten_answer_tree(tcx, obligation, cond,
assume)).collect(),
Condition::Immutable { ty } => {
let trait_ref =
ty::TraitRef::new(tcx,
tcx.require_lang_item(LangItem::Freeze,
obligation.cause.span), [ty::GenericArg::from(ty)]);
{
let len = [()].len();
let mut vec = ::thin_vec::ThinVec::with_capacity(len);
vec.push(Obligation::with_depth(tcx,
obligation.cause.clone(), obligation.recursion_depth + 1,
obligation.param_env, trait_ref));
vec
}
}
Condition::Outlives { long, short } => {
let outlives = ty::OutlivesPredicate(long, short);
{
let len = [()].len();
let mut vec = ::thin_vec::ThinVec::with_capacity(len);
vec.push(Obligation::with_depth(tcx,
obligation.cause.clone(), obligation.recursion_depth + 1,
obligation.param_env, outlives));
vec
}
}
Condition::Transmutable { src, dst } => {
let transmute_trait = obligation.predicate.def_id();
let assume =
obligation.predicate.skip_binder().trait_ref.args.const_at(2);
let trait_ref =
ty::TraitRef::new(tcx, transmute_trait,
[ty::GenericArg::from(dst), ty::GenericArg::from(src),
ty::GenericArg::from(assume)]);
{
let len = [()].len();
let mut vec = ::thin_vec::ThinVec::with_capacity(len);
vec.push(Obligation::with_depth(tcx,
obligation.cause.clone(), obligation.recursion_depth + 1,
obligation.param_env, trait_ref));
vec
}
}
}
}
}
}
}
let predicate =
self.infcx.enter_forall_and_leak_universe(obligation.predicate);
let mut assume = predicate.trait_ref.args.const_at(2);
if self.tcx().features().generic_const_exprs() {
assume =
crate::traits::evaluate_const(self.infcx, assume,
obligation.param_env)
}
let Some(assume) =
rustc_transmute::Assume::from_const(self.infcx.tcx,
assume) else { return Err(SelectionError::Unimplemented); };
let dst = predicate.trait_ref.args.type_at(0);
let src = predicate.trait_ref.args.type_at(1);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:366",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(366u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("src")
}> =
::tracing::__macro_support::FieldName::new("src");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("dst")
}> =
::tracing::__macro_support::FieldName::new("dst");
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(&src)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&dst)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let mut transmute_env =
rustc_transmute::TransmuteTypeEnv::new(self.infcx.tcx);
let maybe_transmutable =
transmute_env.is_transmutable(src, dst, assume);
let fully_flattened =
match maybe_transmutable {
Answer::No(_) => Err(SelectionError::Unimplemented)?,
Answer::If(cond) =>
flatten_answer_tree(self.tcx(), obligation, cond, assume),
Answer::Yes => PredicateObligations::new(),
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:376",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(376u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fully_flattened")
}> =
::tracing::__macro_support::FieldName::new("fully_flattened");
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(&fully_flattened)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
Ok(fully_flattened)
}
}
}#[instrument(level = "debug", skip(self))]
285 fn confirm_transmutability_candidate(
286 &mut self,
287 obligation: &PolyTraitObligation<'tcx>,
288 ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
289 use rustc_transmute::{Answer, Assume, Condition};
290
291 #[instrument(level = "debug", skip(tcx, obligation))]
293 fn flatten_answer_tree<'tcx>(
294 tcx: TyCtxt<'tcx>,
295 obligation: &PolyTraitObligation<'tcx>,
296 cond: Condition<Region<'tcx>, Ty<'tcx>>,
297 assume: Assume,
298 ) -> PredicateObligations<'tcx> {
299 match cond {
300 Condition::IfAll(conds) | Condition::IfAny(conds) => conds
303 .into_iter()
304 .flat_map(|cond| flatten_answer_tree(tcx, obligation, cond, assume))
305 .collect(),
306 Condition::Immutable { ty } => {
307 let trait_ref = ty::TraitRef::new(
308 tcx,
309 tcx.require_lang_item(LangItem::Freeze, obligation.cause.span),
310 [ty::GenericArg::from(ty)],
311 );
312 thin_vec![Obligation::with_depth(
313 tcx,
314 obligation.cause.clone(),
315 obligation.recursion_depth + 1,
316 obligation.param_env,
317 trait_ref,
318 )]
319 }
320 Condition::Outlives { long, short } => {
321 let outlives = ty::OutlivesPredicate(long, short);
322 thin_vec![Obligation::with_depth(
323 tcx,
324 obligation.cause.clone(),
325 obligation.recursion_depth + 1,
326 obligation.param_env,
327 outlives,
328 )]
329 }
330 Condition::Transmutable { src, dst } => {
331 let transmute_trait = obligation.predicate.def_id();
332 let assume = obligation.predicate.skip_binder().trait_ref.args.const_at(2);
333 let trait_ref = ty::TraitRef::new(
334 tcx,
335 transmute_trait,
336 [
337 ty::GenericArg::from(dst),
338 ty::GenericArg::from(src),
339 ty::GenericArg::from(assume),
340 ],
341 );
342 thin_vec![Obligation::with_depth(
343 tcx,
344 obligation.cause.clone(),
345 obligation.recursion_depth + 1,
346 obligation.param_env,
347 trait_ref,
348 )]
349 }
350 }
351 }
352
353 let predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
354
355 let mut assume = predicate.trait_ref.args.const_at(2);
356 if self.tcx().features().generic_const_exprs() {
357 assume = crate::traits::evaluate_const(self.infcx, assume, obligation.param_env)
358 }
359 let Some(assume) = rustc_transmute::Assume::from_const(self.infcx.tcx, assume) else {
360 return Err(SelectionError::Unimplemented);
361 };
362
363 let dst = predicate.trait_ref.args.type_at(0);
364 let src = predicate.trait_ref.args.type_at(1);
365
366 debug!(?src, ?dst);
367 let mut transmute_env = rustc_transmute::TransmuteTypeEnv::new(self.infcx.tcx);
368 let maybe_transmutable = transmute_env.is_transmutable(src, dst, assume);
369
370 let fully_flattened = match maybe_transmutable {
371 Answer::No(_) => Err(SelectionError::Unimplemented)?,
372 Answer::If(cond) => flatten_answer_tree(self.tcx(), obligation, cond, assume),
373 Answer::Yes => PredicateObligations::new(),
374 };
375
376 debug!(?fully_flattened);
377 Ok(fully_flattened)
378 }
379
380 fn confirm_auto_impl_candidate(
386 &mut self,
387 obligation: &PolyTraitObligation<'tcx>,
388 ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
389 ensure_sufficient_stack(|| {
390 {
match (&obligation.predicate.polarity(), &ty::PredicatePolarity::Positive)
{
(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!(obligation.predicate.polarity(), ty::PredicatePolarity::Positive);
391
392 let self_ty =
393 obligation.predicate.self_ty().map_bound(|ty| self.infcx.shallow_resolve(ty));
394 let self_ty = self.infcx.enter_forall_and_leak_universe(self_ty);
395
396 let constituents = self.constituent_types_for_auto_trait(self_ty)?;
397 let constituents = self.infcx.enter_forall_and_leak_universe(constituents);
398
399 let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerived);
400 let mut obligations = self.collect_predicates_for_types(
401 obligation.param_env,
402 cause.clone(),
403 obligation.recursion_depth + 1,
404 obligation.predicate.def_id(),
405 constituents.types,
406 );
407
408 if self.tcx().sess.opts.unstable_opts.higher_ranked_assumptions {
412 for assumption in constituents.assumptions {
416 let assumption = normalize_with_depth_to(
417 self,
418 obligation.param_env,
419 cause.clone(),
420 obligation.recursion_depth + 1,
421 Unnormalized::new_wip(assumption),
422 &mut obligations,
423 );
424 self.infcx.register_region_assumption(assumption);
425 }
426 }
427
428 Ok(obligations)
429 })
430 }
431
432 fn confirm_impl_candidate(
433 &mut self,
434 obligation: &PolyTraitObligation<'tcx>,
435 impl_def_id: DefId,
436 ) -> ImplSourceUserDefinedData<'tcx, PredicateObligation<'tcx>> {
437 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:437",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(437u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::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("impl_def_id")
}> =
::tracing::__macro_support::FieldName::new("impl_def_id");
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_impl_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(&impl_def_id)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?obligation, ?impl_def_id, "confirm_impl_candidate");
438
439 let args = self.rematch_impl(impl_def_id, obligation);
442 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:442",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(442u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("args")
}> =
::tracing::__macro_support::FieldName::new("args");
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!("impl args")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?args, "impl args");
443 ensure_sufficient_stack(|| {
444 self.vtable_impl(
445 impl_def_id,
446 args,
447 &obligation.cause,
448 obligation.recursion_depth + 1,
449 obligation.param_env,
450 obligation.predicate,
451 )
452 })
453 }
454
455 fn vtable_impl(
456 &mut self,
457 impl_def_id: DefId,
458 args: Normalized<'tcx, GenericArgsRef<'tcx>>,
459 cause: &ObligationCause<'tcx>,
460 recursion_depth: usize,
461 param_env: ty::ParamEnv<'tcx>,
462 parent_trait_pred: ty::Binder<'tcx, ty::TraitPredicate<'tcx>>,
463 ) -> ImplSourceUserDefinedData<'tcx, PredicateObligation<'tcx>> {
464 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:464",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(464u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("impl_def_id")
}> =
::tracing::__macro_support::FieldName::new("impl_def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("args")
}> =
::tracing::__macro_support::FieldName::new("args");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("recursion_depth")
}> =
::tracing::__macro_support::FieldName::new("recursion_depth");
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!("vtable_impl")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&impl_def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&recursion_depth)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?impl_def_id, ?args, ?recursion_depth, "vtable_impl");
465
466 let mut impl_obligations = self.impl_or_trait_obligations(
467 cause,
468 recursion_depth,
469 param_env,
470 impl_def_id,
471 args.value,
472 parent_trait_pred,
473 );
474
475 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:475",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(475u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("impl_obligations")
}> =
::tracing::__macro_support::FieldName::new("impl_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!("vtable_impl")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&impl_obligations)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?impl_obligations, "vtable_impl");
476
477 impl_obligations.extend(args.obligations);
483
484 ImplSourceUserDefinedData { impl_def_id, args: args.value, nested: impl_obligations }
485 }
486
487 fn confirm_object_candidate(
488 &mut self,
489 obligation: &PolyTraitObligation<'tcx>,
490 index: usize,
491 ) -> Result<ImplSource<'tcx, PredicateObligation<'tcx>>, SelectionError<'tcx>> {
492 let tcx = self.tcx();
493 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:493",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(493u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::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("index")
}> =
::tracing::__macro_support::FieldName::new("index");
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_object_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(&index)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?obligation, ?index, "confirm_object_candidate");
494
495 let trait_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
496 let self_ty = self.infcx.shallow_resolve(trait_predicate.self_ty());
497 let ty::Dynamic(data, ..) = *self_ty.kind() else {
498 ::rustc_middle::util::bug::span_bug_fmt(obligation.cause.span,
format_args!("object candidate with non-object"));span_bug!(obligation.cause.span, "object candidate with non-object");
499 };
500
501 let object_trait_ref = data.principal().unwrap_or_else(|| {
502 ::rustc_middle::util::bug::span_bug_fmt(obligation.cause.span,
format_args!("object candidate with no principal"))span_bug!(obligation.cause.span, "object candidate with no principal")
503 });
504 let object_trait_ref = self.infcx.instantiate_binder_with_fresh_vars(
505 obligation.cause.span,
506 BoundRegionConversionTime::HigherRankedType,
507 object_trait_ref,
508 );
509 let object_trait_ref = object_trait_ref.with_self_ty(self.tcx(), self_ty);
510
511 let mut nested = PredicateObligations::new();
512
513 let mut supertraits = util::supertraits(tcx, ty::Binder::dummy(object_trait_ref));
514 let unnormalized_upcast_trait_ref =
515 supertraits.nth(index).expect("supertraits iterator no longer has as many elements");
516
517 let upcast_trait_ref = self.infcx.instantiate_binder_with_fresh_vars(
518 obligation.cause.span,
519 BoundRegionConversionTime::HigherRankedType,
520 unnormalized_upcast_trait_ref,
521 );
522 let upcast_trait_ref = normalize_with_depth_to(
523 self,
524 obligation.param_env,
525 obligation.cause.clone(),
526 obligation.recursion_depth + 1,
527 ty::Unnormalized::new_wip(upcast_trait_ref),
528 &mut nested,
529 );
530
531 nested.extend(
532 self.infcx
533 .at(&obligation.cause, obligation.param_env)
534 .eq(DefineOpaqueTypes::No, trait_predicate.trait_ref, upcast_trait_ref)
535 .map(|InferOk { obligations, .. }| obligations)
536 .map_err(|_| SelectionError::Unimplemented)?,
537 );
538
539 for supertrait in tcx
542 .explicit_super_clauses_of(trait_predicate.def_id())
543 .iter_instantiated_copied(tcx, trait_predicate.trait_ref.args)
544 .map(|clause| clause.unzip().0)
545 {
546 let normalized_supertrait = normalize_with_depth_to(
547 self,
548 obligation.param_env,
549 obligation.cause.clone(),
550 obligation.recursion_depth + 1,
551 supertrait,
552 &mut nested,
553 );
554 nested.push(obligation.with(tcx, normalized_supertrait));
555 }
556
557 let assoc_types: Vec<_> = tcx
558 .associated_items(trait_predicate.def_id())
559 .in_definition_order()
560 .filter(|item| !tcx.generics_require_sized_self(item.def_id))
563 .filter_map(|item| if item.is_type() { Some(item.def_id) } else { None })
564 .collect();
565
566 for assoc_type in assoc_types {
567 let defs: &ty::Generics = tcx.generics_of(assoc_type);
568
569 if !defs.own_params.is_empty() {
570 tcx.dcx().span_delayed_bug(
571 obligation.cause.span,
572 "GATs in trait object shouldn't have been considered",
573 );
574 return Err(SelectionError::TraitDynIncompatible(trait_predicate.trait_ref.def_id));
575 }
576
577 for bound in self.tcx().item_bounds(assoc_type).transpose_iter() {
581 let normalized_bound = normalize_with_depth_to(
582 self,
583 obligation.param_env,
584 obligation.cause.clone(),
585 obligation.recursion_depth + 1,
586 bound.instantiate(tcx, trait_predicate.trait_ref.args),
587 &mut nested,
588 );
589 nested.push(obligation.with(tcx, normalized_bound));
590 }
591 }
592
593 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:593",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(593u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("nested")
}> =
::tracing::__macro_support::FieldName::new("nested");
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!("object nested obligations")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&nested)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?nested, "object nested obligations");
594
595 Ok(ImplSource::Builtin(BuiltinImplSource::Object(index), nested))
596 }
597
598 fn confirm_fn_pointer_candidate(
599 &mut self,
600 obligation: &PolyTraitObligation<'tcx>,
601 ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
602 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:602",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(602u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::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()
}], ::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_fn_pointer_candidate")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?obligation, "confirm_fn_pointer_candidate");
603 let placeholder_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
604 let self_ty = self.infcx.shallow_resolve(placeholder_predicate.self_ty());
605
606 let tcx = self.tcx();
607 let sig = self_ty.unnormalized_fn_sig(tcx);
608 let output_ty = sig.map(|sig| self.infcx.enter_forall_and_leak_universe(sig.output()));
609 let sig = sig.skip_norm_wip();
610 let trait_ref = closure_trait_ref_and_return_type(
611 tcx,
612 obligation.predicate.def_id(),
613 self_ty,
614 sig,
615 util::TupleArgumentsFlag::Yes,
616 )
617 .map_bound(|(trait_ref, _)| trait_ref);
618
619 let mut nested =
620 self.equate_trait_refs(obligation.with(tcx, placeholder_predicate), trait_ref)?;
621 let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerived);
622
623 let output_ty = normalize_with_depth_to(
625 self,
626 obligation.param_env,
627 cause.clone(),
628 obligation.recursion_depth,
629 output_ty,
630 &mut nested,
631 );
632 let tr = ty::TraitRef::new(
633 self.tcx(),
634 self.tcx().require_lang_item(LangItem::Sized, cause.span),
635 [output_ty],
636 );
637 nested.push(Obligation::new(self.infcx.tcx, cause, obligation.param_env, tr));
638
639 Ok(nested)
640 }
641
642 fn confirm_trait_alias_candidate(
643 &mut self,
644 obligation: &PolyTraitObligation<'tcx>,
645 ) -> PredicateObligations<'tcx> {
646 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:646",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(646u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::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()
}], ::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_trait_alias_candidate")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?obligation, "confirm_trait_alias_candidate");
647
648 let predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
649 let trait_ref = predicate.trait_ref;
650 let trait_def_id = trait_ref.def_id;
651 let args = trait_ref.args;
652
653 let trait_obligations = self.impl_or_trait_obligations(
654 &obligation.cause,
655 obligation.recursion_depth,
656 obligation.param_env,
657 trait_def_id,
658 args,
659 obligation.predicate,
660 );
661
662 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:662",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(662u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("trait_def_id")
}> =
::tracing::__macro_support::FieldName::new("trait_def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("trait_obligations")
}> =
::tracing::__macro_support::FieldName::new("trait_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!("trait alias obligations")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_obligations)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?trait_def_id, ?trait_obligations, "trait alias obligations");
663
664 trait_obligations
665 }
666
667 fn confirm_coroutine_candidate(
668 &mut self,
669 obligation: &PolyTraitObligation<'tcx>,
670 ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
671 let placeholder_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
672 let self_ty = self.infcx.shallow_resolve(placeholder_predicate.self_ty());
673 let ty::Coroutine(coroutine_def_id, args) = *self_ty.kind() else {
674 ::rustc_middle::util::bug::bug_fmt(format_args!("closure candidate for non-closure {0:?}",
obligation));bug!("closure candidate for non-closure {:?}", obligation);
675 };
676
677 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:677",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(677u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::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_def_id")
}> =
::tracing::__macro_support::FieldName::new("coroutine_def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("args")
}> =
::tracing::__macro_support::FieldName::new("args");
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_def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?obligation, ?coroutine_def_id, ?args, "confirm_coroutine_candidate");
678
679 let coroutine_sig = args.as_coroutine().sig();
680
681 let (trait_ref, _, _) = super::util::coroutine_trait_ref_and_outputs(
682 self.tcx(),
683 obligation.predicate.def_id(),
684 self_ty,
685 coroutine_sig,
686 );
687
688 let nested = self.equate_trait_refs(
689 obligation.with(self.tcx(), placeholder_predicate),
690 ty::Binder::dummy(trait_ref),
691 )?;
692 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:692",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(692u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("trait_ref")
}> =
::tracing::__macro_support::FieldName::new("trait_ref");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("nested")
}> =
::tracing::__macro_support::FieldName::new("nested");
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!("coroutine candidate obligations")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_ref)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&nested)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?trait_ref, ?nested, "coroutine candidate obligations");
693
694 Ok(nested)
695 }
696
697 fn confirm_future_candidate(
698 &mut self,
699 obligation: &PolyTraitObligation<'tcx>,
700 ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
701 let placeholder_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
702 let self_ty = self.infcx.shallow_resolve(placeholder_predicate.self_ty());
703 let ty::Coroutine(coroutine_def_id, args) = *self_ty.kind() else {
704 ::rustc_middle::util::bug::bug_fmt(format_args!("closure candidate for non-closure {0:?}",
obligation));bug!("closure candidate for non-closure {:?}", obligation);
705 };
706
707 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:707",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(707u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::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_def_id")
}> =
::tracing::__macro_support::FieldName::new("coroutine_def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("args")
}> =
::tracing::__macro_support::FieldName::new("args");
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_def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?obligation, ?coroutine_def_id, ?args, "confirm_future_candidate");
708
709 let coroutine_sig = args.as_coroutine().sig();
710
711 let (trait_ref, _) = super::util::future_trait_ref_and_outputs(
712 self.tcx(),
713 obligation.predicate.def_id(),
714 self_ty,
715 coroutine_sig,
716 );
717
718 let nested = self.equate_trait_refs(
719 obligation.with(self.tcx(), placeholder_predicate),
720 ty::Binder::dummy(trait_ref),
721 )?;
722 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:722",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(722u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("trait_ref")
}> =
::tracing::__macro_support::FieldName::new("trait_ref");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("nested")
}> =
::tracing::__macro_support::FieldName::new("nested");
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!("future candidate obligations")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_ref)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&nested)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?trait_ref, ?nested, "future candidate obligations");
723
724 Ok(nested)
725 }
726
727 fn confirm_iterator_candidate(
728 &mut self,
729 obligation: &PolyTraitObligation<'tcx>,
730 ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
731 let placeholder_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
732 let self_ty = self.infcx.shallow_resolve(placeholder_predicate.self_ty());
733 let ty::Coroutine(coroutine_def_id, args) = *self_ty.kind() else {
734 ::rustc_middle::util::bug::bug_fmt(format_args!("closure candidate for non-closure {0:?}",
obligation));bug!("closure candidate for non-closure {:?}", obligation);
735 };
736
737 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:737",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(737u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::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_def_id")
}> =
::tracing::__macro_support::FieldName::new("coroutine_def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("args")
}> =
::tracing::__macro_support::FieldName::new("args");
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(&coroutine_def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?obligation, ?coroutine_def_id, ?args, "confirm_iterator_candidate");
738
739 let gen_sig = args.as_coroutine().sig();
740
741 let (trait_ref, _) = super::util::iterator_trait_ref_and_outputs(
742 self.tcx(),
743 obligation.predicate.def_id(),
744 self_ty,
745 gen_sig,
746 );
747
748 let nested = self.equate_trait_refs(
749 obligation.with(self.tcx(), placeholder_predicate),
750 ty::Binder::dummy(trait_ref),
751 )?;
752 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:752",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(752u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("trait_ref")
}> =
::tracing::__macro_support::FieldName::new("trait_ref");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("nested")
}> =
::tracing::__macro_support::FieldName::new("nested");
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!("iterator candidate obligations")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_ref)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&nested)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?trait_ref, ?nested, "iterator candidate obligations");
753
754 Ok(nested)
755 }
756
757 fn confirm_async_iterator_candidate(
758 &mut self,
759 obligation: &PolyTraitObligation<'tcx>,
760 ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
761 let placeholder_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
762 let self_ty = self.infcx.shallow_resolve(placeholder_predicate.self_ty());
763 let ty::Coroutine(coroutine_def_id, args) = *self_ty.kind() else {
764 ::rustc_middle::util::bug::bug_fmt(format_args!("closure candidate for non-closure {0:?}",
obligation));bug!("closure candidate for non-closure {:?}", obligation);
765 };
766
767 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:767",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(767u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::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_def_id")
}> =
::tracing::__macro_support::FieldName::new("coroutine_def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("args")
}> =
::tracing::__macro_support::FieldName::new("args");
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(&coroutine_def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?obligation, ?coroutine_def_id, ?args, "confirm_async_iterator_candidate");
768
769 let gen_sig = args.as_coroutine().sig();
770
771 let (trait_ref, _) = super::util::async_iterator_trait_ref_and_outputs(
772 self.tcx(),
773 obligation.predicate.def_id(),
774 self_ty,
775 gen_sig,
776 );
777
778 let nested = self.equate_trait_refs(
779 obligation.with(self.tcx(), placeholder_predicate),
780 ty::Binder::dummy(trait_ref),
781 )?;
782 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:782",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(782u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("trait_ref")
}> =
::tracing::__macro_support::FieldName::new("trait_ref");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("nested")
}> =
::tracing::__macro_support::FieldName::new("nested");
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!("iterator candidate obligations")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_ref)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&nested)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?trait_ref, ?nested, "iterator candidate obligations");
783
784 Ok(nested)
785 }
786
787 #[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("confirm_closure_candidate",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(787u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::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:
Result<PredicateObligations<'tcx>, SelectionError<'tcx>> =
loop {};
return __tracing_attr_fake_return;
}
{
let placeholder_predicate =
self.infcx.enter_forall_and_leak_universe(obligation.predicate);
let self_ty: Ty<'_> =
self.infcx.shallow_resolve(placeholder_predicate.self_ty());
let trait_ref =
match *self_ty.kind() {
ty::Closure(..) => {
self.closure_trait_ref_unnormalized(self_ty,
obligation.predicate.def_id())
}
ty::CoroutineClosure(_, args) => {
args.as_coroutine_closure().coroutine_closure_sig().map_bound(|sig|
{
ty::TraitRef::new(self.tcx(), obligation.predicate.def_id(),
[self_ty, sig.tupled_inputs_ty])
})
}
_ => {
::rustc_middle::util::bug::bug_fmt(format_args!("closure candidate for non-closure {0:?}",
obligation));
}
};
self.equate_trait_refs(obligation.with(self.tcx(),
placeholder_predicate), trait_ref)
}
}
}#[instrument(skip(self), level = "debug")]
788 fn confirm_closure_candidate(
789 &mut self,
790 obligation: &PolyTraitObligation<'tcx>,
791 ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
792 let placeholder_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
793 let self_ty: Ty<'_> = self.infcx.shallow_resolve(placeholder_predicate.self_ty());
794
795 let trait_ref = match *self_ty.kind() {
796 ty::Closure(..) => {
797 self.closure_trait_ref_unnormalized(self_ty, obligation.predicate.def_id())
798 }
799 ty::CoroutineClosure(_, args) => {
800 args.as_coroutine_closure().coroutine_closure_sig().map_bound(|sig| {
801 ty::TraitRef::new(
802 self.tcx(),
803 obligation.predicate.def_id(),
804 [self_ty, sig.tupled_inputs_ty],
805 )
806 })
807 }
808 _ => {
809 bug!("closure candidate for non-closure {:?}", obligation);
810 }
811 };
812
813 self.equate_trait_refs(obligation.with(self.tcx(), placeholder_predicate), trait_ref)
814 }
815
816 #[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("confirm_async_closure_candidate",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(816u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::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:
Result<PredicateObligations<'tcx>, SelectionError<'tcx>> =
loop {};
return __tracing_attr_fake_return;
}
{
let placeholder_predicate =
self.infcx.enter_forall_and_leak_universe(obligation.predicate);
let self_ty =
self.infcx.shallow_resolve(placeholder_predicate.self_ty());
let tcx = self.tcx();
let mut nested = PredicateObligations::new();
let (trait_ref, kind_ty) =
match *self_ty.kind() {
ty::CoroutineClosure(_, args) => {
let args = args.as_coroutine_closure();
let trait_ref =
args.coroutine_closure_sig().map_bound(|sig|
{
ty::TraitRef::new(self.tcx(), obligation.predicate.def_id(),
[self_ty, sig.tupled_inputs_ty])
});
(trait_ref, args.kind_ty())
}
ty::FnDef(..) | ty::FnPtr(..) => {
let sig = self_ty.fn_sig(tcx);
let trait_ref =
sig.map_bound(|sig|
{
ty::TraitRef::new(self.tcx(), obligation.predicate.def_id(),
[self_ty, Ty::new_tup(tcx, sig.inputs())])
});
let future_trait_def_id =
tcx.require_lang_item(LangItem::Future,
obligation.cause.span);
nested.push(obligation.with(tcx,
sig.output().map_bound(|output_ty|
{
ty::TraitRef::new(tcx, future_trait_def_id, [output_ty])
})));
let sized_trait_def_id =
tcx.require_lang_item(LangItem::Sized,
obligation.cause.span);
nested.push(obligation.with(tcx,
sig.output().map_bound(|output_ty|
{
ty::TraitRef::new(tcx, sized_trait_def_id, [output_ty])
})));
(trait_ref, Ty::from_closure_kind(tcx, ty::ClosureKind::Fn))
}
ty::Closure(_, args) => {
let args = args.as_closure();
let sig = args.sig();
let trait_ref =
sig.map_bound(|sig|
{
ty::TraitRef::new(self.tcx(), obligation.predicate.def_id(),
[self_ty, sig.inputs()[0]])
});
let future_trait_def_id =
tcx.require_lang_item(LangItem::Future,
obligation.cause.span);
let placeholder_output_ty =
self.infcx.enter_forall_and_leak_universe(sig.output());
nested.push(obligation.with(tcx,
ty::TraitRef::new(tcx, future_trait_def_id,
[placeholder_output_ty])));
let sized_trait_def_id =
tcx.require_lang_item(LangItem::Sized,
obligation.cause.span);
nested.push(obligation.with(tcx,
sig.output().map_bound(|output_ty|
{
ty::TraitRef::new(tcx, sized_trait_def_id, [output_ty])
})));
(trait_ref, args.kind_ty())
}
_ =>
::rustc_middle::util::bug::bug_fmt(format_args!("expected callable type for AsyncFn candidate")),
};
nested.extend(self.equate_trait_refs(obligation.with(tcx,
placeholder_predicate), trait_ref)?);
let goal_kind =
self.tcx().async_fn_trait_kind_from_def_id(obligation.predicate.def_id()).unwrap();
if let Some(closure_kind) =
self.infcx.shallow_resolve(kind_ty).to_opt_closure_kind() {
if !closure_kind.extends(goal_kind) {
return Err(SelectionError::Unimplemented);
}
} else {
nested.push(Obligation::new(self.tcx(),
obligation.derived_cause(ObligationCauseCode::BuiltinDerived),
obligation.param_env,
ty::TraitRef::new(self.tcx(),
self.tcx().require_lang_item(LangItem::AsyncFnKindHelper,
obligation.cause.span),
[kind_ty, Ty::from_closure_kind(self.tcx(), goal_kind)])));
}
Ok(nested)
}
}
}#[instrument(skip(self), level = "debug")]
817 fn confirm_async_closure_candidate(
818 &mut self,
819 obligation: &PolyTraitObligation<'tcx>,
820 ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
821 let placeholder_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
822 let self_ty = self.infcx.shallow_resolve(placeholder_predicate.self_ty());
823
824 let tcx = self.tcx();
825
826 let mut nested = PredicateObligations::new();
827 let (trait_ref, kind_ty) = match *self_ty.kind() {
828 ty::CoroutineClosure(_, args) => {
829 let args = args.as_coroutine_closure();
830 let trait_ref = args.coroutine_closure_sig().map_bound(|sig| {
831 ty::TraitRef::new(
832 self.tcx(),
833 obligation.predicate.def_id(),
834 [self_ty, sig.tupled_inputs_ty],
835 )
836 });
837
838 (trait_ref, args.kind_ty())
842 }
843 ty::FnDef(..) | ty::FnPtr(..) => {
844 let sig = self_ty.fn_sig(tcx);
845 let trait_ref = sig.map_bound(|sig| {
846 ty::TraitRef::new(
847 self.tcx(),
848 obligation.predicate.def_id(),
849 [self_ty, Ty::new_tup(tcx, sig.inputs())],
850 )
851 });
852
853 let future_trait_def_id =
855 tcx.require_lang_item(LangItem::Future, obligation.cause.span);
856 nested.push(obligation.with(
857 tcx,
858 sig.output().map_bound(|output_ty| {
859 ty::TraitRef::new(tcx, future_trait_def_id, [output_ty])
860 }),
861 ));
862 let sized_trait_def_id =
863 tcx.require_lang_item(LangItem::Sized, obligation.cause.span);
864 nested.push(obligation.with(
865 tcx,
866 sig.output().map_bound(|output_ty| {
867 ty::TraitRef::new(tcx, sized_trait_def_id, [output_ty])
868 }),
869 ));
870
871 (trait_ref, Ty::from_closure_kind(tcx, ty::ClosureKind::Fn))
872 }
873 ty::Closure(_, args) => {
874 let args = args.as_closure();
875 let sig = args.sig();
876 let trait_ref = sig.map_bound(|sig| {
877 ty::TraitRef::new(
878 self.tcx(),
879 obligation.predicate.def_id(),
880 [self_ty, sig.inputs()[0]],
881 )
882 });
883
884 let future_trait_def_id =
886 tcx.require_lang_item(LangItem::Future, obligation.cause.span);
887 let placeholder_output_ty = self.infcx.enter_forall_and_leak_universe(sig.output());
888 nested.push(obligation.with(
889 tcx,
890 ty::TraitRef::new(tcx, future_trait_def_id, [placeholder_output_ty]),
891 ));
892 let sized_trait_def_id =
893 tcx.require_lang_item(LangItem::Sized, obligation.cause.span);
894 nested.push(obligation.with(
895 tcx,
896 sig.output().map_bound(|output_ty| {
897 ty::TraitRef::new(tcx, sized_trait_def_id, [output_ty])
898 }),
899 ));
900
901 (trait_ref, args.kind_ty())
902 }
903 _ => bug!("expected callable type for AsyncFn candidate"),
904 };
905
906 nested.extend(
907 self.equate_trait_refs(obligation.with(tcx, placeholder_predicate), trait_ref)?,
908 );
909
910 let goal_kind =
911 self.tcx().async_fn_trait_kind_from_def_id(obligation.predicate.def_id()).unwrap();
912
913 if let Some(closure_kind) = self.infcx.shallow_resolve(kind_ty).to_opt_closure_kind() {
917 if !closure_kind.extends(goal_kind) {
918 return Err(SelectionError::Unimplemented);
919 }
920 } else {
921 nested.push(Obligation::new(
922 self.tcx(),
923 obligation.derived_cause(ObligationCauseCode::BuiltinDerived),
924 obligation.param_env,
925 ty::TraitRef::new(
926 self.tcx(),
927 self.tcx()
928 .require_lang_item(LangItem::AsyncFnKindHelper, obligation.cause.span),
929 [kind_ty, Ty::from_closure_kind(self.tcx(), goal_kind)],
930 ),
931 ));
932 }
933
934 Ok(nested)
935 }
936
937 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("equate_trait_refs",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(962u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::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()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("found_trait_ref")
}> =
::tracing::__macro_support::FieldName::new("found_trait_ref");
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::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[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)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&found_trait_ref)
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<PredicateObligations<'tcx>, SelectionError<'tcx>> =
loop {};
return __tracing_attr_fake_return;
}
{
let found_trait_ref =
self.infcx.instantiate_binder_with_fresh_vars(obligation.cause.span,
BoundRegionConversionTime::HigherRankedType,
found_trait_ref);
let Normalized {
obligations: nested,
value: (obligation_trait_ref, found_trait_ref) } =
ensure_sufficient_stack(||
{
normalize_with_depth(self, obligation.param_env,
obligation.cause.clone(), obligation.recursion_depth + 1,
Unnormalized::new_wip((obligation.predicate.trait_ref,
found_trait_ref)))
});
self.infcx.at(&obligation.cause,
obligation.param_env).eq(DefineOpaqueTypes::Yes,
obligation_trait_ref,
found_trait_ref).map(|InferOk { mut obligations, .. }|
{
obligations.extend(nested);
obligations
}).map_err(|terr|
{
SelectionError::SignatureMismatch(Box::new(SignatureMismatchData {
expected_trait_ref: obligation_trait_ref,
found_trait_ref,
terr,
}))
})
}
}
}#[instrument(skip(self), level = "trace")]
963 fn equate_trait_refs(
964 &mut self,
965 obligation: TraitObligation<'tcx>,
966 found_trait_ref: ty::PolyTraitRef<'tcx>,
967 ) -> Result<PredicateObligations<'tcx>, SelectionError<'tcx>> {
968 let found_trait_ref = self.infcx.instantiate_binder_with_fresh_vars(
969 obligation.cause.span,
970 BoundRegionConversionTime::HigherRankedType,
971 found_trait_ref,
972 );
973 let Normalized { obligations: nested, value: (obligation_trait_ref, found_trait_ref) } =
975 ensure_sufficient_stack(|| {
976 normalize_with_depth(
977 self,
978 obligation.param_env,
979 obligation.cause.clone(),
980 obligation.recursion_depth + 1,
981 Unnormalized::new_wip((obligation.predicate.trait_ref, found_trait_ref)),
982 )
983 });
984
985 self.infcx
987 .at(&obligation.cause, obligation.param_env)
988 .eq(DefineOpaqueTypes::Yes, obligation_trait_ref, found_trait_ref)
989 .map(|InferOk { mut obligations, .. }| {
990 obligations.extend(nested);
991 obligations
992 })
993 .map_err(|terr| {
994 SelectionError::SignatureMismatch(Box::new(SignatureMismatchData {
995 expected_trait_ref: obligation_trait_ref,
996 found_trait_ref,
997 terr,
998 }))
999 })
1000 }
1001
1002 fn confirm_trait_upcasting_unsize_candidate(
1003 &mut self,
1004 obligation: &PolyTraitObligation<'tcx>,
1005 idx: usize,
1006 ) -> Result<ImplSource<'tcx, PredicateObligation<'tcx>>, SelectionError<'tcx>> {
1007 let tcx = self.tcx();
1008
1009 let predicate = obligation.predicate.no_bound_vars().unwrap();
1012 let a_ty = self.infcx.shallow_resolve(predicate.self_ty());
1013 let b_ty = self.infcx.shallow_resolve(predicate.trait_ref.args.type_at(1));
1014
1015 let ty::Dynamic(a_data, a_region) = *a_ty.kind() else {
1016 ::rustc_middle::util::bug::bug_fmt(format_args!("expected `dyn` type in `confirm_trait_upcasting_unsize_candidate`"))bug!("expected `dyn` type in `confirm_trait_upcasting_unsize_candidate`")
1017 };
1018 let ty::Dynamic(b_data, b_region) = *b_ty.kind() else {
1019 ::rustc_middle::util::bug::bug_fmt(format_args!("expected `dyn` type in `confirm_trait_upcasting_unsize_candidate`"))bug!("expected `dyn` type in `confirm_trait_upcasting_unsize_candidate`")
1020 };
1021
1022 let source_principal = a_data.principal().unwrap().with_self_ty(tcx, a_ty);
1023 let unnormalized_upcast_principal =
1024 ty::Unnormalized::new_wip(util::supertraits(tcx, source_principal).nth(idx).unwrap());
1025
1026 let nested = self
1027 .match_upcast_principal(
1028 obligation,
1029 unnormalized_upcast_principal,
1030 a_data,
1031 b_data,
1032 a_region,
1033 b_region,
1034 )?
1035 .expect("did not expect ambiguity during confirmation");
1036
1037 Ok(ImplSource::Builtin(BuiltinImplSource::TraitUpcasting(idx), nested))
1038 }
1039
1040 fn confirm_builtin_unsize_candidate(
1041 &mut self,
1042 obligation: &PolyTraitObligation<'tcx>,
1043 ) -> Result<ImplSource<'tcx, PredicateObligation<'tcx>>, SelectionError<'tcx>> {
1044 let tcx = self.tcx();
1045
1046 let source = self.infcx.shallow_resolve(obligation.self_ty().no_bound_vars().unwrap());
1049 let target = obligation.predicate.skip_binder().trait_ref.args.type_at(1);
1050 let target = self.infcx.shallow_resolve(target);
1051 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/confirmation.rs:1051",
"rustc_trait_selection::traits::select::confirmation",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/confirmation.rs"),
::tracing_core::__macro_support::Option::Some(1051u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::confirmation"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("source")
}> =
::tracing::__macro_support::FieldName::new("source");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("target")
}> =
::tracing::__macro_support::FieldName::new("target");
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_builtin_unsize_candidate")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&target)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?source, ?target, "confirm_builtin_unsize_candidate");
1052
1053 Ok(match (source.kind(), target.kind()) {
1054 (&ty::Dynamic(data_a, r_a), &ty::Dynamic(data_b, r_b)) => {
1056 let existential_predicates = if data_b.principal().is_some() {
1059 tcx.mk_poly_existential_predicates_from_iter(
1060 data_a
1061 .principal()
1062 .map(|b| b.map_bound(ty::ExistentialPredicate::Trait))
1063 .into_iter()
1064 .chain(
1065 data_a
1066 .projection_bounds()
1067 .map(|b| b.map_bound(ty::ExistentialPredicate::Projection)),
1068 )
1069 .chain(
1070 data_b
1071 .auto_traits()
1072 .map(ty::ExistentialPredicate::AutoTrait)
1073 .map(ty::Binder::dummy),
1074 ),
1075 )
1076 } else {
1077 tcx.mk_poly_existential_predicates_from_iter(
1082 data_b
1083 .auto_traits()
1084 .map(ty::ExistentialPredicate::AutoTrait)
1085 .map(ty::Binder::dummy),
1086 )
1087 };
1088 let source_trait = Ty::new_dynamic(tcx, existential_predicates, r_b);
1089
1090 let InferOk { mut obligations, .. } = self
1093 .infcx
1094 .at(&obligation.cause, obligation.param_env)
1095 .sup(DefineOpaqueTypes::Yes, target, source_trait)
1096 .map_err(|_| SelectionError::Unimplemented)?;
1097
1098 let outlives = ty::OutlivesPredicate(r_a, r_b);
1100 obligations.push(Obligation::with_depth(
1101 tcx,
1102 obligation.cause.clone(),
1103 obligation.recursion_depth + 1,
1104 obligation.param_env,
1105 obligation.predicate.rebind(outlives),
1106 ));
1107
1108 ImplSource::Builtin(BuiltinImplSource::Misc, obligations)
1109 }
1110
1111 (_, &ty::Dynamic(data, r)) => {
1113 let mut object_dids = data.auto_traits().chain(data.principal_def_id());
1114 if let Some(did) = object_dids.find(|did| !tcx.is_dyn_compatible(*did)) {
1115 return Err(SelectionError::TraitDynIncompatible(did));
1116 }
1117
1118 let predicate_to_obligation = |predicate| {
1119 Obligation::with_depth(
1120 tcx,
1121 obligation.cause.clone(),
1122 obligation.recursion_depth + 1,
1123 obligation.param_env,
1124 predicate,
1125 )
1126 };
1127
1128 let mut nested: PredicateObligations<'_> = data
1135 .iter()
1136 .map(|predicate| predicate_to_obligation(predicate.with_self_ty(tcx, source)))
1137 .collect();
1138
1139 let tr = ty::TraitRef::new(
1141 tcx,
1142 tcx.require_lang_item(LangItem::Sized, obligation.cause.span),
1143 [source],
1144 );
1145 nested.push(predicate_to_obligation(tr.upcast(tcx)));
1146
1147 let outlives = ty::OutlivesPredicate(source, r);
1150 nested.push(predicate_to_obligation(
1151 ty::ClauseKind::TypeOutlives(outlives).upcast(tcx),
1152 ));
1153
1154 ImplSource::Builtin(BuiltinImplSource::Misc, nested)
1155 }
1156
1157 (&ty::Array(a, _), &ty::Slice(b)) => {
1159 let InferOk { obligations, .. } = self
1160 .infcx
1161 .at(&obligation.cause, obligation.param_env)
1162 .eq(DefineOpaqueTypes::Yes, b, a)
1163 .map_err(|_| SelectionError::Unimplemented)?;
1164
1165 ImplSource::Builtin(BuiltinImplSource::Misc, obligations)
1166 }
1167
1168 (&ty::Adt(def, args_a), &ty::Adt(_, args_b)) => {
1170 let unsizing_params = tcx.unsizing_params_for_adt(def.did());
1171 if unsizing_params.is_empty() {
1172 return Err(SelectionError::Unimplemented);
1173 }
1174
1175 let tail_field = def.non_enum_variant().tail();
1176 let tail_field_ty = tcx.type_of(tail_field.did);
1177
1178 let mut nested = PredicateObligations::new();
1179
1180 let source_tail = normalize_with_depth_to(
1184 self,
1185 obligation.param_env,
1186 obligation.cause.clone(),
1187 obligation.recursion_depth + 1,
1188 tail_field_ty.instantiate(tcx, args_a),
1189 &mut nested,
1190 );
1191 let target_tail = normalize_with_depth_to(
1192 self,
1193 obligation.param_env,
1194 obligation.cause.clone(),
1195 obligation.recursion_depth + 1,
1196 tail_field_ty.instantiate(tcx, args_b),
1197 &mut nested,
1198 );
1199
1200 let args =
1203 tcx.mk_args_from_iter(args_a.iter().enumerate().map(|(i, k)| {
1204 if unsizing_params.contains(i as u32) { args_b[i] } else { k }
1205 }));
1206 let new_struct = Ty::new_adt(tcx, def, args);
1207 let InferOk { obligations, .. } = self
1208 .infcx
1209 .at(&obligation.cause, obligation.param_env)
1210 .eq(DefineOpaqueTypes::Yes, target, new_struct)
1211 .map_err(|_| SelectionError::Unimplemented)?;
1212 nested.extend(obligations);
1213
1214 let tail_unsize_obligation = obligation.with(
1216 tcx,
1217 ty::TraitRef::new(
1218 tcx,
1219 obligation.predicate.def_id(),
1220 [source_tail, target_tail],
1221 ),
1222 );
1223 nested.push(tail_unsize_obligation);
1224
1225 ImplSource::Builtin(BuiltinImplSource::Misc, nested)
1226 }
1227
1228 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("source: {0}, target: {1}",
source, target))bug!("source: {source}, target: {target}"),
1229 })
1230 }
1231
1232 fn confirm_bikeshed_guaranteed_no_drop_candidate(
1235 &mut self,
1236 obligation: &PolyTraitObligation<'tcx>,
1237 ) -> ImplSource<'tcx, PredicateObligation<'tcx>> {
1238 let mut obligations = ::thin_vec::ThinVec::new()thin_vec![];
1239
1240 let tcx = self.tcx();
1241 let self_ty = obligation.predicate.self_ty();
1242 match *self_ty.skip_binder().kind() {
1243 ty::Ref(..) => {}
1245 ty::Adt(def, _) if def.is_manually_drop() => {}
1247 ty::Tuple(tys) => {
1250 obligations.extend(tys.iter().map(|elem_ty| {
1251 obligation.with(
1252 tcx,
1253 self_ty.rebind(ty::TraitRef::new(
1254 tcx,
1255 obligation.predicate.def_id(),
1256 [elem_ty],
1257 )),
1258 )
1259 }));
1260 }
1261 ty::Array(elem_ty, _) => {
1262 obligations.push(obligation.with(
1263 tcx,
1264 self_ty.rebind(ty::TraitRef::new(
1265 tcx,
1266 obligation.predicate.def_id(),
1267 [elem_ty],
1268 )),
1269 ));
1270 }
1271
1272 ty::FnDef(..)
1276 | ty::FnPtr(..)
1277 | ty::Error(_)
1278 | ty::Uint(_)
1279 | ty::Int(_)
1280 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
1281 | ty::Bool
1282 | ty::Float(_)
1283 | ty::Char
1284 | ty::RawPtr(..)
1285 | ty::Never
1286 | ty::Pat(..)
1287 | ty::Dynamic(..)
1288 | ty::Str
1289 | ty::Slice(_)
1290 | ty::Foreign(..)
1291 | ty::Adt(..)
1292 | ty::Alias(..)
1293 | ty::Param(_)
1294 | ty::Placeholder(..)
1295 | ty::Closure(..)
1296 | ty::CoroutineClosure(..)
1297 | ty::Coroutine(..)
1298 | ty::UnsafeBinder(_)
1299 | ty::CoroutineWitness(..)
1300 | ty::Bound(..) => {
1301 obligations.push(obligation.with(
1302 tcx,
1303 self_ty.map_bound(|ty| {
1304 ty::TraitRef::new(
1305 tcx,
1306 tcx.require_lang_item(LangItem::Copy, obligation.cause.span),
1307 [ty],
1308 )
1309 }),
1310 ));
1311 }
1312
1313 ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1314 {
::core::panicking::panic_fmt(format_args!("unexpected type `{0:?}`",
self_ty));
}panic!("unexpected type `{self_ty:?}`")
1315 }
1316 }
1317
1318 ImplSource::Builtin(BuiltinImplSource::Misc, obligations)
1319 }
1320
1321 fn confirm_try_as_dyn_candidate(
1322 &mut self,
1323 obligation: &PolyTraitObligation<'tcx>,
1324 ) -> ImplSource<'tcx, PredicateObligation<'tcx>> {
1325 let tcx = self.tcx();
1326
1327 let mut obligations = PredicateObligations::new();
1328
1329 let self_ty = obligation.predicate.self_ty();
1330 let ty_lifetime = obligation.predicate.map_bound(|p| p.trait_ref.args.region_at(1));
1331
1332 match *self_ty.skip_binder().kind() {
1333 ty::Dynamic(_bounds, lifetime) => {
1334 obligations.push(
1335 obligation.with(
1336 tcx,
1337 ty_lifetime
1338 .map_bound(|ty_lifetime| ty::OutlivesPredicate(ty_lifetime, lifetime)),
1339 ),
1340 );
1341 }
1342
1343 ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1344 {
::core::panicking::panic_fmt(format_args!("unexpected type `{0:?}`",
self_ty));
}panic!("unexpected type `{self_ty:?}`")
1345 }
1346
1347 _ => {}
1348 }
1349 ImplSource::Builtin(BuiltinImplSource::Misc, obligations)
1350 }
1351}