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, SelectionError};
16use rustc_middle::ty::fast_reject::DeepRejectCtxt;
17use rustc_middle::ty::{self, SizedTraitKind, Ty, TypeVisitableExt, TypingMode, elaborate};
18use rustc_middle::{bug, span_bug};
19use tracing::{debug, instrument, trace};
20
21use super::SelectionCandidate::*;
22use super::{SelectionCandidateSet, SelectionContext, TraitObligationStack};
23use crate::traits::util;
24
25impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
26 #[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(26u32),
::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(&[]) })
} 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:40",
"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(40u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message", "ty"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("ambiguous inference var or opaque type")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligation.predicate.skip_binder().self_ty())
as &dyn 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:71",
"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(71u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["obligation_self_ty"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligation.predicate.skip_binder().self_ty())
as &dyn 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);
}
_ => {
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:176",
"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(176u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("candidate list size: {0}",
candidates.vec.len()) as &dyn Value))])
});
} else { ; }
};
Ok(candidates)
}
}
}#[instrument(skip(self, stack), level = "debug")]
27 pub(super) fn assemble_candidates<'o>(
28 &mut self,
29 stack: &TraitObligationStack<'o, 'tcx>,
30 ) -> Result<SelectionCandidateSet<'tcx>, SelectionError<'tcx>> {
31 let TraitObligationStack { obligation, .. } = *stack;
32 let obligation = &Obligation {
33 param_env: obligation.param_env,
34 cause: obligation.cause.clone(),
35 recursion_depth: obligation.recursion_depth,
36 predicate: self.infcx.resolve_vars_if_possible(obligation.predicate),
37 };
38
39 if obligation.predicate.skip_binder().self_ty().is_ty_var() {
40 debug!(ty = ?obligation.predicate.skip_binder().self_ty(), "ambiguous inference var or opaque type");
41 return Ok(SelectionCandidateSet { vec: vec![], ambiguous: true });
51 }
52
53 let mut candidates = SelectionCandidateSet { vec: Vec::new(), ambiguous: false };
54
55 if obligation.polarity() == ty::PredicatePolarity::Negative {
57 self.assemble_candidates_for_trait_alias(obligation, &mut candidates);
58 self.assemble_candidates_from_impls(obligation, &mut candidates);
59 self.assemble_candidates_from_caller_bounds(stack, &mut candidates)?;
60 } else {
61 self.assemble_candidates_for_trait_alias(obligation, &mut candidates);
62
63 let def_id = obligation.predicate.def_id();
66 let tcx = self.tcx();
67
68 let lang_item = tcx.as_lang_item(def_id);
69 match lang_item {
70 Some(LangItem::Copy | LangItem::Clone | LangItem::TrivialClone) => {
71 debug!(obligation_self_ty = ?obligation.predicate.skip_binder().self_ty());
72
73 self.assemble_candidates_from_impls(obligation, &mut candidates);
76
77 self.assemble_builtin_copy_clone_candidate(
79 obligation.predicate.self_ty().skip_binder(),
80 &mut candidates,
81 );
82 }
83 Some(LangItem::DiscriminantKind) => {
84 candidates.vec.push(BuiltinCandidate);
86 }
87 Some(LangItem::PointeeTrait) => {
88 candidates.vec.push(BuiltinCandidate);
90 }
91 Some(LangItem::Sized) => {
92 self.assemble_builtin_sized_candidate(
93 obligation.predicate.self_ty().skip_binder(),
94 &mut candidates,
95 SizedTraitKind::Sized,
96 );
97 }
98 Some(LangItem::MetaSized) => {
99 self.assemble_builtin_sized_candidate(
100 obligation.predicate.self_ty().skip_binder(),
101 &mut candidates,
102 SizedTraitKind::MetaSized,
103 );
104 }
105 Some(LangItem::PointeeSized) => {
106 bug!("`PointeeSized` is removed during lowering");
107 }
108 Some(LangItem::Unsize) => {
109 self.assemble_candidates_for_unsizing(obligation, &mut candidates);
110 }
111 Some(LangItem::Destruct) => {
112 self.assemble_const_destruct_candidates(obligation, &mut candidates);
113 }
114 Some(LangItem::TransmuteTrait) => {
115 self.assemble_candidates_from_impls(obligation, &mut candidates);
117 self.assemble_candidates_for_transmutability(obligation, &mut candidates);
118 }
119 Some(LangItem::Tuple) => {
120 self.assemble_candidate_for_tuple(obligation, &mut candidates);
121 }
122 Some(LangItem::FnPtrTrait) => {
123 self.assemble_candidates_for_fn_ptr_trait(obligation, &mut candidates);
124 }
125 Some(LangItem::BikeshedGuaranteedNoDrop) => {
126 self.assemble_candidates_for_bikeshed_guaranteed_no_drop_trait(
127 obligation,
128 &mut candidates,
129 );
130 }
131 _ => {
132 match lang_item {
136 Some(LangItem::Coroutine) => {
137 self.assemble_coroutine_candidates(obligation, &mut candidates);
138 }
139 Some(LangItem::Future) => {
140 self.assemble_future_candidates(obligation, &mut candidates);
141 }
142 Some(LangItem::Iterator) => {
143 self.assemble_iterator_candidates(obligation, &mut candidates);
144 }
145 Some(LangItem::FusedIterator) => {
146 self.assemble_fused_iterator_candidates(obligation, &mut candidates);
147 }
148 Some(LangItem::AsyncIterator) => {
149 self.assemble_async_iterator_candidates(obligation, &mut candidates);
150 }
151 Some(LangItem::AsyncFnKindHelper) => {
152 self.assemble_async_fn_kind_helper_candidates(
153 obligation,
154 &mut candidates,
155 );
156 }
157 Some(LangItem::AsyncFn | LangItem::AsyncFnMut | LangItem::AsyncFnOnce) => {
158 self.assemble_async_closure_candidates(obligation, &mut candidates);
159 }
160 Some(LangItem::Fn | LangItem::FnMut | LangItem::FnOnce) => {
161 self.assemble_closure_candidates(obligation, &mut candidates);
162 self.assemble_fn_pointer_candidates(obligation, &mut candidates);
163 }
164 _ => {}
165 }
166
167 self.assemble_candidates_from_impls(obligation, &mut candidates);
168 self.assemble_candidates_from_object_ty(obligation, &mut candidates);
169 }
170 }
171
172 self.assemble_candidates_from_projected_tys(obligation, &mut candidates);
173 self.assemble_candidates_from_caller_bounds(stack, &mut candidates)?;
174 self.assemble_candidates_from_auto_impls(obligation, &mut candidates);
175 }
176 debug!("candidate list size: {}", candidates.vec.len());
177 Ok(candidates)
178 }
179
180 #[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(180u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["obligation"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn 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::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))]
181 fn assemble_candidates_from_projected_tys(
182 &mut self,
183 obligation: &PolyTraitObligation<'tcx>,
184 candidates: &mut SelectionCandidateSet<'tcx>,
185 ) {
186 match obligation.predicate.skip_binder().trait_ref.self_ty().kind() {
189 ty::Alias(ty::Projection | ty::Opaque, _) => {}
191 ty::Infer(ty::TyVar(_)) => {
192 span_bug!(
193 obligation.cause.span,
194 "Self=_ should have been handled by assemble_candidates"
195 );
196 }
197 _ => return,
198 }
199
200 self.infcx.probe(|_| {
201 let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
202 let placeholder_trait_predicate =
203 self.infcx.enter_forall_and_leak_universe(poly_trait_predicate);
204
205 let mut distinct_normalized_bounds = FxHashSet::default();
209 let _ = self.for_each_item_bound::<!>(
210 placeholder_trait_predicate.self_ty(),
211 |selcx, bound, idx, alias_bound_kind| {
212 let Some(bound) = bound.as_trait_clause() else {
213 return ControlFlow::Continue(());
214 };
215 if bound.polarity() != placeholder_trait_predicate.polarity {
216 return ControlFlow::Continue(());
217 }
218
219 selcx.infcx.probe(|_| {
220 let bound = util::lazily_elaborate_sizedness_candidate(
221 selcx.infcx,
222 obligation,
223 bound,
224 );
225
226 match selcx.match_normalize_trait_ref(
228 obligation,
229 placeholder_trait_predicate.trait_ref,
230 bound.map_bound(|pred| pred.trait_ref),
231 ) {
232 Ok(None) => {
233 candidates
234 .vec
235 .push(ProjectionCandidate { idx, kind: alias_bound_kind });
236 }
237 Ok(Some(normalized_trait))
238 if distinct_normalized_bounds.insert(normalized_trait) =>
239 {
240 candidates
241 .vec
242 .push(ProjectionCandidate { idx, kind: alias_bound_kind });
243 }
244 _ => {}
245 }
246 });
247
248 ControlFlow::Continue(())
249 },
250 || candidates.ambiguous = true,
252 );
253 });
254 }
255
256 #[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(260u32),
::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(&[]) })
} 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:266",
"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(266u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["stack.obligation"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&stack.obligation)
as &dyn Value))])
});
} else { ; }
};
let bounds =
stack.obligation.param_env.caller_bounds().iter().filter_map(|p|
p.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))]
261 fn assemble_candidates_from_caller_bounds<'o>(
262 &mut self,
263 stack: &TraitObligationStack<'o, 'tcx>,
264 candidates: &mut SelectionCandidateSet<'tcx>,
265 ) -> Result<(), SelectionError<'tcx>> {
266 debug!(?stack.obligation);
267
268 let bounds = stack
269 .obligation
270 .param_env
271 .caller_bounds()
272 .iter()
273 .filter_map(|p| p.as_trait_clause())
274 .filter(|p| p.polarity() == stack.obligation.predicate.polarity());
276
277 let drcx = DeepRejectCtxt::relate_rigid_rigid(self.tcx());
278 let obligation_args = stack.obligation.predicate.skip_binder().trait_ref.args;
279 for bound in bounds {
281 let bound =
282 util::lazily_elaborate_sizedness_candidate(self.infcx, stack.obligation, bound);
283
284 if bound.def_id() != stack.obligation.predicate.def_id() {
286 continue;
287 }
288
289 let bound_trait_ref = bound.map_bound(|t| t.trait_ref);
290 if !drcx.args_may_unify(obligation_args, bound_trait_ref.skip_binder().args) {
291 continue;
292 }
293 let wc = self.where_clause_may_apply(stack, bound_trait_ref)?;
294 if wc.may_apply() {
295 candidates.vec.push(ParamCandidate(bound));
296 }
297 }
298
299 Ok(())
300 }
301
302 fn assemble_coroutine_candidates(
303 &mut self,
304 obligation: &PolyTraitObligation<'tcx>,
305 candidates: &mut SelectionCandidateSet<'tcx>,
306 ) {
307 let self_ty = obligation.self_ty().skip_binder();
311 match self_ty.kind() {
312 ty::Coroutine(did, ..) if self.tcx().is_general_coroutine(*did) => {
315 {
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:315",
"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(315u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message", "self_ty",
"obligation"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("assemble_coroutine_candidates")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&self_ty) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligation)
as &dyn Value))])
});
} else { ; }
};debug!(?self_ty, ?obligation, "assemble_coroutine_candidates",);
316
317 candidates.vec.push(CoroutineCandidate);
318 }
319 ty::Infer(ty::TyVar(_)) => {
320 {
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:320",
"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(320u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("assemble_coroutine_candidates: ambiguous self-type")
as &dyn Value))])
});
} else { ; }
};debug!("assemble_coroutine_candidates: ambiguous self-type");
321 candidates.ambiguous = true;
322 }
323 _ => {}
324 }
325 }
326
327 fn assemble_future_candidates(
328 &mut self,
329 obligation: &PolyTraitObligation<'tcx>,
330 candidates: &mut SelectionCandidateSet<'tcx>,
331 ) {
332 let self_ty = obligation.self_ty().skip_binder();
333 if let ty::Coroutine(did, ..) = self_ty.kind() {
334 if self.tcx().coroutine_is_async(*did) {
337 {
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:337",
"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(337u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message", "self_ty",
"obligation"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("assemble_future_candidates")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&self_ty) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligation)
as &dyn Value))])
});
} else { ; }
};debug!(?self_ty, ?obligation, "assemble_future_candidates",);
338
339 candidates.vec.push(FutureCandidate);
340 }
341 }
342 }
343
344 fn assemble_iterator_candidates(
345 &mut self,
346 obligation: &PolyTraitObligation<'tcx>,
347 candidates: &mut SelectionCandidateSet<'tcx>,
348 ) {
349 let self_ty = obligation.self_ty().skip_binder();
350 if let ty::Coroutine(did, ..) = self_ty.kind()
353 && self.tcx().coroutine_is_gen(*did)
354 {
355 {
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:355",
"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(355u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message", "self_ty",
"obligation"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("assemble_iterator_candidates")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&self_ty) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligation)
as &dyn Value))])
});
} else { ; }
};debug!(?self_ty, ?obligation, "assemble_iterator_candidates",);
356
357 candidates.vec.push(IteratorCandidate);
358 }
359 }
360
361 fn assemble_fused_iterator_candidates(
362 &mut self,
363 obligation: &PolyTraitObligation<'tcx>,
364 candidates: &mut SelectionCandidateSet<'tcx>,
365 ) {
366 if self.coroutine_is_gen(obligation.self_ty().skip_binder()) {
367 candidates.vec.push(BuiltinCandidate);
368 }
369 }
370
371 fn assemble_async_iterator_candidates(
372 &mut self,
373 obligation: &PolyTraitObligation<'tcx>,
374 candidates: &mut SelectionCandidateSet<'tcx>,
375 ) {
376 let self_ty = obligation.self_ty().skip_binder();
377 if let ty::Coroutine(did, args) = *self_ty.kind() {
378 if self.tcx().coroutine_is_async_gen(did) {
381 {
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:381",
"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(381u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message", "self_ty",
"obligation"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("assemble_iterator_candidates")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&self_ty) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligation)
as &dyn Value))])
});
} else { ; }
};debug!(?self_ty, ?obligation, "assemble_iterator_candidates",);
382
383 let ty::Adt(_poll_def, args) = *args.as_coroutine().yield_ty().kind() else {
386 candidates.ambiguous = true;
387 return;
388 };
389 let ty::Adt(_option_def, _) = *args.type_at(0).kind() else {
390 candidates.ambiguous = true;
391 return;
392 };
393
394 candidates.vec.push(AsyncIteratorCandidate);
395 }
396 }
397 }
398
399 fn assemble_closure_candidates(
406 &mut self,
407 obligation: &PolyTraitObligation<'tcx>,
408 candidates: &mut SelectionCandidateSet<'tcx>,
409 ) {
410 let kind = self.tcx().fn_trait_kind_from_def_id(obligation.predicate.def_id()).unwrap();
411
412 let self_ty = obligation.self_ty().skip_binder();
416 match *self_ty.kind() {
417 ty::Closure(def_id, _) => {
418 let is_const = self.tcx().is_const_fn(def_id);
419 {
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:419",
"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(419u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message", "kind",
"obligation"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("assemble_unboxed_candidates")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&kind) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligation)
as &dyn Value))])
});
} else { ; }
};debug!(?kind, ?obligation, "assemble_unboxed_candidates");
420 match self.infcx.closure_kind(self_ty) {
421 Some(closure_kind) => {
422 {
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:422",
"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(422u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message",
"closure_kind"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("assemble_unboxed_candidates")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&closure_kind)
as &dyn Value))])
});
} else { ; }
};debug!(?closure_kind, "assemble_unboxed_candidates");
423 if closure_kind.extends(kind) {
424 candidates.vec.push(ClosureCandidate { is_const });
425 }
426 }
427 None => {
428 if kind == ty::ClosureKind::FnOnce {
429 candidates.vec.push(ClosureCandidate { is_const });
430 } else {
431 candidates.ambiguous = true;
432 }
433 }
434 }
435 }
436 ty::CoroutineClosure(def_id, args) => {
437 let args = args.as_coroutine_closure();
438 let is_const = self.tcx().is_const_fn(def_id);
439 if let Some(closure_kind) = self.infcx.closure_kind(self_ty)
440 && !args.tupled_upvars_ty().is_ty_var()
442 {
443 if closure_kind.extends(kind) && !args.has_self_borrows() {
448 candidates.vec.push(ClosureCandidate { is_const });
449 } else if kind == ty::ClosureKind::FnOnce {
450 candidates.vec.push(ClosureCandidate { is_const });
451 }
452 } else if kind == ty::ClosureKind::FnOnce {
453 candidates.vec.push(ClosureCandidate { is_const });
454 } else {
455 candidates.ambiguous = true;
457 }
458 }
459 ty::Infer(ty::TyVar(_)) => {
460 {
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:460",
"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(460u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("assemble_unboxed_closure_candidates: ambiguous self-type")
as &dyn Value))])
});
} else { ; }
};debug!("assemble_unboxed_closure_candidates: ambiguous self-type");
461 candidates.ambiguous = true;
462 }
463 _ => {}
464 }
465 }
466
467 #[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(467u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["obligation"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn 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:476",
"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(476u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("self_ty = {0:?}",
obligation.self_ty().skip_binder().kind()) as &dyn 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:493",
"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(493u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["coroutine_kind"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&coroutine_kind)
as &dyn 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))]
468 fn assemble_async_closure_candidates(
469 &mut self,
470 obligation: &PolyTraitObligation<'tcx>,
471 candidates: &mut SelectionCandidateSet<'tcx>,
472 ) {
473 let goal_kind =
474 self.tcx().async_fn_trait_kind_from_def_id(obligation.predicate.def_id()).unwrap();
475
476 debug!("self_ty = {:?}", obligation.self_ty().skip_binder().kind());
477 match *obligation.self_ty().skip_binder().kind() {
478 ty::CoroutineClosure(def_id, args) => {
479 if let Some(closure_kind) =
480 args.as_coroutine_closure().kind_ty().to_opt_closure_kind()
481 && !closure_kind.extends(goal_kind)
482 {
483 return;
484 }
485
486 let Some(coroutine_kind) =
488 self.tcx().coroutine_kind(self.tcx().coroutine_for_closure(def_id))
489 else {
490 bug!("coroutine with no kind");
491 };
492
493 debug!(?coroutine_kind);
494 match coroutine_kind {
495 CoroutineKind::Desugared(CoroutineDesugaring::Async, _) => {
496 candidates.vec.push(AsyncClosureCandidate);
497 }
498 _ => (),
499 }
500 }
501 ty::Closure(_, args) => {
504 if let Some(closure_kind) = args.as_closure().kind_ty().to_opt_closure_kind()
505 && !closure_kind.extends(goal_kind)
506 {
507 return;
508 }
509 candidates.vec.push(AsyncClosureCandidate);
510 }
511 ty::FnPtr(sig_tys, hdr) => {
513 if sig_tys.with(hdr).is_fn_trait_compatible() {
514 candidates.vec.push(AsyncClosureCandidate);
515 }
516 }
517 ty::FnDef(def_id, _) => {
519 let tcx = self.tcx();
520 if tcx.fn_sig(def_id).skip_binder().is_fn_trait_compatible()
521 && tcx.codegen_fn_attrs(def_id).target_features.is_empty()
522 {
523 candidates.vec.push(AsyncClosureCandidate);
524 }
525 }
526 _ => {}
527 }
528 }
529
530 fn assemble_async_fn_kind_helper_candidates(
531 &mut self,
532 obligation: &PolyTraitObligation<'tcx>,
533 candidates: &mut SelectionCandidateSet<'tcx>,
534 ) {
535 let self_ty = obligation.self_ty().skip_binder();
536 let target_kind_ty = obligation.predicate.skip_binder().trait_ref.args.type_at(1);
537
538 if !(self_ty.is_integral() || self_ty.is_ty_var()) {
540 return;
541 }
542 if !(target_kind_ty.is_integral() || self_ty.is_ty_var()) {
543 return;
544 }
545
546 if let Some(closure_kind) = self_ty.to_opt_closure_kind()
549 && let Some(goal_kind) = target_kind_ty.to_opt_closure_kind()
550 && closure_kind.extends(goal_kind)
551 {
552 candidates.vec.push(AsyncFnKindHelperCandidate);
553 }
554 }
555
556 fn assemble_fn_pointer_candidates(
558 &mut self,
559 obligation: &PolyTraitObligation<'tcx>,
560 candidates: &mut SelectionCandidateSet<'tcx>,
561 ) {
562 let self_ty = obligation.self_ty().skip_binder();
567 match *self_ty.kind() {
568 ty::Infer(ty::TyVar(_)) => {
569 {
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:569",
"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(569u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("assemble_fn_pointer_candidates: ambiguous self-type")
as &dyn Value))])
});
} else { ; }
};debug!("assemble_fn_pointer_candidates: ambiguous self-type");
570 candidates.ambiguous = true; }
572 ty::FnPtr(sig_tys, hdr) => {
574 if sig_tys.with(hdr).is_fn_trait_compatible() {
575 candidates.vec.push(FnPointerCandidate);
576 }
577 }
578 ty::FnDef(def_id, _) => {
580 let tcx = self.tcx();
581 if tcx.fn_sig(def_id).skip_binder().is_fn_trait_compatible()
582 && tcx.codegen_fn_attrs(def_id).target_features.is_empty()
583 {
584 candidates.vec.push(FnPointerCandidate);
585 }
586 }
587 _ => {}
588 }
589 }
590
591 #[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(592u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["obligation"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn 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))]
593 fn assemble_candidates_from_impls(
594 &mut self,
595 obligation: &PolyTraitObligation<'tcx>,
596 candidates: &mut SelectionCandidateSet<'tcx>,
597 ) {
598 let drcx = DeepRejectCtxt::relate_rigid_infer(self.tcx());
599 let obligation_args = obligation.predicate.skip_binder().trait_ref.args;
600 self.tcx().for_each_relevant_impl(
601 obligation.predicate.def_id(),
602 obligation.predicate.skip_binder().trait_ref.self_ty(),
603 |impl_def_id| {
604 let impl_trait_header = self.tcx().impl_trait_header(impl_def_id);
608 if !drcx
609 .args_may_unify(obligation_args, impl_trait_header.trait_ref.skip_binder().args)
610 {
611 return;
612 }
613
614 if self.tcx().defaultness(impl_def_id).is_default() {
618 return;
619 }
620
621 if self.reject_fn_ptr_impls(
622 impl_def_id,
623 obligation,
624 impl_trait_header.trait_ref.skip_binder().self_ty(),
625 ) {
626 return;
627 }
628
629 self.infcx.probe(|_| {
630 if let Ok(_args) = self.match_impl(impl_def_id, impl_trait_header, obligation) {
631 candidates.vec.push(ImplCandidate(impl_def_id));
632 }
633 });
634 },
635 );
636 }
637
638 x;#[instrument(level = "trace", skip(self), ret)]
643 fn reject_fn_ptr_impls(
644 &mut self,
645 impl_def_id: DefId,
646 obligation: &PolyTraitObligation<'tcx>,
647 impl_self_ty: Ty<'tcx>,
648 ) -> bool {
649 if !matches!(impl_self_ty.kind(), ty::Param(..)) {
651 return false;
652 }
653 let Some(fn_ptr_trait) = self.tcx().lang_items().fn_ptr_trait() else {
654 return false;
655 };
656
657 for &(predicate, _) in self.tcx().predicates_of(impl_def_id).predicates {
658 let ty::ClauseKind::Trait(pred) = predicate.kind().skip_binder() else { continue };
659 if fn_ptr_trait != pred.trait_ref.def_id {
660 continue;
661 }
662 trace!(?pred);
663 if pred.self_ty() != impl_self_ty {
665 continue;
666 }
667
668 let self_ty = obligation.self_ty().skip_binder();
669 match self_ty.kind() {
670 ty::FnPtr(..) => return false,
673
674 ty::Placeholder(..)
676 | ty::Dynamic(_, _)
677 | ty::Alias(_, _)
678 | ty::Infer(_)
679 | ty::Param(..)
680 | ty::Bound(_, _) => {}
681
682 ty::Bool
685 | ty::Char
686 | ty::Int(_)
687 | ty::Uint(_)
688 | ty::Float(_)
689 | ty::Adt(_, _)
690 | ty::Foreign(_)
691 | ty::Str
692 | ty::Array(_, _)
693 | ty::Pat(_, _)
694 | ty::Slice(_)
695 | ty::RawPtr(_, _)
696 | ty::Ref(_, _, _)
697 | ty::Closure(..)
698 | ty::CoroutineClosure(..)
699 | ty::Coroutine(_, _)
700 | ty::CoroutineWitness(..)
701 | ty::UnsafeBinder(_)
702 | ty::Never
703 | ty::Tuple(_)
704 | ty::Error(_) => return true,
705 ty::FnDef(_, _) => return true,
708 }
709
710 let obligation = Obligation::new(
713 self.tcx(),
714 obligation.cause.clone(),
715 obligation.param_env,
716 self.tcx().mk_predicate(obligation.predicate.map_bound(|mut pred| {
717 pred.trait_ref =
718 ty::TraitRef::new(self.tcx(), fn_ptr_trait, [pred.trait_ref.self_ty()]);
719 ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred))
720 })),
721 );
722 if let Ok(r) = self.evaluate_root_obligation(&obligation) {
723 if !r.may_apply() {
724 return true;
725 }
726 }
727 }
728 false
729 }
730
731 fn assemble_candidates_from_auto_impls(
732 &mut self,
733 obligation: &PolyTraitObligation<'tcx>,
734 candidates: &mut SelectionCandidateSet<'tcx>,
735 ) {
736 let self_ty = obligation.self_ty().skip_binder();
738 {
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:738",
"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(738u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message",
"self_ty"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("assemble_candidates_from_auto_impls")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&self_ty) as
&dyn Value))])
});
} else { ; }
};debug!(?self_ty, "assemble_candidates_from_auto_impls");
739
740 let def_id = obligation.predicate.def_id();
741
742 let mut check_impls = || {
743 let mut has_impl = false;
753 self.tcx().for_each_relevant_impl(def_id, self_ty, |_| has_impl = true);
754 if !has_impl {
755 candidates.vec.push(AutoImplCandidate)
756 }
757 };
758
759 if self.tcx().trait_is_auto(def_id) {
760 match *self_ty.kind() {
761 ty::Dynamic(..) => {
762 }
767 ty::Foreign(..) => {
768 if self.tcx().is_default_trait(def_id) {
776 check_impls()
777 }
778 }
779 ty::Param(..)
780 | ty::Alias(ty::Projection | ty::Inherent | ty::Free, ..)
781 | ty::Placeholder(..)
782 | ty::Bound(..) => {
783 }
797 ty::Infer(ty::TyVar(_) | ty::IntVar(_) | ty::FloatVar(_)) => {
798 candidates.ambiguous = true;
800 }
801 ty::Coroutine(coroutine_def_id, _) => {
802 if self.tcx().is_lang_item(def_id, LangItem::Unpin) {
803 match self.tcx().coroutine_movability(coroutine_def_id) {
804 hir::Movability::Static => {
805 }
808 hir::Movability::Movable => {
809 candidates.vec.push(BuiltinCandidate);
812 }
813 }
814 } else {
815 if self.should_stall_coroutine(coroutine_def_id) {
816 candidates.ambiguous = true;
817 } else {
818 candidates.vec.push(AutoImplCandidate);
820 }
821 }
822 }
823
824 ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
825 ::rustc_middle::util::bug::bug_fmt(format_args!("asked to assemble auto trait candidates of unexpected type: {0:?}",
self_ty));bug!(
826 "asked to assemble auto trait candidates of unexpected type: {:?}",
827 self_ty
828 );
829 }
830
831 ty::Alias(ty::Opaque, alias) => {
832 if candidates.vec.iter().any(|c| #[allow(non_exhaustive_omitted_patterns)] match c {
ProjectionCandidate { .. } => true,
_ => false,
}matches!(c, ProjectionCandidate { .. })) {
833 } else if let TypingMode::Coherence = self.infcx.typing_mode() {
843 candidates.ambiguous = true;
846 } else if self.infcx.can_define_opaque_ty(alias.def_id) {
847 candidates.ambiguous = true;
851 } else {
852 candidates.vec.push(AutoImplCandidate)
853 }
854 }
855
856 ty::CoroutineWitness(..) => {
857 candidates.vec.push(AutoImplCandidate);
858 }
859
860 ty::Bool
861 | ty::Char
862 | ty::Int(_)
863 | ty::Uint(_)
864 | ty::Float(_)
865 | ty::Str
866 | ty::Array(_, _)
867 | ty::Pat(_, _)
868 | ty::Slice(_)
869 | ty::Adt(..)
870 | ty::RawPtr(_, _)
871 | ty::Ref(..)
872 | ty::FnDef(..)
873 | ty::FnPtr(..)
874 | ty::Closure(..)
875 | ty::CoroutineClosure(..)
876 | ty::Never
877 | ty::Tuple(_)
878 | ty::UnsafeBinder(_) => {
879 if self.tcx().trait_def(def_id).safety.is_unsafe()
882 && self_ty.has_unsafe_fields()
883 {
884 return;
885 }
886
887 check_impls();
888 }
889 ty::Error(_) => {
890 candidates.vec.push(AutoImplCandidate);
891 }
892 }
893 }
894 }
895
896 fn assemble_candidates_from_object_ty(
898 &mut self,
899 obligation: &PolyTraitObligation<'tcx>,
900 candidates: &mut SelectionCandidateSet<'tcx>,
901 ) {
902 {
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:902",
"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(902u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message",
"self_ty"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("assemble_candidates_from_object_ty")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&obligation.self_ty().skip_binder())
as &dyn Value))])
});
} else { ; }
};debug!(
903 self_ty = ?obligation.self_ty().skip_binder(),
904 "assemble_candidates_from_object_ty",
905 );
906
907 if self.tcx().is_sizedness_trait(obligation.predicate.def_id()) {
908 return;
911 }
912
913 self.infcx.probe(|_snapshot| {
914 let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
915 self.infcx.enter_forall(poly_trait_predicate, |placeholder_trait_predicate| {
916 let self_ty = placeholder_trait_predicate.self_ty();
917 let principal_trait_ref = match self_ty.kind() {
918 ty::Dynamic(data, ..) => {
919 if data.auto_traits().any(|did| did == obligation.predicate.def_id()) {
920 {
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:920",
"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(920u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("assemble_candidates_from_object_ty: matched builtin bound, pushing candidate")
as &dyn Value))])
});
} else { ; }
};debug!(
921 "assemble_candidates_from_object_ty: matched builtin bound, \
922 pushing candidate"
923 );
924 candidates.vec.push(BuiltinObjectCandidate);
925 return;
926 }
927
928 if let Some(principal) = data.principal() {
929 principal.with_self_ty(self.tcx(), self_ty)
930 } else {
931 return;
933 }
934 }
935 ty::Infer(ty::TyVar(_)) => {
936 {
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:936",
"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(936u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("assemble_candidates_from_object_ty: ambiguous")
as &dyn Value))])
});
} else { ; }
};debug!("assemble_candidates_from_object_ty: ambiguous");
937 candidates.ambiguous = true; return;
939 }
940 _ => return,
941 };
942
943 {
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:943",
"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(943u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message",
"principal_trait_ref"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("assemble_candidates_from_object_ty")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&principal_trait_ref)
as &dyn Value))])
});
} else { ; }
};debug!(?principal_trait_ref, "assemble_candidates_from_object_ty");
944
945 let candidate_supertraits = util::supertraits(self.tcx(), principal_trait_ref)
951 .enumerate()
952 .filter(|&(_, upcast_trait_ref)| {
953 self.infcx.probe(|_| {
954 self.match_normalize_trait_ref(
955 obligation,
956 placeholder_trait_predicate.trait_ref,
957 upcast_trait_ref,
958 )
959 .is_ok()
960 })
961 })
962 .map(|(idx, _)| ObjectCandidate(idx));
963
964 candidates.vec.extend(candidate_supertraits);
965 })
966 })
967 }
968
969 fn assemble_candidates_for_unsizing(
971 &mut self,
972 obligation: &PolyTraitObligation<'tcx>,
973 candidates: &mut SelectionCandidateSet<'tcx>,
974 ) {
975 let Some(trait_pred) = obligation.predicate.no_bound_vars() else {
990 return;
992 };
993 let source = trait_pred.self_ty();
994 let target = trait_pred.trait_ref.args.type_at(1);
995
996 {
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:996",
"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(996u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["message", "source",
"target"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("assemble_candidates_for_unsizing")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&source) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&target) as
&dyn Value))])
});
} else { ; }
};debug!(?source, ?target, "assemble_candidates_for_unsizing");
997
998 match (source.kind(), target.kind()) {
999 (&ty::Dynamic(a_data, a_region), &ty::Dynamic(b_data, b_region)) => {
1001 let principal_def_id_a = a_data.principal_def_id();
1013 let principal_def_id_b = b_data.principal_def_id();
1014 if principal_def_id_a == principal_def_id_b || principal_def_id_b.is_none() {
1015 let a_auto_traits: FxIndexSet<DefId> = a_data
1019 .auto_traits()
1020 .chain(principal_def_id_a.into_iter().flat_map(|principal_def_id| {
1021 elaborate::supertrait_def_ids(self.tcx(), principal_def_id)
1022 .filter(|def_id| self.tcx().trait_is_auto(*def_id))
1023 }))
1024 .collect();
1025 let auto_traits_compatible = b_data
1026 .auto_traits()
1027 .all(|b| a_auto_traits.contains(&b));
1029 if auto_traits_compatible {
1030 candidates.vec.push(BuiltinUnsizeCandidate);
1031 }
1032 } else if principal_def_id_a.is_some() && principal_def_id_b.is_some() {
1033 let principal_a = a_data.principal().unwrap();
1035 let target_trait_did = principal_def_id_b.unwrap();
1036 let source_trait_ref = principal_a.with_self_ty(self.tcx(), source);
1037
1038 for (idx, upcast_trait_ref) in
1039 util::supertraits(self.tcx(), source_trait_ref).enumerate()
1040 {
1041 self.infcx.probe(|_| {
1042 if upcast_trait_ref.def_id() == target_trait_did
1043 && let Ok(nested) = self.match_upcast_principal(
1044 obligation,
1045 upcast_trait_ref,
1046 a_data,
1047 b_data,
1048 a_region,
1049 b_region,
1050 )
1051 {
1052 if nested.is_none() {
1053 candidates.ambiguous = true;
1054 }
1055 candidates.vec.push(TraitUpcastingUnsizeCandidate(idx));
1056 }
1057 })
1058 }
1059 }
1060 }
1061
1062 (_, &ty::Dynamic(_, _)) => {
1064 candidates.vec.push(BuiltinUnsizeCandidate);
1065 }
1066
1067 (&ty::Infer(ty::TyVar(_)), _) | (_, &ty::Infer(ty::TyVar(_))) => {
1071 {
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:1071",
"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(1071u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("assemble_candidates_for_unsizing: ambiguous")
as &dyn Value))])
});
} else { ; }
};debug!("assemble_candidates_for_unsizing: ambiguous");
1072 candidates.ambiguous = true;
1073 }
1074
1075 (&ty::Array(..), &ty::Slice(_)) => {
1077 candidates.vec.push(BuiltinUnsizeCandidate);
1078 }
1079
1080 (&ty::Adt(def_id_a, _), &ty::Adt(def_id_b, _)) if def_id_a.is_struct() => {
1082 if def_id_a == def_id_b {
1083 candidates.vec.push(BuiltinUnsizeCandidate);
1084 }
1085 }
1086
1087 _ => {}
1088 };
1089 }
1090
1091 #[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(1091u32),
::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(&[]) })
} 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))]
1092 fn assemble_candidates_for_transmutability(
1093 &mut self,
1094 obligation: &PolyTraitObligation<'tcx>,
1095 candidates: &mut SelectionCandidateSet<'tcx>,
1096 ) {
1097 if obligation.predicate.has_non_region_param() {
1098 return;
1099 }
1100
1101 if obligation.has_non_region_infer() {
1102 candidates.ambiguous = true;
1103 return;
1104 }
1105
1106 candidates.vec.push(TransmutabilityCandidate);
1107 }
1108
1109 #[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(1109u32),
::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(&[]) })
} 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:1117",
"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(1117u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["self_ty"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&self_ty) as
&dyn 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))]
1110 fn assemble_candidates_for_trait_alias(
1111 &mut self,
1112 obligation: &PolyTraitObligation<'tcx>,
1113 candidates: &mut SelectionCandidateSet<'tcx>,
1114 ) {
1115 let self_ty = obligation.self_ty().skip_binder();
1117 debug!(?self_ty);
1118
1119 let def_id = obligation.predicate.def_id();
1120
1121 if self.tcx().is_trait_alias(def_id) {
1122 candidates.vec.push(TraitAliasCandidate);
1123 }
1124 }
1125
1126 #[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(1128u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["self_ty"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn 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))]
1129 fn assemble_builtin_copy_clone_candidate(
1130 &mut self,
1131 self_ty: Ty<'tcx>,
1132 candidates: &mut SelectionCandidateSet<'tcx>,
1133 ) {
1134 match *self_ty.kind() {
1135 ty::FnDef(..) | ty::FnPtr(..) | ty::Error(_) | ty::Tuple(..) | ty::Pat(..) => {
1138 candidates.vec.push(BuiltinCandidate);
1139 }
1140
1141 ty::Uint(_)
1143 | ty::Int(_)
1144 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
1145 | ty::Bool
1146 | ty::Float(_)
1147 | ty::Char
1148 | ty::RawPtr(..)
1149 | ty::Never
1150 | ty::Ref(_, _, hir::Mutability::Not)
1151 | ty::Array(..) => {}
1152
1153 ty::UnsafeBinder(_) => {}
1156
1157 ty::Dynamic(..) | ty::Str | ty::Slice(..) | ty::Foreign(..) => {}
1159
1160 ty::Ref(_, _, hir::Mutability::Mut) => {}
1162
1163 ty::Coroutine(coroutine_def_id, args) => {
1164 if self.should_stall_coroutine(coroutine_def_id) {
1165 candidates.ambiguous = true;
1166 return;
1167 }
1168
1169 match self.tcx().coroutine_movability(coroutine_def_id) {
1170 hir::Movability::Static => {}
1171 hir::Movability::Movable => {
1172 if self.tcx().features().coroutine_clone() {
1173 let resolved_upvars =
1174 self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty());
1175 if resolved_upvars.is_ty_var() {
1176 candidates.ambiguous = true;
1178 } else {
1179 candidates.vec.push(BuiltinCandidate);
1180 }
1181 }
1182 }
1183 }
1184 }
1185
1186 ty::Closure(_, args) => {
1187 let resolved_upvars =
1188 self.infcx.shallow_resolve(args.as_closure().tupled_upvars_ty());
1189 if resolved_upvars.is_ty_var() {
1190 candidates.ambiguous = true;
1192 } else {
1193 candidates.vec.push(BuiltinCandidate);
1194 }
1195 }
1196
1197 ty::CoroutineClosure(_, args) => {
1198 let resolved_upvars =
1199 self.infcx.shallow_resolve(args.as_coroutine_closure().tupled_upvars_ty());
1200 if resolved_upvars.is_ty_var() {
1201 candidates.ambiguous = true;
1203 } else {
1204 candidates.vec.push(BuiltinCandidate);
1205 }
1206 }
1207
1208 ty::CoroutineWitness(..) => {
1209 candidates.vec.push(SizedCandidate);
1210 }
1211
1212 ty::Adt(..) | ty::Alias(..) | ty::Param(..) | ty::Placeholder(..) => {}
1214
1215 ty::Infer(ty::TyVar(_)) => {
1216 candidates.ambiguous = true;
1217 }
1218
1219 ty::Bound(..) => {}
1221
1222 ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1223 bug!("asked to assemble builtin bounds of unexpected type: {:?}", self_ty);
1224 }
1225 }
1226 }
1227
1228 #[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(1229u32),
::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::select::candidate_assembly"),
::tracing_core::field::FieldSet::new(&["self_ty",
"sizedness"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&sizedness)
as &dyn 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))]
1230 fn assemble_builtin_sized_candidate(
1231 &mut self,
1232 self_ty: Ty<'tcx>,
1233 candidates: &mut SelectionCandidateSet<'tcx>,
1234 sizedness: SizedTraitKind,
1235 ) {
1236 match *self_ty.kind() {
1237 ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
1239 | ty::Uint(_)
1240 | ty::Int(_)
1241 | ty::Bool
1242 | ty::Float(_)
1243 | ty::FnDef(..)
1244 | ty::FnPtr(..)
1245 | ty::RawPtr(..)
1246 | ty::Char
1247 | ty::Ref(..)
1248 | ty::Array(..)
1249 | ty::Closure(..)
1250 | ty::CoroutineClosure(..)
1251 | ty::Never
1252 | ty::Error(_) => {
1253 candidates.vec.push(SizedCandidate);
1254 }
1255
1256 ty::Coroutine(coroutine_def_id, _) => {
1257 if self.should_stall_coroutine(coroutine_def_id) {
1258 candidates.ambiguous = true;
1259 } else {
1260 candidates.vec.push(SizedCandidate);
1261 }
1262 }
1263
1264 ty::CoroutineWitness(..) => {
1265 candidates.vec.push(SizedCandidate);
1266 }
1267
1268 ty::Tuple(..) | ty::Pat(..) | ty::Adt(..) | ty::UnsafeBinder(_) => {
1270 candidates.vec.push(SizedCandidate);
1271 }
1272
1273 ty::Str | ty::Slice(_) | ty::Dynamic(..) => match sizedness {
1275 SizedTraitKind::Sized => {}
1276 SizedTraitKind::MetaSized => {
1277 candidates.vec.push(SizedCandidate);
1278 }
1279 },
1280
1281 ty::Foreign(..) => {}
1283
1284 ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => {}
1285
1286 ty::Infer(ty::TyVar(_)) => {
1287 candidates.ambiguous = true;
1288 }
1289
1290 ty::Bound(..) => {}
1292
1293 ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1294 bug!("asked to assemble builtin bounds of unexpected type: {:?}", self_ty);
1295 }
1296 }
1297 }
1298
1299 fn assemble_const_destruct_candidates(
1300 &mut self,
1301 _obligation: &PolyTraitObligation<'tcx>,
1302 candidates: &mut SelectionCandidateSet<'tcx>,
1303 ) {
1304 candidates.vec.push(BuiltinCandidate);
1305 }
1306
1307 fn assemble_candidate_for_tuple(
1308 &mut self,
1309 obligation: &PolyTraitObligation<'tcx>,
1310 candidates: &mut SelectionCandidateSet<'tcx>,
1311 ) {
1312 let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder());
1313 match self_ty.kind() {
1314 ty::Tuple(_) => {
1315 candidates.vec.push(BuiltinCandidate);
1316 }
1317 ty::Infer(ty::TyVar(_)) => {
1318 candidates.ambiguous = true;
1319 }
1320 ty::Bool
1321 | ty::Char
1322 | ty::Int(_)
1323 | ty::Uint(_)
1324 | ty::Float(_)
1325 | ty::Adt(_, _)
1326 | ty::Foreign(_)
1327 | ty::Str
1328 | ty::Array(_, _)
1329 | ty::Slice(_)
1330 | ty::RawPtr(_, _)
1331 | ty::Ref(_, _, _)
1332 | ty::FnDef(_, _)
1333 | ty::Pat(_, _)
1334 | ty::FnPtr(..)
1335 | ty::UnsafeBinder(_)
1336 | ty::Dynamic(_, _)
1337 | ty::Closure(..)
1338 | ty::CoroutineClosure(..)
1339 | ty::Coroutine(_, _)
1340 | ty::CoroutineWitness(..)
1341 | ty::Never
1342 | ty::Alias(..)
1343 | ty::Param(_)
1344 | ty::Bound(_, _)
1345 | ty::Error(_)
1346 | ty::Infer(_)
1347 | ty::Placeholder(_) => {}
1348 }
1349 }
1350
1351 fn assemble_candidates_for_fn_ptr_trait(
1352 &mut self,
1353 obligation: &PolyTraitObligation<'tcx>,
1354 candidates: &mut SelectionCandidateSet<'tcx>,
1355 ) {
1356 let self_ty = self.infcx.resolve_vars_if_possible(obligation.self_ty());
1357
1358 match self_ty.skip_binder().kind() {
1359 ty::FnPtr(..) => candidates.vec.push(BuiltinCandidate),
1360 ty::Bool
1361 | ty::Char
1362 | ty::Int(_)
1363 | ty::Uint(_)
1364 | ty::Float(_)
1365 | ty::Adt(..)
1366 | ty::Foreign(..)
1367 | ty::Str
1368 | ty::Array(..)
1369 | ty::Pat(..)
1370 | ty::Slice(_)
1371 | ty::RawPtr(_, _)
1372 | ty::Ref(..)
1373 | ty::FnDef(..)
1374 | ty::Placeholder(..)
1375 | ty::Dynamic(..)
1376 | ty::Closure(..)
1377 | ty::CoroutineClosure(..)
1378 | ty::Coroutine(..)
1379 | ty::CoroutineWitness(..)
1380 | ty::UnsafeBinder(_)
1381 | ty::Never
1382 | ty::Tuple(..)
1383 | ty::Alias(..)
1384 | ty::Param(..)
1385 | ty::Bound(..)
1386 | ty::Error(_)
1387 | ty::Infer(
1388 ty::InferTy::IntVar(_)
1389 | ty::InferTy::FloatVar(_)
1390 | ty::InferTy::FreshIntTy(_)
1391 | ty::InferTy::FreshFloatTy(_),
1392 ) => {}
1393 ty::Infer(ty::InferTy::TyVar(_) | ty::InferTy::FreshTy(_)) => {
1394 candidates.ambiguous = true;
1395 }
1396 }
1397 }
1398
1399 fn assemble_candidates_for_bikeshed_guaranteed_no_drop_trait(
1400 &mut self,
1401 obligation: &PolyTraitObligation<'tcx>,
1402 candidates: &mut SelectionCandidateSet<'tcx>,
1403 ) {
1404 match obligation.predicate.self_ty().skip_binder().kind() {
1405 ty::Ref(..)
1406 | ty::Adt(..)
1407 | ty::Tuple(_)
1408 | ty::Array(..)
1409 | ty::FnDef(..)
1410 | ty::FnPtr(..)
1411 | ty::Error(_)
1412 | ty::Uint(_)
1413 | ty::Int(_)
1414 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
1415 | ty::Bool
1416 | ty::Float(_)
1417 | ty::Char
1418 | ty::RawPtr(..)
1419 | ty::Never
1420 | ty::Pat(..)
1421 | ty::Dynamic(..)
1422 | ty::Str
1423 | ty::Slice(_)
1424 | ty::Foreign(..)
1425 | ty::Alias(..)
1426 | ty::Param(_)
1427 | ty::Placeholder(..)
1428 | ty::Closure(..)
1429 | ty::CoroutineClosure(..)
1430 | ty::Coroutine(..)
1431 | ty::UnsafeBinder(_)
1432 | ty::CoroutineWitness(..)
1433 | ty::Bound(..) => {
1434 candidates.vec.push(BikeshedGuaranteedNoDropCandidate);
1435 }
1436
1437 ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1438 candidates.ambiguous = true;
1439 }
1440 }
1441 }
1442}