1use std::ops::ControlFlow;
10
11use hir::LangItem;
12use hir::def_id::DefId;
13use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
14use rustc_hir::{self as hir, CoroutineDesugaring, CoroutineKind};
15use rustc_infer::traits::{Obligation, PolyTraitObligation, PredicateObligation, SelectionError};
16use rustc_middle::ty::fast_reject::DeepRejectCtxt;
17use rustc_middle::ty::{
18 self, ExistentialPredicate, FieldInfo, SizedTraitKind, TraitRef, Ty, TypeVisitableExt,
19 elaborate,
20};
21use rustc_middle::{bug, span_bug};
22use rustc_span::DUMMY_SP;
23use tracing::{debug, instrument, trace};
24
25use super::SelectionCandidate::*;
26use super::{SelectionCandidateSet, SelectionContext, TraitObligationStack};
27use crate::traits::query::evaluate_obligation::InferCtxtExt;
28use crate::traits::util;
29
30impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
31 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_candidates",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(31u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{ meta.fields().value_set_all(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
Result<SelectionCandidateSet<'tcx>, SelectionError<'tcx>> =
loop {};
return __tracing_attr_fake_return;
}
{
let TraitObligationStack { obligation, .. } = *stack;
let obligation =
&Obligation {
param_env: obligation.param_env,
cause: obligation.cause.clone(),
recursion_depth: obligation.recursion_depth,
predicate: self.infcx.resolve_vars_if_possible(obligation.predicate),
};
if obligation.predicate.skip_binder().self_ty().is_ty_var() {
{
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/candidate_assembly.rs:45",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(45u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ty")
}> =
::tracing::__macro_support::FieldName::new("ty");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("ambiguous inference var or opaque type")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation.predicate.skip_binder().self_ty())
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
return Ok(SelectionCandidateSet {
vec: ::alloc::vec::Vec::new(),
ambiguous: true,
});
}
let mut candidates =
SelectionCandidateSet { vec: Vec::new(), ambiguous: false };
if obligation.polarity() == ty::PredicatePolarity::Negative {
self.assemble_candidates_for_trait_alias(obligation,
&mut candidates);
self.assemble_candidates_from_impls(obligation,
&mut candidates);
self.assemble_candidates_from_caller_bounds(stack,
&mut candidates)?;
} else {
self.assemble_candidates_for_trait_alias(obligation,
&mut candidates);
let def_id = obligation.predicate.def_id();
let tcx = self.tcx();
let lang_item = tcx.as_lang_item(def_id);
match lang_item {
Some(LangItem::Copy | LangItem::Clone |
LangItem::TrivialClone) => {
{
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/candidate_assembly.rs:76",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(76u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligation_self_ty")
}> =
::tracing::__macro_support::FieldName::new("obligation_self_ty");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation.predicate.skip_binder().self_ty())
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
self.assemble_candidates_from_impls(obligation,
&mut candidates);
self.assemble_builtin_copy_clone_candidate(obligation.predicate.self_ty().skip_binder(),
&mut candidates);
}
Some(LangItem::DiscriminantKind) => {
candidates.vec.push(BuiltinCandidate);
}
Some(LangItem::PointeeTrait) => {
candidates.vec.push(BuiltinCandidate);
}
Some(LangItem::Sized) => {
self.assemble_builtin_sized_candidate(obligation.predicate.self_ty().skip_binder(),
&mut candidates, SizedTraitKind::Sized);
}
Some(LangItem::MetaSized) => {
self.assemble_builtin_sized_candidate(obligation.predicate.self_ty().skip_binder(),
&mut candidates, SizedTraitKind::MetaSized);
}
Some(LangItem::PointeeSized) => {
::rustc_middle::util::bug::bug_fmt(format_args!("`PointeeSized` is removed during lowering"));
}
Some(LangItem::Unsize) => {
self.assemble_candidates_for_unsizing(obligation,
&mut candidates);
}
Some(LangItem::Destruct) => {
self.assemble_const_destruct_candidates(obligation,
&mut candidates);
}
Some(LangItem::TransmuteTrait) => {
self.assemble_candidates_from_impls(obligation,
&mut candidates);
self.assemble_candidates_for_transmutability(obligation,
&mut candidates);
}
Some(LangItem::Tuple) => {
self.assemble_candidate_for_tuple(obligation,
&mut candidates);
}
Some(LangItem::FnPtrTrait) => {
self.assemble_candidates_for_fn_ptr_trait(obligation,
&mut candidates);
}
Some(LangItem::BikeshedGuaranteedNoDrop) => {
self.assemble_candidates_for_bikeshed_guaranteed_no_drop_trait(obligation,
&mut candidates);
}
Some(LangItem::TryAsDyn) => {
self.assemble_candidates_for_try_as_dyn(obligation,
&mut candidates);
}
Some(LangItem::Field) => {
self.assemble_candidates_for_field_trait(obligation,
&mut candidates);
}
_ => {
match lang_item {
Some(LangItem::Coroutine) => {
self.assemble_coroutine_candidates(obligation,
&mut candidates);
}
Some(LangItem::Future) => {
self.assemble_future_candidates(obligation,
&mut candidates);
}
Some(LangItem::Iterator) => {
self.assemble_iterator_candidates(obligation,
&mut candidates);
}
Some(LangItem::FusedIterator) => {
self.assemble_fused_iterator_candidates(obligation,
&mut candidates);
}
Some(LangItem::AsyncIterator) => {
self.assemble_async_iterator_candidates(obligation,
&mut candidates);
}
Some(LangItem::AsyncFnKindHelper) => {
self.assemble_async_fn_kind_helper_candidates(obligation,
&mut candidates);
}
Some(LangItem::AsyncFn | LangItem::AsyncFnMut |
LangItem::AsyncFnOnce) => {
self.assemble_async_closure_candidates(obligation,
&mut candidates);
}
Some(LangItem::Fn | LangItem::FnMut | LangItem::FnOnce) => {
self.assemble_closure_candidates(obligation,
&mut candidates);
self.assemble_fn_pointer_candidates(obligation,
&mut candidates);
}
_ => {}
}
self.assemble_candidates_from_impls(obligation,
&mut candidates);
self.assemble_candidates_from_object_ty(obligation,
&mut candidates);
}
}
self.assemble_candidates_from_projected_tys(obligation,
&mut candidates);
self.assemble_candidates_from_caller_bounds(stack,
&mut candidates)?;
self.assemble_candidates_from_auto_impls(obligation,
&mut candidates);
}
{
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/candidate_assembly.rs:187",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(187u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("candidate list size: {0}",
candidates.vec.len()) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
Ok(candidates)
}
}
}#[instrument(skip(self, stack), level = "debug")]
32 pub(super) fn assemble_candidates<'o>(
33 &mut self,
34 stack: &TraitObligationStack<'o, 'tcx>,
35 ) -> Result<SelectionCandidateSet<'tcx>, SelectionError<'tcx>> {
36 let TraitObligationStack { obligation, .. } = *stack;
37 let obligation = &Obligation {
38 param_env: obligation.param_env,
39 cause: obligation.cause.clone(),
40 recursion_depth: obligation.recursion_depth,
41 predicate: self.infcx.resolve_vars_if_possible(obligation.predicate),
42 };
43
44 if obligation.predicate.skip_binder().self_ty().is_ty_var() {
45 debug!(ty = ?obligation.predicate.skip_binder().self_ty(), "ambiguous inference var or opaque type");
46 return Ok(SelectionCandidateSet { vec: vec![], ambiguous: true });
56 }
57
58 let mut candidates = SelectionCandidateSet { vec: Vec::new(), ambiguous: false };
59
60 if obligation.polarity() == ty::PredicatePolarity::Negative {
62 self.assemble_candidates_for_trait_alias(obligation, &mut candidates);
63 self.assemble_candidates_from_impls(obligation, &mut candidates);
64 self.assemble_candidates_from_caller_bounds(stack, &mut candidates)?;
65 } else {
66 self.assemble_candidates_for_trait_alias(obligation, &mut candidates);
67
68 let def_id = obligation.predicate.def_id();
71 let tcx = self.tcx();
72
73 let lang_item = tcx.as_lang_item(def_id);
74 match lang_item {
75 Some(LangItem::Copy | LangItem::Clone | LangItem::TrivialClone) => {
76 debug!(obligation_self_ty = ?obligation.predicate.skip_binder().self_ty());
77
78 self.assemble_candidates_from_impls(obligation, &mut candidates);
81
82 self.assemble_builtin_copy_clone_candidate(
84 obligation.predicate.self_ty().skip_binder(),
85 &mut candidates,
86 );
87 }
88 Some(LangItem::DiscriminantKind) => {
89 candidates.vec.push(BuiltinCandidate);
91 }
92 Some(LangItem::PointeeTrait) => {
93 candidates.vec.push(BuiltinCandidate);
95 }
96 Some(LangItem::Sized) => {
97 self.assemble_builtin_sized_candidate(
98 obligation.predicate.self_ty().skip_binder(),
99 &mut candidates,
100 SizedTraitKind::Sized,
101 );
102 }
103 Some(LangItem::MetaSized) => {
104 self.assemble_builtin_sized_candidate(
105 obligation.predicate.self_ty().skip_binder(),
106 &mut candidates,
107 SizedTraitKind::MetaSized,
108 );
109 }
110 Some(LangItem::PointeeSized) => {
111 bug!("`PointeeSized` is removed during lowering");
112 }
113 Some(LangItem::Unsize) => {
114 self.assemble_candidates_for_unsizing(obligation, &mut candidates);
115 }
116 Some(LangItem::Destruct) => {
117 self.assemble_const_destruct_candidates(obligation, &mut candidates);
118 }
119 Some(LangItem::TransmuteTrait) => {
120 self.assemble_candidates_from_impls(obligation, &mut candidates);
122 self.assemble_candidates_for_transmutability(obligation, &mut candidates);
123 }
124 Some(LangItem::Tuple) => {
125 self.assemble_candidate_for_tuple(obligation, &mut candidates);
126 }
127 Some(LangItem::FnPtrTrait) => {
128 self.assemble_candidates_for_fn_ptr_trait(obligation, &mut candidates);
129 }
130 Some(LangItem::BikeshedGuaranteedNoDrop) => {
131 self.assemble_candidates_for_bikeshed_guaranteed_no_drop_trait(
132 obligation,
133 &mut candidates,
134 );
135 }
136 Some(LangItem::TryAsDyn) => {
137 self.assemble_candidates_for_try_as_dyn(obligation, &mut candidates);
138 }
139 Some(LangItem::Field) => {
140 self.assemble_candidates_for_field_trait(obligation, &mut candidates);
141 }
142 _ => {
143 match lang_item {
147 Some(LangItem::Coroutine) => {
148 self.assemble_coroutine_candidates(obligation, &mut candidates);
149 }
150 Some(LangItem::Future) => {
151 self.assemble_future_candidates(obligation, &mut candidates);
152 }
153 Some(LangItem::Iterator) => {
154 self.assemble_iterator_candidates(obligation, &mut candidates);
155 }
156 Some(LangItem::FusedIterator) => {
157 self.assemble_fused_iterator_candidates(obligation, &mut candidates);
158 }
159 Some(LangItem::AsyncIterator) => {
160 self.assemble_async_iterator_candidates(obligation, &mut candidates);
161 }
162 Some(LangItem::AsyncFnKindHelper) => {
163 self.assemble_async_fn_kind_helper_candidates(
164 obligation,
165 &mut candidates,
166 );
167 }
168 Some(LangItem::AsyncFn | LangItem::AsyncFnMut | LangItem::AsyncFnOnce) => {
169 self.assemble_async_closure_candidates(obligation, &mut candidates);
170 }
171 Some(LangItem::Fn | LangItem::FnMut | LangItem::FnOnce) => {
172 self.assemble_closure_candidates(obligation, &mut candidates);
173 self.assemble_fn_pointer_candidates(obligation, &mut candidates);
174 }
175 _ => {}
176 }
177
178 self.assemble_candidates_from_impls(obligation, &mut candidates);
179 self.assemble_candidates_from_object_ty(obligation, &mut candidates);
180 }
181 }
182
183 self.assemble_candidates_from_projected_tys(obligation, &mut candidates);
184 self.assemble_candidates_from_caller_bounds(stack, &mut candidates)?;
185 self.assemble_candidates_from_auto_impls(obligation, &mut candidates);
186 }
187 debug!("candidate list size: {}", candidates.vec.len());
188 Ok(candidates)
189 }
190
191 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_candidates_from_projected_tys",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(191u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligation")
}> =
::tracing::__macro_support::FieldName::new("obligation");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
match obligation.predicate.skip_binder().trait_ref.self_ty().kind()
{
ty::Alias(_, ty::AliasTy {
kind: ty::Projection { .. } | ty::Opaque { .. }, .. }) => {}
ty::Infer(ty::TyVar(_)) => {
::rustc_middle::util::bug::span_bug_fmt(obligation.cause.span,
format_args!("Self=_ should have been handled by assemble_candidates"));
}
_ => return,
}
self.infcx.probe(|_|
{
let poly_trait_predicate =
self.infcx.resolve_vars_if_possible(obligation.predicate);
let placeholder_trait_predicate =
self.infcx.enter_forall_and_leak_universe(poly_trait_predicate);
let mut distinct_normalized_bounds = FxHashSet::default();
let _ =
self.for_each_item_bound::<!>(placeholder_trait_predicate.self_ty(),
|selcx, bound, idx, alias_bound_kind|
{
let Some(bound) =
bound.as_trait_clause() else {
return ControlFlow::Continue(());
};
if bound.polarity() != placeholder_trait_predicate.polarity
{
return ControlFlow::Continue(());
}
selcx.infcx.probe(|_|
{
let bound =
util::lazily_elaborate_sizedness_candidate(selcx.infcx,
obligation, bound);
match selcx.match_normalize_trait_ref(obligation,
placeholder_trait_predicate.trait_ref,
bound.map_bound(|pred| pred.trait_ref)) {
Ok(None) => {
candidates.vec.push(ProjectionCandidate {
idx,
kind: alias_bound_kind,
});
}
Ok(Some(normalized_trait)) if
distinct_normalized_bounds.insert(normalized_trait) => {
candidates.vec.push(ProjectionCandidate {
idx,
kind: alias_bound_kind,
});
}
_ => {}
}
});
ControlFlow::Continue(())
}, || candidates.ambiguous = true);
});
}
}
}#[instrument(level = "debug", skip(self, candidates))]
192 fn assemble_candidates_from_projected_tys(
193 &mut self,
194 obligation: &PolyTraitObligation<'tcx>,
195 candidates: &mut SelectionCandidateSet<'tcx>,
196 ) {
197 match obligation.predicate.skip_binder().trait_ref.self_ty().kind() {
200 ty::Alias(_, ty::AliasTy { kind: ty::Projection { .. } | ty::Opaque { .. }, .. }) => {}
202 ty::Infer(ty::TyVar(_)) => {
203 span_bug!(
204 obligation.cause.span,
205 "Self=_ should have been handled by assemble_candidates"
206 );
207 }
208 _ => return,
209 }
210
211 self.infcx.probe(|_| {
212 let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
213 let placeholder_trait_predicate =
214 self.infcx.enter_forall_and_leak_universe(poly_trait_predicate);
215
216 let mut distinct_normalized_bounds = FxHashSet::default();
220 let _ = self.for_each_item_bound::<!>(
221 placeholder_trait_predicate.self_ty(),
222 |selcx, bound, idx, alias_bound_kind| {
223 let Some(bound) = bound.as_trait_clause() else {
224 return ControlFlow::Continue(());
225 };
226 if bound.polarity() != placeholder_trait_predicate.polarity {
227 return ControlFlow::Continue(());
228 }
229
230 selcx.infcx.probe(|_| {
231 let bound = util::lazily_elaborate_sizedness_candidate(
232 selcx.infcx,
233 obligation,
234 bound,
235 );
236
237 match selcx.match_normalize_trait_ref(
239 obligation,
240 placeholder_trait_predicate.trait_ref,
241 bound.map_bound(|pred| pred.trait_ref),
242 ) {
243 Ok(None) => {
244 candidates
245 .vec
246 .push(ProjectionCandidate { idx, kind: alias_bound_kind });
247 }
248 Ok(Some(normalized_trait))
249 if distinct_normalized_bounds.insert(normalized_trait) =>
250 {
251 candidates
252 .vec
253 .push(ProjectionCandidate { idx, kind: alias_bound_kind });
254 }
255 _ => {}
256 }
257 });
258
259 ControlFlow::Continue(())
260 },
261 || candidates.ambiguous = true,
263 );
264 });
265 }
266
267 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_candidates_from_caller_bounds",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(271u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{ meta.fields().value_set_all(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Result<(), SelectionError<'tcx>> =
loop {};
return __tracing_attr_fake_return;
}
{
{
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/candidate_assembly.rs:277",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(277u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("stack.obligation")
}> =
::tracing::__macro_support::FieldName::new("stack.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(&::tracing::field::debug(&stack.obligation)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let bounds =
stack.obligation.param_env.caller_bounds().iter().filter_map(|c|
c.as_trait_clause()).filter(|p|
p.polarity() == stack.obligation.predicate.polarity());
let drcx = DeepRejectCtxt::relate_rigid_rigid(self.tcx());
let obligation_args =
stack.obligation.predicate.skip_binder().trait_ref.args;
for bound in bounds {
let bound =
util::lazily_elaborate_sizedness_candidate(self.infcx,
stack.obligation, bound);
if bound.def_id() != stack.obligation.predicate.def_id() {
continue;
}
let bound_trait_ref = bound.map_bound(|t| t.trait_ref);
if !drcx.args_may_unify(obligation_args,
bound_trait_ref.skip_binder().args) {
continue;
}
let wc = self.where_clause_may_apply(stack, bound_trait_ref)?;
if wc.may_apply() {
candidates.vec.push(ParamCandidate(bound));
}
}
Ok(())
}
}
}#[instrument(level = "debug", skip(self, stack, candidates))]
272 fn assemble_candidates_from_caller_bounds<'o>(
273 &mut self,
274 stack: &TraitObligationStack<'o, 'tcx>,
275 candidates: &mut SelectionCandidateSet<'tcx>,
276 ) -> Result<(), SelectionError<'tcx>> {
277 debug!(?stack.obligation);
278
279 let bounds = stack
280 .obligation
281 .param_env
282 .caller_bounds()
283 .iter()
284 .filter_map(|c| c.as_trait_clause())
285 .filter(|p| p.polarity() == stack.obligation.predicate.polarity());
287
288 let drcx = DeepRejectCtxt::relate_rigid_rigid(self.tcx());
289 let obligation_args = stack.obligation.predicate.skip_binder().trait_ref.args;
290 for bound in bounds {
292 let bound =
293 util::lazily_elaborate_sizedness_candidate(self.infcx, stack.obligation, bound);
294
295 if bound.def_id() != stack.obligation.predicate.def_id() {
297 continue;
298 }
299
300 let bound_trait_ref = bound.map_bound(|t| t.trait_ref);
301 if !drcx.args_may_unify(obligation_args, bound_trait_ref.skip_binder().args) {
302 continue;
303 }
304 let wc = self.where_clause_may_apply(stack, bound_trait_ref)?;
305 if wc.may_apply() {
306 candidates.vec.push(ParamCandidate(bound));
307 }
308 }
309
310 Ok(())
311 }
312
313 fn assemble_coroutine_candidates(
314 &mut self,
315 obligation: &PolyTraitObligation<'tcx>,
316 candidates: &mut SelectionCandidateSet<'tcx>,
317 ) {
318 let self_ty = obligation.self_ty().skip_binder();
322 match self_ty.kind() {
323 ty::Coroutine(did, ..) if self.tcx().is_general_coroutine(*did) => {
326 {
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/candidate_assembly.rs:326",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(326u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
},
{
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!("assemble_coroutine_candidates")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?self_ty, ?obligation, "assemble_coroutine_candidates");
327
328 candidates.vec.push(CoroutineCandidate);
329 }
330 ty::Infer(ty::TyVar(_)) => {
331 {
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/candidate_assembly.rs:331",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(331u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("assemble_coroutine_candidates: ambiguous self-type")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("assemble_coroutine_candidates: ambiguous self-type");
332 candidates.ambiguous = true;
333 }
334 _ => {}
335 }
336 }
337
338 fn assemble_future_candidates(
339 &mut self,
340 obligation: &PolyTraitObligation<'tcx>,
341 candidates: &mut SelectionCandidateSet<'tcx>,
342 ) {
343 let self_ty = obligation.self_ty().skip_binder();
344 if let ty::Coroutine(did, ..) = self_ty.kind() {
345 if self.tcx().coroutine_is_async(*did) {
348 {
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/candidate_assembly.rs:348",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(348u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
},
{
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!("assemble_future_candidates")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?self_ty, ?obligation, "assemble_future_candidates");
349
350 candidates.vec.push(FutureCandidate);
351 }
352 }
353 }
354
355 fn assemble_iterator_candidates(
356 &mut self,
357 obligation: &PolyTraitObligation<'tcx>,
358 candidates: &mut SelectionCandidateSet<'tcx>,
359 ) {
360 let self_ty = obligation.self_ty().skip_binder();
361 if let ty::Coroutine(did, ..) = self_ty.kind()
364 && self.tcx().coroutine_is_gen(*did)
365 {
366 {
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/candidate_assembly.rs:366",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(366u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
},
{
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!("assemble_iterator_candidates")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?self_ty, ?obligation, "assemble_iterator_candidates");
367
368 candidates.vec.push(IteratorCandidate);
369 }
370 }
371
372 fn assemble_fused_iterator_candidates(
373 &mut self,
374 obligation: &PolyTraitObligation<'tcx>,
375 candidates: &mut SelectionCandidateSet<'tcx>,
376 ) {
377 if self.coroutine_is_gen(obligation.self_ty().skip_binder()) {
378 candidates.vec.push(BuiltinCandidate);
379 }
380 }
381
382 fn assemble_async_iterator_candidates(
383 &mut self,
384 obligation: &PolyTraitObligation<'tcx>,
385 candidates: &mut SelectionCandidateSet<'tcx>,
386 ) {
387 let self_ty = obligation.self_ty().skip_binder();
388 if let ty::Coroutine(did, args) = *self_ty.kind() {
389 if self.tcx().coroutine_is_async_gen(did) {
392 {
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/candidate_assembly.rs:392",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(392u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
},
{
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!("assemble_iterator_candidates")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?self_ty, ?obligation, "assemble_iterator_candidates");
393
394 let ty::Adt(_poll_def, args) = *args.as_coroutine().yield_ty().kind() else {
397 candidates.ambiguous = true;
398 return;
399 };
400 let ty::Adt(_option_def, _) = *args.type_at(0).kind() else {
401 candidates.ambiguous = true;
402 return;
403 };
404
405 candidates.vec.push(AsyncIteratorCandidate);
406 }
407 }
408 }
409
410 fn assemble_closure_candidates(
417 &mut self,
418 obligation: &PolyTraitObligation<'tcx>,
419 candidates: &mut SelectionCandidateSet<'tcx>,
420 ) {
421 let kind = self.tcx().fn_trait_kind_from_def_id(obligation.predicate.def_id()).unwrap();
422
423 let self_ty = obligation.self_ty().skip_binder();
427 match *self_ty.kind() {
428 ty::Closure(def_id, _) => {
429 let is_const = self.tcx().is_const_fn(def_id);
430 {
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/candidate_assembly.rs:430",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(430u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("kind")
}> =
::tracing::__macro_support::FieldName::new("kind");
NAME.as_str()
},
{
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!("assemble_unboxed_candidates")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&kind)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?kind, ?obligation, "assemble_unboxed_candidates");
431 match self.infcx.closure_kind(self_ty) {
432 Some(closure_kind) => {
433 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs:433",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(433u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("closure_kind")
}> =
::tracing::__macro_support::FieldName::new("closure_kind");
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!("assemble_unboxed_candidates")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&closure_kind)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?closure_kind, "assemble_unboxed_candidates");
434 if closure_kind.extends(kind) {
435 candidates.vec.push(ClosureCandidate { is_const });
436 }
437 }
438 None => {
439 if kind == ty::ClosureKind::FnOnce {
440 candidates.vec.push(ClosureCandidate { is_const });
441 } else {
442 candidates.ambiguous = true;
443 }
444 }
445 }
446 }
447 ty::CoroutineClosure(def_id, args) => {
448 let args = args.as_coroutine_closure();
449 let is_const = self.tcx().is_const_fn(def_id);
450 if let Some(closure_kind) = self.infcx.closure_kind(self_ty)
451 && !args.tupled_upvars_ty().is_ty_var()
453 {
454 if closure_kind.extends(kind) && !args.has_self_borrows() {
459 candidates.vec.push(ClosureCandidate { is_const });
460 } else if kind == ty::ClosureKind::FnOnce {
461 candidates.vec.push(ClosureCandidate { is_const });
462 }
463 } else if kind == ty::ClosureKind::FnOnce {
464 candidates.vec.push(ClosureCandidate { is_const });
465 } else {
466 candidates.ambiguous = true;
468 }
469 }
470 ty::Infer(ty::TyVar(_)) => {
471 {
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/candidate_assembly.rs:471",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(471u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("assemble_unboxed_closure_candidates: ambiguous self-type")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("assemble_unboxed_closure_candidates: ambiguous self-type");
472 candidates.ambiguous = true;
473 }
474 _ => {}
475 }
476 }
477
478 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_async_closure_candidates",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(478u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligation")
}> =
::tracing::__macro_support::FieldName::new("obligation");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let goal_kind =
self.tcx().async_fn_trait_kind_from_def_id(obligation.predicate.def_id()).unwrap();
{
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/candidate_assembly.rs:487",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(487u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("self_ty = {0:?}",
obligation.self_ty().skip_binder().kind()) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};
match *obligation.self_ty().skip_binder().kind() {
ty::CoroutineClosure(def_id, args) => {
if let Some(closure_kind) =
args.as_coroutine_closure().kind_ty().to_opt_closure_kind()
&& !closure_kind.extends(goal_kind) {
return;
}
let Some(coroutine_kind) =
self.tcx().coroutine_kind(self.tcx().coroutine_for_closure(def_id)) else {
::rustc_middle::util::bug::bug_fmt(format_args!("coroutine with no kind"));
};
{
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/candidate_assembly.rs:504",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(504u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("coroutine_kind")
}> =
::tracing::__macro_support::FieldName::new("coroutine_kind");
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(&coroutine_kind)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
match coroutine_kind {
CoroutineKind::Desugared(CoroutineDesugaring::Async, _) => {
candidates.vec.push(AsyncClosureCandidate);
}
_ => (),
}
}
ty::Closure(_, args) => {
if let Some(closure_kind) =
args.as_closure().kind_ty().to_opt_closure_kind() &&
!closure_kind.extends(goal_kind) {
return;
}
candidates.vec.push(AsyncClosureCandidate);
}
ty::FnPtr(sig_tys, hdr) => {
if sig_tys.with(hdr).is_fn_trait_compatible() {
candidates.vec.push(AsyncClosureCandidate);
}
}
ty::FnDef(def_id, _) => {
let tcx = self.tcx();
if tcx.fn_sig(def_id).skip_binder().is_fn_trait_compatible()
&& tcx.codegen_fn_attrs(def_id).target_features.is_empty() {
candidates.vec.push(AsyncClosureCandidate);
}
}
_ => {}
}
}
}
}#[instrument(level = "debug", skip(self, candidates))]
479 fn assemble_async_closure_candidates(
480 &mut self,
481 obligation: &PolyTraitObligation<'tcx>,
482 candidates: &mut SelectionCandidateSet<'tcx>,
483 ) {
484 let goal_kind =
485 self.tcx().async_fn_trait_kind_from_def_id(obligation.predicate.def_id()).unwrap();
486
487 debug!("self_ty = {:?}", obligation.self_ty().skip_binder().kind());
488 match *obligation.self_ty().skip_binder().kind() {
489 ty::CoroutineClosure(def_id, args) => {
490 if let Some(closure_kind) =
491 args.as_coroutine_closure().kind_ty().to_opt_closure_kind()
492 && !closure_kind.extends(goal_kind)
493 {
494 return;
495 }
496
497 let Some(coroutine_kind) =
499 self.tcx().coroutine_kind(self.tcx().coroutine_for_closure(def_id))
500 else {
501 bug!("coroutine with no kind");
502 };
503
504 debug!(?coroutine_kind);
505 match coroutine_kind {
506 CoroutineKind::Desugared(CoroutineDesugaring::Async, _) => {
507 candidates.vec.push(AsyncClosureCandidate);
508 }
509 _ => (),
510 }
511 }
512 ty::Closure(_, args) => {
515 if let Some(closure_kind) = args.as_closure().kind_ty().to_opt_closure_kind()
516 && !closure_kind.extends(goal_kind)
517 {
518 return;
519 }
520 candidates.vec.push(AsyncClosureCandidate);
521 }
522 ty::FnPtr(sig_tys, hdr) => {
524 if sig_tys.with(hdr).is_fn_trait_compatible() {
525 candidates.vec.push(AsyncClosureCandidate);
526 }
527 }
528 ty::FnDef(def_id, _) => {
530 let tcx = self.tcx();
531 if tcx.fn_sig(def_id).skip_binder().is_fn_trait_compatible()
532 && tcx.codegen_fn_attrs(def_id).target_features.is_empty()
533 {
534 candidates.vec.push(AsyncClosureCandidate);
535 }
536 }
537 _ => {}
538 }
539 }
540
541 fn assemble_async_fn_kind_helper_candidates(
542 &mut self,
543 obligation: &PolyTraitObligation<'tcx>,
544 candidates: &mut SelectionCandidateSet<'tcx>,
545 ) {
546 let self_ty = obligation.self_ty().skip_binder();
547 let target_kind_ty = obligation.predicate.skip_binder().trait_ref.args.type_at(1);
548
549 if !(self_ty.is_integral() || self_ty.is_ty_var()) {
551 return;
552 }
553 if !(target_kind_ty.is_integral() || self_ty.is_ty_var()) {
554 return;
555 }
556
557 if let Some(closure_kind) = self_ty.to_opt_closure_kind()
560 && let Some(goal_kind) = target_kind_ty.to_opt_closure_kind()
561 && closure_kind.extends(goal_kind)
562 {
563 candidates.vec.push(AsyncFnKindHelperCandidate);
564 }
565 }
566
567 fn assemble_fn_pointer_candidates(
569 &mut self,
570 obligation: &PolyTraitObligation<'tcx>,
571 candidates: &mut SelectionCandidateSet<'tcx>,
572 ) {
573 let self_ty = obligation.self_ty().skip_binder();
578 match *self_ty.kind() {
579 ty::Infer(ty::TyVar(_)) => {
580 {
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/candidate_assembly.rs:580",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(580u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("assemble_fn_pointer_candidates: ambiguous self-type")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("assemble_fn_pointer_candidates: ambiguous self-type");
581 candidates.ambiguous = true; }
583 ty::FnPtr(sig_tys, hdr) => {
585 if sig_tys.with(hdr).is_fn_trait_compatible() {
586 candidates.vec.push(FnPointerCandidate);
587 }
588 }
589 ty::FnDef(def_id, _) => {
591 let tcx = self.tcx();
592 if tcx.fn_sig(def_id).skip_binder().is_fn_trait_compatible()
593 && tcx.codegen_fn_attrs(def_id).target_features.is_empty()
594 {
595 candidates.vec.push(FnPointerCandidate);
596 }
597 }
598 _ => {}
599 }
600 }
601
602 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_candidates_from_impls",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(603u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("obligation")
}> =
::tracing::__macro_support::FieldName::new("obligation");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let drcx = DeepRejectCtxt::relate_rigid_infer(self.tcx());
let obligation_args =
obligation.predicate.skip_binder().trait_ref.args;
self.tcx().for_each_relevant_impl(obligation.predicate.def_id(),
obligation.predicate.skip_binder().trait_ref.self_ty(),
|impl_def_id|
{
let impl_trait_header =
self.tcx().impl_trait_header(impl_def_id);
if !drcx.args_may_unify(obligation_args,
impl_trait_header.trait_ref.skip_binder().args) {
return;
}
if self.tcx().defaultness(impl_def_id).is_default() {
return;
}
if self.reject_fn_ptr_impls(impl_def_id, obligation,
impl_trait_header.trait_ref.skip_binder().self_ty()) {
return;
}
self.infcx.probe(|_|
{
if let Ok(_args) =
self.match_impl(impl_def_id, impl_trait_header, obligation)
{
candidates.vec.push(ImplCandidate(impl_def_id));
}
});
});
}
}
}#[instrument(level = "debug", skip(self, candidates))]
604 fn assemble_candidates_from_impls(
605 &mut self,
606 obligation: &PolyTraitObligation<'tcx>,
607 candidates: &mut SelectionCandidateSet<'tcx>,
608 ) {
609 let drcx = DeepRejectCtxt::relate_rigid_infer(self.tcx());
610 let obligation_args = obligation.predicate.skip_binder().trait_ref.args;
611 self.tcx().for_each_relevant_impl(
612 obligation.predicate.def_id(),
613 obligation.predicate.skip_binder().trait_ref.self_ty(),
614 |impl_def_id| {
615 let impl_trait_header = self.tcx().impl_trait_header(impl_def_id);
619 if !drcx
620 .args_may_unify(obligation_args, impl_trait_header.trait_ref.skip_binder().args)
621 {
622 return;
623 }
624
625 if self.tcx().defaultness(impl_def_id).is_default() {
629 return;
630 }
631
632 if self.reject_fn_ptr_impls(
633 impl_def_id,
634 obligation,
635 impl_trait_header.trait_ref.skip_binder().self_ty(),
636 ) {
637 return;
638 }
639
640 self.infcx.probe(|_| {
641 if let Ok(_args) = self.match_impl(impl_def_id, impl_trait_header, obligation) {
642 candidates.vec.push(ImplCandidate(impl_def_id));
643 }
644 });
645 },
646 );
647 }
648
649 x;#[instrument(level = "trace", skip(self), ret)]
654 fn reject_fn_ptr_impls(
655 &mut self,
656 impl_def_id: DefId,
657 obligation: &PolyTraitObligation<'tcx>,
658 impl_self_ty: Ty<'tcx>,
659 ) -> bool {
660 if !matches!(impl_self_ty.kind(), ty::Param(..)) {
662 return false;
663 }
664 let Some(fn_ptr_trait) = self.tcx().lang_items().fn_ptr_trait() else {
665 return false;
666 };
667
668 for &(clause, _) in self.tcx().clauses_of(impl_def_id).clauses {
669 let ty::ClauseKind::Trait(pred) = clause.kind().skip_binder() else { continue };
670 if fn_ptr_trait != pred.trait_ref.def_id {
671 continue;
672 }
673 trace!(?pred);
674 if pred.self_ty() != impl_self_ty {
676 continue;
677 }
678
679 let self_ty = obligation.self_ty().skip_binder();
680 match self_ty.kind() {
681 ty::FnPtr(..) => return false,
684
685 ty::Placeholder(..)
687 | ty::Dynamic(_, _)
688 | ty::Alias(_, _)
689 | ty::Infer(_)
690 | ty::Param(..)
691 | ty::Bound(_, _) => {}
692
693 ty::Bool
696 | ty::Char
697 | ty::Int(_)
698 | ty::Uint(_)
699 | ty::Float(_)
700 | ty::Adt(_, _)
701 | ty::Foreign(_)
702 | ty::Str
703 | ty::Array(_, _)
704 | ty::Pat(_, _)
705 | ty::Slice(_)
706 | ty::RawPtr(_, _)
707 | ty::Ref(_, _, _)
708 | ty::Closure(..)
709 | ty::CoroutineClosure(..)
710 | ty::Coroutine(_, _)
711 | ty::CoroutineWitness(..)
712 | ty::UnsafeBinder(_)
713 | ty::Never
714 | ty::Tuple(_)
715 | ty::Error(_) => return true,
716 ty::FnDef(_, _) => return true,
719 }
720
721 let obligation = Obligation::new(
724 self.tcx(),
725 obligation.cause.clone(),
726 obligation.param_env,
727 self.tcx().mk_predicate(obligation.predicate.map_bound(|mut pred| {
728 pred.trait_ref =
729 ty::TraitRef::new(self.tcx(), fn_ptr_trait, [pred.trait_ref.self_ty()]);
730 ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred))
731 })),
732 );
733 if let Ok(r) = self.evaluate_root_obligation(&obligation) {
734 if !r.may_apply() {
735 return true;
736 }
737 }
738 }
739 false
740 }
741
742 fn assemble_candidates_from_auto_impls(
743 &mut self,
744 obligation: &PolyTraitObligation<'tcx>,
745 candidates: &mut SelectionCandidateSet<'tcx>,
746 ) {
747 let self_ty = obligation.self_ty().skip_binder();
749 {
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/candidate_assembly.rs:749",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(749u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("assemble_candidates_from_auto_impls")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?self_ty, "assemble_candidates_from_auto_impls");
750
751 let def_id = obligation.predicate.def_id();
752
753 let mut check_impls = || {
754 let mut has_impl = false;
764 self.tcx().for_each_relevant_impl(def_id, self_ty, |_| has_impl = true);
765 if !has_impl {
766 candidates.vec.push(AutoImplCandidate)
767 }
768 };
769
770 if self.tcx().trait_is_auto(def_id) {
771 match *self_ty.kind() {
772 ty::Dynamic(..) => {
773 }
778 ty::Foreign(..) => {
779 if self.tcx().is_default_trait(def_id) {
787 check_impls()
788 }
789 }
790 ty::Param(..)
791 | ty::Alias(
792 _,
793 ty::AliasTy {
794 kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. },
795 ..
796 },
797 )
798 | ty::Placeholder(..)
799 | ty::Bound(..) => {
800 }
814 ty::Infer(ty::TyVar(_) | ty::IntVar(_) | ty::FloatVar(_)) => {
815 candidates.ambiguous = true;
817 }
818 ty::Coroutine(coroutine_def_id, _) => {
819 if self.tcx().is_lang_item(def_id, LangItem::Unpin) {
820 match self.tcx().coroutine_movability(coroutine_def_id) {
821 hir::Movability::Static => {
822 }
825 hir::Movability::Movable => {
826 candidates.vec.push(BuiltinCandidate);
829 }
830 }
831 } else {
832 if self.should_stall_coroutine(coroutine_def_id) {
833 candidates.ambiguous = true;
834 } else {
835 candidates.vec.push(AutoImplCandidate);
837 }
838 }
839 }
840
841 ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
842 ::rustc_middle::util::bug::bug_fmt(format_args!("asked to assemble auto trait candidates of unexpected type: {0:?}",
self_ty));bug!(
843 "asked to assemble auto trait candidates of unexpected type: {:?}",
844 self_ty
845 );
846 }
847
848 ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => {
849 if candidates.vec.iter().any(|c| #[allow(non_exhaustive_omitted_patterns)] match c {
ProjectionCandidate { .. } => true,
_ => false,
}matches!(c, ProjectionCandidate { .. })) {
850 } else if self.typing_mode().is_coherence() {
860 candidates.ambiguous = true;
863 } else if self.infcx.can_define_opaque_ty(def_id) {
864 candidates.ambiguous = true;
868 } else {
869 candidates.vec.push(AutoImplCandidate)
870 }
871 }
872
873 ty::CoroutineWitness(..) => {
874 candidates.vec.push(AutoImplCandidate);
875 }
876
877 ty::Bool
878 | ty::Char
879 | ty::Int(_)
880 | ty::Uint(_)
881 | ty::Float(_)
882 | ty::Str
883 | ty::Array(_, _)
884 | ty::Pat(_, _)
885 | ty::Slice(_)
886 | ty::Adt(..)
887 | ty::RawPtr(_, _)
888 | ty::Ref(..)
889 | ty::FnDef(..)
890 | ty::FnPtr(..)
891 | ty::Closure(..)
892 | ty::CoroutineClosure(..)
893 | ty::Never
894 | ty::Tuple(_)
895 | ty::UnsafeBinder(_) => {
896 if self.tcx().trait_def(def_id).safety.is_unsafe()
899 && self_ty.has_unsafe_fields()
900 {
901 return;
902 }
903
904 check_impls();
905 }
906 ty::Error(_) => {
907 candidates.vec.push(AutoImplCandidate);
908 }
909 }
910 }
911 }
912
913 fn assemble_candidates_from_object_ty(
915 &mut self,
916 obligation: &PolyTraitObligation<'tcx>,
917 candidates: &mut SelectionCandidateSet<'tcx>,
918 ) {
919 {
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/candidate_assembly.rs:919",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(919u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("assemble_candidates_from_object_ty")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation.self_ty().skip_binder())
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
920 self_ty = ?obligation.self_ty().skip_binder(),
921 "assemble_candidates_from_object_ty",
922 );
923
924 if self.tcx().is_sizedness_trait(obligation.predicate.def_id()) {
925 return;
928 }
929
930 self.infcx.probe(|_snapshot| {
931 let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
932 self.infcx.enter_forall(poly_trait_predicate, |placeholder_trait_predicate| {
933 let self_ty = placeholder_trait_predicate.self_ty();
934 let principal_trait_ref = match self_ty.kind() {
935 ty::Dynamic(data, ..) => {
936 if data.auto_traits().any(|did| did == obligation.predicate.def_id()) {
937 {
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/candidate_assembly.rs:937",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(937u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("assemble_candidates_from_object_ty: matched builtin bound, pushing candidate")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
938 "assemble_candidates_from_object_ty: matched builtin bound, \
939 pushing candidate"
940 );
941 candidates.vec.push(BuiltinObjectCandidate);
942 return;
943 }
944
945 if let Some(principal) = data.principal() {
946 principal.with_self_ty(self.tcx(), self_ty)
947 } else {
948 return;
950 }
951 }
952 ty::Infer(ty::TyVar(_)) => {
953 {
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/candidate_assembly.rs:953",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(953u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("assemble_candidates_from_object_ty: ambiguous")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("assemble_candidates_from_object_ty: ambiguous");
954 candidates.ambiguous = true; return;
956 }
957 _ => return,
958 };
959
960 {
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/candidate_assembly.rs:960",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(960u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("principal_trait_ref")
}> =
::tracing::__macro_support::FieldName::new("principal_trait_ref");
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!("assemble_candidates_from_object_ty")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&principal_trait_ref)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?principal_trait_ref, "assemble_candidates_from_object_ty");
961
962 let candidate_supertraits = util::supertraits(self.tcx(), principal_trait_ref)
968 .enumerate()
969 .filter(|&(_, upcast_trait_ref)| {
970 self.infcx.probe(|_| {
971 self.match_normalize_trait_ref(
972 obligation,
973 placeholder_trait_predicate.trait_ref,
974 upcast_trait_ref,
975 )
976 .is_ok()
977 })
978 })
979 .map(|(idx, _)| ObjectCandidate(idx));
980
981 candidates.vec.extend(candidate_supertraits);
982 })
983 })
984 }
985
986 fn assemble_candidates_for_unsizing(
988 &mut self,
989 obligation: &PolyTraitObligation<'tcx>,
990 candidates: &mut SelectionCandidateSet<'tcx>,
991 ) {
992 let Some(trait_pred) = obligation.predicate.no_bound_vars() else {
1007 return;
1009 };
1010 let source = trait_pred.self_ty();
1011 let target = trait_pred.trait_ref.args.type_at(1);
1012
1013 {
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/candidate_assembly.rs:1013",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(1013u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::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!("assemble_candidates_for_unsizing")
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, "assemble_candidates_for_unsizing");
1014
1015 match (source.kind(), target.kind()) {
1016 (&ty::Dynamic(a_data, a_region), &ty::Dynamic(b_data, b_region)) => {
1018 let principal_def_id_a = a_data.principal_def_id();
1030 let principal_def_id_b = b_data.principal_def_id();
1031 if principal_def_id_a == principal_def_id_b || principal_def_id_b.is_none() {
1032 let a_auto_traits: FxIndexSet<DefId> = a_data
1036 .auto_traits()
1037 .chain(
1038 principal_def_id_a
1039 .map(|principal_def_id| {
1040 elaborate::supertrait_def_ids(self.tcx(), principal_def_id)
1041 .filter(|def_id| self.tcx().trait_is_auto(*def_id))
1042 })
1043 .into_flat_iter(),
1044 )
1045 .collect();
1046 let auto_traits_compatible = b_data
1047 .auto_traits()
1048 .all(|b| a_auto_traits.contains(&b));
1050 if auto_traits_compatible {
1051 candidates.vec.push(BuiltinUnsizeCandidate);
1052 }
1053 } else if principal_def_id_a.is_some() && principal_def_id_b.is_some() {
1054 let principal_a = a_data.principal().unwrap();
1056 let target_trait_did = principal_def_id_b.unwrap();
1057 let source_trait_ref = principal_a.with_self_ty(self.tcx(), source);
1058
1059 for (idx, upcast_trait_ref) in
1060 util::supertraits(self.tcx(), source_trait_ref).enumerate()
1061 {
1062 self.infcx.probe(|_| {
1063 if upcast_trait_ref.def_id() == target_trait_did
1064 && let Ok(nested) = self.match_upcast_principal(
1065 obligation,
1066 ty::Unnormalized::new_wip(upcast_trait_ref),
1067 a_data,
1068 b_data,
1069 a_region,
1070 b_region,
1071 )
1072 {
1073 if nested.is_none() {
1074 candidates.ambiguous = true;
1075 }
1076 candidates.vec.push(TraitUpcastingUnsizeCandidate(idx));
1077 }
1078 })
1079 }
1080 }
1081 }
1082
1083 (_, &ty::Dynamic(_, _)) => {
1085 candidates.vec.push(BuiltinUnsizeCandidate);
1086 }
1087
1088 (&ty::Infer(ty::TyVar(_)), _) | (_, &ty::Infer(ty::TyVar(_))) => {
1092 {
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/candidate_assembly.rs:1092",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(1092u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("assemble_candidates_for_unsizing: ambiguous")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("assemble_candidates_for_unsizing: ambiguous");
1093 candidates.ambiguous = true;
1094 }
1095
1096 (&ty::Array(..), &ty::Slice(_)) => {
1098 candidates.vec.push(BuiltinUnsizeCandidate);
1099 }
1100
1101 (&ty::Adt(def_id_a, _), &ty::Adt(def_id_b, _)) if def_id_a.is_struct() => {
1103 if def_id_a == def_id_b {
1104 candidates.vec.push(BuiltinUnsizeCandidate);
1105 }
1106 }
1107
1108 _ => {}
1109 };
1110 }
1111
1112 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_candidates_for_transmutability",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(1112u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{ meta.fields().value_set_all(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
if obligation.predicate.has_non_region_param() { return; }
if obligation.has_non_region_infer() {
candidates.ambiguous = true;
return;
}
candidates.vec.push(TransmutabilityCandidate);
}
}
}#[instrument(level = "debug", skip(self, obligation, candidates))]
1113 fn assemble_candidates_for_transmutability(
1114 &mut self,
1115 obligation: &PolyTraitObligation<'tcx>,
1116 candidates: &mut SelectionCandidateSet<'tcx>,
1117 ) {
1118 if obligation.predicate.has_non_region_param() {
1119 return;
1120 }
1121
1122 if obligation.has_non_region_infer() {
1123 candidates.ambiguous = true;
1124 return;
1125 }
1126
1127 candidates.vec.push(TransmutabilityCandidate);
1128 }
1129
1130 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_candidates_for_trait_alias",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(1130u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{ meta.fields().value_set_all(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let self_ty = obligation.self_ty().skip_binder();
{
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/candidate_assembly.rs:1138",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(1138u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let def_id = obligation.predicate.def_id();
if self.tcx().is_trait_alias(def_id) {
candidates.vec.push(TraitAliasCandidate);
}
}
}
}#[instrument(level = "debug", skip(self, obligation, candidates))]
1131 fn assemble_candidates_for_trait_alias(
1132 &mut self,
1133 obligation: &PolyTraitObligation<'tcx>,
1134 candidates: &mut SelectionCandidateSet<'tcx>,
1135 ) {
1136 let self_ty = obligation.self_ty().skip_binder();
1138 debug!(?self_ty);
1139
1140 let def_id = obligation.predicate.def_id();
1141
1142 if self.tcx().is_trait_alias(def_id) {
1143 candidates.vec.push(TraitAliasCandidate);
1144 }
1145 }
1146
1147 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_builtin_copy_clone_candidate",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(1149u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
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(&self_ty)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
match *self_ty.kind() {
ty::FnDef(..) | ty::FnPtr(..) | ty::Error(_) | ty::Tuple(..) |
ty::Pat(..) => {
candidates.vec.push(BuiltinCandidate);
}
ty::Uint(_) | ty::Int(_) |
ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) | ty::Bool |
ty::Float(_) | ty::Char | ty::RawPtr(..) | ty::Never |
ty::Ref(_, _, hir::Mutability::Not) | ty::Array(..) => {}
ty::UnsafeBinder(_) => {}
ty::Dynamic(..) | ty::Str | ty::Slice(..) | ty::Foreign(..) =>
{}
ty::Ref(_, _, hir::Mutability::Mut) => {}
ty::Coroutine(coroutine_def_id, args) => {
if self.should_stall_coroutine(coroutine_def_id) {
candidates.ambiguous = true;
return;
}
match self.tcx().coroutine_movability(coroutine_def_id) {
hir::Movability::Static => {}
hir::Movability::Movable => {
if self.tcx().features().coroutine_clone() {
let resolved_upvars =
self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty());
if resolved_upvars.is_ty_var() {
candidates.ambiguous = true;
} else { candidates.vec.push(BuiltinCandidate); }
}
}
}
}
ty::Closure(_, args) => {
let resolved_upvars =
self.infcx.shallow_resolve(args.as_closure().tupled_upvars_ty());
if resolved_upvars.is_ty_var() {
candidates.ambiguous = true;
} else { candidates.vec.push(BuiltinCandidate); }
}
ty::CoroutineClosure(_, args) => {
let resolved_upvars =
self.infcx.shallow_resolve(args.as_coroutine_closure().tupled_upvars_ty());
if resolved_upvars.is_ty_var() {
candidates.ambiguous = true;
} else { candidates.vec.push(BuiltinCandidate); }
}
ty::CoroutineWitness(..) => {
candidates.vec.push(SizedCandidate);
}
ty::Adt(..) | ty::Alias(..) | ty::Param(..) |
ty::Placeholder(..) => {}
ty::Infer(ty::TyVar(_)) => { candidates.ambiguous = true; }
ty::Bound(..) => {}
ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) |
ty::FreshFloatTy(_)) => {
::rustc_middle::util::bug::bug_fmt(format_args!("asked to assemble builtin bounds of unexpected type: {0:?}",
self_ty));
}
}
}
}
}#[instrument(level = "debug", skip(self, candidates))]
1150 fn assemble_builtin_copy_clone_candidate(
1151 &mut self,
1152 self_ty: Ty<'tcx>,
1153 candidates: &mut SelectionCandidateSet<'tcx>,
1154 ) {
1155 match *self_ty.kind() {
1156 ty::FnDef(..) | ty::FnPtr(..) | ty::Error(_) | ty::Tuple(..) | ty::Pat(..) => {
1159 candidates.vec.push(BuiltinCandidate);
1160 }
1161
1162 ty::Uint(_)
1164 | ty::Int(_)
1165 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
1166 | ty::Bool
1167 | ty::Float(_)
1168 | ty::Char
1169 | ty::RawPtr(..)
1170 | ty::Never
1171 | ty::Ref(_, _, hir::Mutability::Not)
1172 | ty::Array(..) => {}
1173
1174 ty::UnsafeBinder(_) => {}
1177
1178 ty::Dynamic(..) | ty::Str | ty::Slice(..) | ty::Foreign(..) => {}
1180
1181 ty::Ref(_, _, hir::Mutability::Mut) => {}
1183
1184 ty::Coroutine(coroutine_def_id, args) => {
1185 if self.should_stall_coroutine(coroutine_def_id) {
1186 candidates.ambiguous = true;
1187 return;
1188 }
1189
1190 match self.tcx().coroutine_movability(coroutine_def_id) {
1191 hir::Movability::Static => {}
1192 hir::Movability::Movable => {
1193 if self.tcx().features().coroutine_clone() {
1194 let resolved_upvars =
1195 self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty());
1196 if resolved_upvars.is_ty_var() {
1197 candidates.ambiguous = true;
1199 } else {
1200 candidates.vec.push(BuiltinCandidate);
1201 }
1202 }
1203 }
1204 }
1205 }
1206
1207 ty::Closure(_, args) => {
1208 let resolved_upvars =
1209 self.infcx.shallow_resolve(args.as_closure().tupled_upvars_ty());
1210 if resolved_upvars.is_ty_var() {
1211 candidates.ambiguous = true;
1213 } else {
1214 candidates.vec.push(BuiltinCandidate);
1215 }
1216 }
1217
1218 ty::CoroutineClosure(_, args) => {
1219 let resolved_upvars =
1220 self.infcx.shallow_resolve(args.as_coroutine_closure().tupled_upvars_ty());
1221 if resolved_upvars.is_ty_var() {
1222 candidates.ambiguous = true;
1224 } else {
1225 candidates.vec.push(BuiltinCandidate);
1226 }
1227 }
1228
1229 ty::CoroutineWitness(..) => {
1230 candidates.vec.push(SizedCandidate);
1231 }
1232
1233 ty::Adt(..) | ty::Alias(..) | ty::Param(..) | ty::Placeholder(..) => {}
1235
1236 ty::Infer(ty::TyVar(_)) => {
1237 candidates.ambiguous = true;
1238 }
1239
1240 ty::Bound(..) => {}
1242
1243 ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1244 bug!("asked to assemble builtin bounds of unexpected type: {:?}", self_ty);
1245 }
1246 }
1247 }
1248
1249 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_builtin_sized_candidate",
"rustc_trait_selection::traits::select::candidate_assembly",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs"),
::tracing_core::__macro_support::Option::Some(1250u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("sizedness")
}> =
::tracing::__macro_support::FieldName::new("sizedness");
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(&self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&sizedness)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
match *self_ty.kind() {
ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) | ty::Uint(_) |
ty::Int(_) | ty::Bool | ty::Float(_) | ty::FnDef(..) |
ty::FnPtr(..) | ty::RawPtr(..) | ty::Char | ty::Ref(..) |
ty::Array(..) | ty::Closure(..) | ty::CoroutineClosure(..) |
ty::Never | ty::Error(_) => {
candidates.vec.push(SizedCandidate);
}
ty::Coroutine(coroutine_def_id, _) => {
if self.should_stall_coroutine(coroutine_def_id) {
candidates.ambiguous = true;
} else { candidates.vec.push(SizedCandidate); }
}
ty::CoroutineWitness(..) => {
candidates.vec.push(SizedCandidate);
}
ty::Tuple(..) | ty::Pat(..) | ty::Adt(..) |
ty::UnsafeBinder(_) => {
candidates.vec.push(SizedCandidate);
}
ty::Str | ty::Slice(_) | ty::Dynamic(..) =>
match sizedness {
SizedTraitKind::Sized => {}
SizedTraitKind::MetaSized => {
candidates.vec.push(SizedCandidate);
}
},
ty::Foreign(..) => {}
ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => {}
ty::Infer(ty::TyVar(_)) => { candidates.ambiguous = true; }
ty::Bound(..) => {}
ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) |
ty::FreshFloatTy(_)) => {
::rustc_middle::util::bug::bug_fmt(format_args!("asked to assemble builtin bounds of unexpected type: {0:?}",
self_ty));
}
}
}
}
}#[instrument(level = "debug", skip(self, candidates))]
1251 fn assemble_builtin_sized_candidate(
1252 &mut self,
1253 self_ty: Ty<'tcx>,
1254 candidates: &mut SelectionCandidateSet<'tcx>,
1255 sizedness: SizedTraitKind,
1256 ) {
1257 match *self_ty.kind() {
1258 ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
1260 | ty::Uint(_)
1261 | ty::Int(_)
1262 | ty::Bool
1263 | ty::Float(_)
1264 | ty::FnDef(..)
1265 | ty::FnPtr(..)
1266 | ty::RawPtr(..)
1267 | ty::Char
1268 | ty::Ref(..)
1269 | ty::Array(..)
1270 | ty::Closure(..)
1271 | ty::CoroutineClosure(..)
1272 | ty::Never
1273 | ty::Error(_) => {
1274 candidates.vec.push(SizedCandidate);
1275 }
1276
1277 ty::Coroutine(coroutine_def_id, _) => {
1278 if self.should_stall_coroutine(coroutine_def_id) {
1279 candidates.ambiguous = true;
1280 } else {
1281 candidates.vec.push(SizedCandidate);
1282 }
1283 }
1284
1285 ty::CoroutineWitness(..) => {
1286 candidates.vec.push(SizedCandidate);
1287 }
1288
1289 ty::Tuple(..) | ty::Pat(..) | ty::Adt(..) | ty::UnsafeBinder(_) => {
1291 candidates.vec.push(SizedCandidate);
1292 }
1293
1294 ty::Str | ty::Slice(_) | ty::Dynamic(..) => match sizedness {
1296 SizedTraitKind::Sized => {}
1297 SizedTraitKind::MetaSized => {
1298 candidates.vec.push(SizedCandidate);
1299 }
1300 },
1301
1302 ty::Foreign(..) => {}
1304
1305 ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => {}
1306
1307 ty::Infer(ty::TyVar(_)) => {
1308 candidates.ambiguous = true;
1309 }
1310
1311 ty::Bound(..) => {}
1313
1314 ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1315 bug!("asked to assemble builtin bounds of unexpected type: {:?}", self_ty);
1316 }
1317 }
1318 }
1319
1320 fn assemble_const_destruct_candidates(
1321 &mut self,
1322 _obligation: &PolyTraitObligation<'tcx>,
1323 candidates: &mut SelectionCandidateSet<'tcx>,
1324 ) {
1325 candidates.vec.push(BuiltinCandidate);
1326 }
1327
1328 fn assemble_candidate_for_tuple(
1329 &mut self,
1330 obligation: &PolyTraitObligation<'tcx>,
1331 candidates: &mut SelectionCandidateSet<'tcx>,
1332 ) {
1333 let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder());
1334 match self_ty.kind() {
1335 ty::Tuple(_) => {
1336 candidates.vec.push(BuiltinCandidate);
1337 }
1338 ty::Infer(ty::TyVar(_)) => {
1339 candidates.ambiguous = true;
1340 }
1341 ty::Bool
1342 | ty::Char
1343 | ty::Int(_)
1344 | ty::Uint(_)
1345 | ty::Float(_)
1346 | ty::Adt(_, _)
1347 | ty::Foreign(_)
1348 | ty::Str
1349 | ty::Array(_, _)
1350 | ty::Slice(_)
1351 | ty::RawPtr(_, _)
1352 | ty::Ref(_, _, _)
1353 | ty::FnDef(_, _)
1354 | ty::Pat(_, _)
1355 | ty::FnPtr(..)
1356 | ty::UnsafeBinder(_)
1357 | ty::Dynamic(_, _)
1358 | ty::Closure(..)
1359 | ty::CoroutineClosure(..)
1360 | ty::Coroutine(_, _)
1361 | ty::CoroutineWitness(..)
1362 | ty::Never
1363 | ty::Alias(..)
1364 | ty::Param(_)
1365 | ty::Bound(_, _)
1366 | ty::Error(_)
1367 | ty::Infer(_)
1368 | ty::Placeholder(_) => {}
1369 }
1370 }
1371
1372 fn assemble_candidates_for_fn_ptr_trait(
1373 &mut self,
1374 obligation: &PolyTraitObligation<'tcx>,
1375 candidates: &mut SelectionCandidateSet<'tcx>,
1376 ) {
1377 let self_ty = self.infcx.resolve_vars_if_possible(obligation.self_ty());
1378
1379 match self_ty.skip_binder().kind() {
1380 ty::FnPtr(..) => candidates.vec.push(BuiltinCandidate),
1381 ty::Bool
1382 | ty::Char
1383 | ty::Int(_)
1384 | ty::Uint(_)
1385 | ty::Float(_)
1386 | ty::Adt(..)
1387 | ty::Foreign(..)
1388 | ty::Str
1389 | ty::Array(..)
1390 | ty::Pat(..)
1391 | ty::Slice(_)
1392 | ty::RawPtr(_, _)
1393 | ty::Ref(..)
1394 | ty::FnDef(..)
1395 | ty::Placeholder(..)
1396 | ty::Dynamic(..)
1397 | ty::Closure(..)
1398 | ty::CoroutineClosure(..)
1399 | ty::Coroutine(..)
1400 | ty::CoroutineWitness(..)
1401 | ty::UnsafeBinder(_)
1402 | ty::Never
1403 | ty::Tuple(..)
1404 | ty::Alias(..)
1405 | ty::Param(..)
1406 | ty::Bound(..)
1407 | ty::Error(_)
1408 | ty::Infer(
1409 ty::InferTy::IntVar(_)
1410 | ty::InferTy::FloatVar(_)
1411 | ty::InferTy::FreshIntTy(_)
1412 | ty::InferTy::FreshFloatTy(_),
1413 ) => {}
1414 ty::Infer(ty::InferTy::TyVar(_) | ty::InferTy::FreshTy(_)) => {
1415 candidates.ambiguous = true;
1416 }
1417 }
1418 }
1419
1420 fn assemble_candidates_for_bikeshed_guaranteed_no_drop_trait(
1421 &mut self,
1422 obligation: &PolyTraitObligation<'tcx>,
1423 candidates: &mut SelectionCandidateSet<'tcx>,
1424 ) {
1425 match obligation.predicate.self_ty().skip_binder().kind() {
1426 ty::Ref(..)
1427 | ty::Adt(..)
1428 | ty::Tuple(_)
1429 | ty::Array(..)
1430 | ty::FnDef(..)
1431 | ty::FnPtr(..)
1432 | ty::Error(_)
1433 | ty::Uint(_)
1434 | ty::Int(_)
1435 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
1436 | ty::Bool
1437 | ty::Float(_)
1438 | ty::Char
1439 | ty::RawPtr(..)
1440 | ty::Never
1441 | ty::Pat(..)
1442 | ty::Dynamic(..)
1443 | ty::Str
1444 | ty::Slice(_)
1445 | ty::Foreign(..)
1446 | ty::Alias(..)
1447 | ty::Param(_)
1448 | ty::Placeholder(..)
1449 | ty::Closure(..)
1450 | ty::CoroutineClosure(..)
1451 | ty::Coroutine(..)
1452 | ty::UnsafeBinder(_)
1453 | ty::CoroutineWitness(..)
1454 | ty::Bound(..) => {
1455 candidates.vec.push(BikeshedGuaranteedNoDropCandidate);
1456 }
1457
1458 ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1459 candidates.ambiguous = true;
1460 }
1461 }
1462 }
1463
1464 fn assemble_candidates_for_try_as_dyn(
1465 &mut self,
1466 obligation: &PolyTraitObligation<'tcx>,
1467 candidates: &mut SelectionCandidateSet<'tcx>,
1468 ) {
1469 match *obligation.predicate.self_ty().skip_binder().kind() {
1470 ty::Dynamic(bounds, _lifetime) => {
1471 for bound in bounds {
1472 match bound.skip_binder() {
1473 ExistentialPredicate::Trait(_) => {}
1474 ExistentialPredicate::Projection(_) => return,
1476 ExistentialPredicate::AutoTrait(_) => {}
1479 }
1480 }
1481 candidates.vec.push(TryAsDynCandidate);
1482 }
1483
1484 ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1485 candidates.ambiguous = true;
1486 }
1487
1488 _ => {}
1489 }
1490 }
1491
1492 fn assemble_candidates_for_field_trait(
1493 &mut self,
1494 obligation: &PolyTraitObligation<'tcx>,
1495 candidates: &mut SelectionCandidateSet<'tcx>,
1496 ) {
1497 if let ty::Adt(def, args) = obligation.predicate.self_ty().skip_binder().kind()
1498 && let Some(FieldInfo { base, ty, .. }) =
1499 def.field_representing_type_info(self.tcx(), args)
1500 && match self.infcx.evaluate_obligation(&PredicateObligation::new(
1505 self.tcx(),
1506 obligation.cause.clone(),
1507 obligation.param_env,
1508 TraitRef::new(
1509 self.tcx(),
1510 self.tcx().require_lang_item(LangItem::Sized, DUMMY_SP),
1511 [base],
1512 ),
1513 )) {
1514 Ok(res) if res.must_apply_modulo_regions() => true,
1515 _ => false,
1516 }
1517 && match self.infcx.evaluate_obligation(&PredicateObligation::new(
1518 self.tcx(),
1519 obligation.cause.clone(),
1520 obligation.param_env,
1521 TraitRef::new(
1522 self.tcx(),
1523 self.tcx().require_lang_item(LangItem::Sized, DUMMY_SP),
1524 [ty],
1525 ),
1526 )) {
1527 Ok(res) if res.must_apply_modulo_regions() => true,
1528 _ => false,
1529 }
1530 && match base.kind() {
1531 ty::Adt(def, _) => def.is_struct() && !def.repr().packed(),
1532 ty::Tuple(..) => true,
1533 _ => false,
1534 }
1535 {
1536 candidates.vec.push(BuiltinCandidate);
1537 }
1538 }
1539}