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