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