1use std::ops::ControlFlow;
10
11use hir::LangItem;
12use hir::def_id::DefId;
13use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
14use rustc_hir::{self as hir, CoroutineDesugaring, CoroutineKind};
15use rustc_infer::traits::{Obligation, PolyTraitObligation, PredicateObligation, SelectionError};
16use rustc_middle::ty::fast_reject::DeepRejectCtxt;
17use rustc_middle::ty::{
18 self, FieldInfo, SizedTraitKind, TraitRef, Ty, TypeVisitableExt, elaborate,
19};
20use rustc_middle::{bug, span_bug};
21use rustc_span::DUMMY_SP;
22use tracing::{debug, instrument, trace};
23
24use super::SelectionCandidate::*;
25use super::{SelectionCandidateSet, SelectionContext, TraitObligationStack};
26use crate::traits::query::evaluate_obligation::InferCtxtExt;
27use crate::traits::util;
28
29impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
30 #[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(30u32),
::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:44",
"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(44u32),
::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:75",
"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(75u32),
::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);
}
Some(LangItem::Field) => {
self.assemble_candidates_for_field_trait(obligation,
&mut candidates);
}
_ => {
match lang_item {
Some(LangItem::Coroutine) => {
self.assemble_coroutine_candidates(obligation,
&mut candidates);
}
Some(LangItem::Future) => {
self.assemble_future_candidates(obligation,
&mut candidates);
}
Some(LangItem::Iterator) => {
self.assemble_iterator_candidates(obligation,
&mut candidates);
}
Some(LangItem::FusedIterator) => {
self.assemble_fused_iterator_candidates(obligation,
&mut candidates);
}
Some(LangItem::AsyncIterator) => {
self.assemble_async_iterator_candidates(obligation,
&mut candidates);
}
Some(LangItem::AsyncFnKindHelper) => {
self.assemble_async_fn_kind_helper_candidates(obligation,
&mut candidates);
}
Some(LangItem::AsyncFn | LangItem::AsyncFnMut |
LangItem::AsyncFnOnce) => {
self.assemble_async_closure_candidates(obligation,
&mut candidates);
}
Some(LangItem::Fn | LangItem::FnMut | LangItem::FnOnce) => {
self.assemble_closure_candidates(obligation,
&mut candidates);
self.assemble_fn_pointer_candidates(obligation,
&mut candidates);
}
_ => {}
}
self.assemble_candidates_from_impls(obligation,
&mut candidates);
self.assemble_candidates_from_object_ty(obligation,
&mut candidates);
}
}
self.assemble_candidates_from_projected_tys(obligation,
&mut candidates);
self.assemble_candidates_from_caller_bounds(stack,
&mut candidates)?;
self.assemble_candidates_from_auto_impls(obligation,
&mut candidates);
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs:183",
"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(183u32),
::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")]
31 pub(super) fn assemble_candidates<'o>(
32 &mut self,
33 stack: &TraitObligationStack<'o, 'tcx>,
34 ) -> Result<SelectionCandidateSet<'tcx>, SelectionError<'tcx>> {
35 let TraitObligationStack { obligation, .. } = *stack;
36 let obligation = &Obligation {
37 param_env: obligation.param_env,
38 cause: obligation.cause.clone(),
39 recursion_depth: obligation.recursion_depth,
40 predicate: self.infcx.resolve_vars_if_possible(obligation.predicate),
41 };
42
43 if obligation.predicate.skip_binder().self_ty().is_ty_var() {
44 debug!(ty = ?obligation.predicate.skip_binder().self_ty(), "ambiguous inference var or opaque type");
45 return Ok(SelectionCandidateSet { vec: vec![], ambiguous: true });
55 }
56
57 let mut candidates = SelectionCandidateSet { vec: Vec::new(), ambiguous: false };
58
59 if obligation.polarity() == ty::PredicatePolarity::Negative {
61 self.assemble_candidates_for_trait_alias(obligation, &mut candidates);
62 self.assemble_candidates_from_impls(obligation, &mut candidates);
63 self.assemble_candidates_from_caller_bounds(stack, &mut candidates)?;
64 } else {
65 self.assemble_candidates_for_trait_alias(obligation, &mut candidates);
66
67 let def_id = obligation.predicate.def_id();
70 let tcx = self.tcx();
71
72 let lang_item = tcx.as_lang_item(def_id);
73 match lang_item {
74 Some(LangItem::Copy | LangItem::Clone | LangItem::TrivialClone) => {
75 debug!(obligation_self_ty = ?obligation.predicate.skip_binder().self_ty());
76
77 self.assemble_candidates_from_impls(obligation, &mut candidates);
80
81 self.assemble_builtin_copy_clone_candidate(
83 obligation.predicate.self_ty().skip_binder(),
84 &mut candidates,
85 );
86 }
87 Some(LangItem::DiscriminantKind) => {
88 candidates.vec.push(BuiltinCandidate);
90 }
91 Some(LangItem::PointeeTrait) => {
92 candidates.vec.push(BuiltinCandidate);
94 }
95 Some(LangItem::Sized) => {
96 self.assemble_builtin_sized_candidate(
97 obligation.predicate.self_ty().skip_binder(),
98 &mut candidates,
99 SizedTraitKind::Sized,
100 );
101 }
102 Some(LangItem::MetaSized) => {
103 self.assemble_builtin_sized_candidate(
104 obligation.predicate.self_ty().skip_binder(),
105 &mut candidates,
106 SizedTraitKind::MetaSized,
107 );
108 }
109 Some(LangItem::PointeeSized) => {
110 bug!("`PointeeSized` is removed during lowering");
111 }
112 Some(LangItem::Unsize) => {
113 self.assemble_candidates_for_unsizing(obligation, &mut candidates);
114 }
115 Some(LangItem::Destruct) => {
116 self.assemble_const_destruct_candidates(obligation, &mut candidates);
117 }
118 Some(LangItem::TransmuteTrait) => {
119 self.assemble_candidates_from_impls(obligation, &mut candidates);
121 self.assemble_candidates_for_transmutability(obligation, &mut candidates);
122 }
123 Some(LangItem::Tuple) => {
124 self.assemble_candidate_for_tuple(obligation, &mut candidates);
125 }
126 Some(LangItem::FnPtrTrait) => {
127 self.assemble_candidates_for_fn_ptr_trait(obligation, &mut candidates);
128 }
129 Some(LangItem::BikeshedGuaranteedNoDrop) => {
130 self.assemble_candidates_for_bikeshed_guaranteed_no_drop_trait(
131 obligation,
132 &mut candidates,
133 );
134 }
135 Some(LangItem::Field) => {
136 self.assemble_candidates_for_field_trait(obligation, &mut candidates);
137 }
138 _ => {
139 match lang_item {
143 Some(LangItem::Coroutine) => {
144 self.assemble_coroutine_candidates(obligation, &mut candidates);
145 }
146 Some(LangItem::Future) => {
147 self.assemble_future_candidates(obligation, &mut candidates);
148 }
149 Some(LangItem::Iterator) => {
150 self.assemble_iterator_candidates(obligation, &mut candidates);
151 }
152 Some(LangItem::FusedIterator) => {
153 self.assemble_fused_iterator_candidates(obligation, &mut candidates);
154 }
155 Some(LangItem::AsyncIterator) => {
156 self.assemble_async_iterator_candidates(obligation, &mut candidates);
157 }
158 Some(LangItem::AsyncFnKindHelper) => {
159 self.assemble_async_fn_kind_helper_candidates(
160 obligation,
161 &mut candidates,
162 );
163 }
164 Some(LangItem::AsyncFn | LangItem::AsyncFnMut | LangItem::AsyncFnOnce) => {
165 self.assemble_async_closure_candidates(obligation, &mut candidates);
166 }
167 Some(LangItem::Fn | LangItem::FnMut | LangItem::FnOnce) => {
168 self.assemble_closure_candidates(obligation, &mut candidates);
169 self.assemble_fn_pointer_candidates(obligation, &mut candidates);
170 }
171 _ => {}
172 }
173
174 self.assemble_candidates_from_impls(obligation, &mut candidates);
175 self.assemble_candidates_from_object_ty(obligation, &mut candidates);
176 }
177 }
178
179 self.assemble_candidates_from_projected_tys(obligation, &mut candidates);
180 self.assemble_candidates_from_caller_bounds(stack, &mut candidates)?;
181 self.assemble_candidates_from_auto_impls(obligation, &mut candidates);
182 }
183 debug!("candidate list size: {}", candidates.vec.len());
184 Ok(candidates)
185 }
186
187 #[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(187u32),
::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::AliasTy {
kind: ty::Projection { .. } | ty::Opaque { .. }, .. }) => {}
ty::Infer(ty::TyVar(_)) => {
::rustc_middle::util::bug::span_bug_fmt(obligation.cause.span,
format_args!("Self=_ should have been handled by assemble_candidates"));
}
_ => return,
}
self.infcx.probe(|_|
{
let poly_trait_predicate =
self.infcx.resolve_vars_if_possible(obligation.predicate);
let placeholder_trait_predicate =
self.infcx.enter_forall_and_leak_universe(poly_trait_predicate);
let mut distinct_normalized_bounds = FxHashSet::default();
let _ =
self.for_each_item_bound::<!>(placeholder_trait_predicate.self_ty(),
|selcx, bound, idx, alias_bound_kind|
{
let Some(bound) =
bound.as_trait_clause() else {
return ControlFlow::Continue(());
};
if bound.polarity() != placeholder_trait_predicate.polarity
{
return ControlFlow::Continue(());
}
selcx.infcx.probe(|_|
{
let bound =
util::lazily_elaborate_sizedness_candidate(selcx.infcx,
obligation, bound);
match selcx.match_normalize_trait_ref(obligation,
placeholder_trait_predicate.trait_ref,
bound.map_bound(|pred| pred.trait_ref)) {
Ok(None) => {
candidates.vec.push(ProjectionCandidate {
idx,
kind: alias_bound_kind,
});
}
Ok(Some(normalized_trait)) if
distinct_normalized_bounds.insert(normalized_trait) => {
candidates.vec.push(ProjectionCandidate {
idx,
kind: alias_bound_kind,
});
}
_ => {}
}
});
ControlFlow::Continue(())
}, || candidates.ambiguous = true);
});
}
}
}#[instrument(level = "debug", skip(self, candidates))]
188 fn assemble_candidates_from_projected_tys(
189 &mut self,
190 obligation: &PolyTraitObligation<'tcx>,
191 candidates: &mut SelectionCandidateSet<'tcx>,
192 ) {
193 match obligation.predicate.skip_binder().trait_ref.self_ty().kind() {
196 ty::Alias(_, ty::AliasTy { kind: ty::Projection { .. } | ty::Opaque { .. }, .. }) => {}
198 ty::Infer(ty::TyVar(_)) => {
199 span_bug!(
200 obligation.cause.span,
201 "Self=_ should have been handled by assemble_candidates"
202 );
203 }
204 _ => return,
205 }
206
207 self.infcx.probe(|_| {
208 let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
209 let placeholder_trait_predicate =
210 self.infcx.enter_forall_and_leak_universe(poly_trait_predicate);
211
212 let mut distinct_normalized_bounds = FxHashSet::default();
216 let _ = self.for_each_item_bound::<!>(
217 placeholder_trait_predicate.self_ty(),
218 |selcx, bound, idx, alias_bound_kind| {
219 let Some(bound) = bound.as_trait_clause() else {
220 return ControlFlow::Continue(());
221 };
222 if bound.polarity() != placeholder_trait_predicate.polarity {
223 return ControlFlow::Continue(());
224 }
225
226 selcx.infcx.probe(|_| {
227 let bound = util::lazily_elaborate_sizedness_candidate(
228 selcx.infcx,
229 obligation,
230 bound,
231 );
232
233 match selcx.match_normalize_trait_ref(
235 obligation,
236 placeholder_trait_predicate.trait_ref,
237 bound.map_bound(|pred| pred.trait_ref),
238 ) {
239 Ok(None) => {
240 candidates
241 .vec
242 .push(ProjectionCandidate { idx, kind: alias_bound_kind });
243 }
244 Ok(Some(normalized_trait))
245 if distinct_normalized_bounds.insert(normalized_trait) =>
246 {
247 candidates
248 .vec
249 .push(ProjectionCandidate { idx, kind: alias_bound_kind });
250 }
251 _ => {}
252 }
253 });
254
255 ControlFlow::Continue(())
256 },
257 || candidates.ambiguous = true,
259 );
260 });
261 }
262
263 #[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(267u32),
::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:273",
"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(273u32),
::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))]
268 fn assemble_candidates_from_caller_bounds<'o>(
269 &mut self,
270 stack: &TraitObligationStack<'o, 'tcx>,
271 candidates: &mut SelectionCandidateSet<'tcx>,
272 ) -> Result<(), SelectionError<'tcx>> {
273 debug!(?stack.obligation);
274
275 let bounds = stack
276 .obligation
277 .param_env
278 .caller_bounds()
279 .iter()
280 .filter_map(|p| p.as_trait_clause())
281 .filter(|p| p.polarity() == stack.obligation.predicate.polarity());
283
284 let drcx = DeepRejectCtxt::relate_rigid_rigid(self.tcx());
285 let obligation_args = stack.obligation.predicate.skip_binder().trait_ref.args;
286 for bound in bounds {
288 let bound =
289 util::lazily_elaborate_sizedness_candidate(self.infcx, stack.obligation, bound);
290
291 if bound.def_id() != stack.obligation.predicate.def_id() {
293 continue;
294 }
295
296 let bound_trait_ref = bound.map_bound(|t| t.trait_ref);
297 if !drcx.args_may_unify(obligation_args, bound_trait_ref.skip_binder().args) {
298 continue;
299 }
300 let wc = self.where_clause_may_apply(stack, bound_trait_ref)?;
301 if wc.may_apply() {
302 candidates.vec.push(ParamCandidate(bound));
303 }
304 }
305
306 Ok(())
307 }
308
309 fn assemble_coroutine_candidates(
310 &mut self,
311 obligation: &PolyTraitObligation<'tcx>,
312 candidates: &mut SelectionCandidateSet<'tcx>,
313 ) {
314 let self_ty = obligation.self_ty().skip_binder();
318 match self_ty.kind() {
319 ty::Coroutine(did, ..) if self.tcx().is_general_coroutine(*did) => {
322 {
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:322",
"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(322u32),
::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");
323
324 candidates.vec.push(CoroutineCandidate);
325 }
326 ty::Infer(ty::TyVar(_)) => {
327 {
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:327",
"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(327u32),
::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");
328 candidates.ambiguous = true;
329 }
330 _ => {}
331 }
332 }
333
334 fn assemble_future_candidates(
335 &mut self,
336 obligation: &PolyTraitObligation<'tcx>,
337 candidates: &mut SelectionCandidateSet<'tcx>,
338 ) {
339 let self_ty = obligation.self_ty().skip_binder();
340 if let ty::Coroutine(did, ..) = self_ty.kind() {
341 if self.tcx().coroutine_is_async(*did) {
344 {
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:344",
"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(344u32),
::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");
345
346 candidates.vec.push(FutureCandidate);
347 }
348 }
349 }
350
351 fn assemble_iterator_candidates(
352 &mut self,
353 obligation: &PolyTraitObligation<'tcx>,
354 candidates: &mut SelectionCandidateSet<'tcx>,
355 ) {
356 let self_ty = obligation.self_ty().skip_binder();
357 if let ty::Coroutine(did, ..) = self_ty.kind()
360 && self.tcx().coroutine_is_gen(*did)
361 {
362 {
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:362",
"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(362u32),
::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");
363
364 candidates.vec.push(IteratorCandidate);
365 }
366 }
367
368 fn assemble_fused_iterator_candidates(
369 &mut self,
370 obligation: &PolyTraitObligation<'tcx>,
371 candidates: &mut SelectionCandidateSet<'tcx>,
372 ) {
373 if self.coroutine_is_gen(obligation.self_ty().skip_binder()) {
374 candidates.vec.push(BuiltinCandidate);
375 }
376 }
377
378 fn assemble_async_iterator_candidates(
379 &mut self,
380 obligation: &PolyTraitObligation<'tcx>,
381 candidates: &mut SelectionCandidateSet<'tcx>,
382 ) {
383 let self_ty = obligation.self_ty().skip_binder();
384 if let ty::Coroutine(did, args) = *self_ty.kind() {
385 if self.tcx().coroutine_is_async_gen(did) {
388 {
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:388",
"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(388u32),
::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");
389
390 let ty::Adt(_poll_def, args) = *args.as_coroutine().yield_ty().kind() else {
393 candidates.ambiguous = true;
394 return;
395 };
396 let ty::Adt(_option_def, _) = *args.type_at(0).kind() else {
397 candidates.ambiguous = true;
398 return;
399 };
400
401 candidates.vec.push(AsyncIteratorCandidate);
402 }
403 }
404 }
405
406 fn assemble_closure_candidates(
413 &mut self,
414 obligation: &PolyTraitObligation<'tcx>,
415 candidates: &mut SelectionCandidateSet<'tcx>,
416 ) {
417 let kind = self.tcx().fn_trait_kind_from_def_id(obligation.predicate.def_id()).unwrap();
418
419 let self_ty = obligation.self_ty().skip_binder();
423 match *self_ty.kind() {
424 ty::Closure(def_id, _) => {
425 let is_const = self.tcx().is_const_fn(def_id);
426 {
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:426",
"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(426u32),
::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");
427 match self.infcx.closure_kind(self_ty) {
428 Some(closure_kind) => {
429 {
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:429",
"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(429u32),
::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");
430 if closure_kind.extends(kind) {
431 candidates.vec.push(ClosureCandidate { is_const });
432 }
433 }
434 None => {
435 if kind == ty::ClosureKind::FnOnce {
436 candidates.vec.push(ClosureCandidate { is_const });
437 } else {
438 candidates.ambiguous = true;
439 }
440 }
441 }
442 }
443 ty::CoroutineClosure(def_id, args) => {
444 let args = args.as_coroutine_closure();
445 let is_const = self.tcx().is_const_fn(def_id);
446 if let Some(closure_kind) = self.infcx.closure_kind(self_ty)
447 && !args.tupled_upvars_ty().is_ty_var()
449 {
450 if closure_kind.extends(kind) && !args.has_self_borrows() {
455 candidates.vec.push(ClosureCandidate { is_const });
456 } else if kind == ty::ClosureKind::FnOnce {
457 candidates.vec.push(ClosureCandidate { is_const });
458 }
459 } else if kind == ty::ClosureKind::FnOnce {
460 candidates.vec.push(ClosureCandidate { is_const });
461 } else {
462 candidates.ambiguous = true;
464 }
465 }
466 ty::Infer(ty::TyVar(_)) => {
467 {
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:467",
"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(&["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");
468 candidates.ambiguous = true;
469 }
470 _ => {}
471 }
472 }
473
474 #[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(474u32),
::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:483",
"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(483u32),
::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:500",
"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(500u32),
::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))]
475 fn assemble_async_closure_candidates(
476 &mut self,
477 obligation: &PolyTraitObligation<'tcx>,
478 candidates: &mut SelectionCandidateSet<'tcx>,
479 ) {
480 let goal_kind =
481 self.tcx().async_fn_trait_kind_from_def_id(obligation.predicate.def_id()).unwrap();
482
483 debug!("self_ty = {:?}", obligation.self_ty().skip_binder().kind());
484 match *obligation.self_ty().skip_binder().kind() {
485 ty::CoroutineClosure(def_id, args) => {
486 if let Some(closure_kind) =
487 args.as_coroutine_closure().kind_ty().to_opt_closure_kind()
488 && !closure_kind.extends(goal_kind)
489 {
490 return;
491 }
492
493 let Some(coroutine_kind) =
495 self.tcx().coroutine_kind(self.tcx().coroutine_for_closure(def_id))
496 else {
497 bug!("coroutine with no kind");
498 };
499
500 debug!(?coroutine_kind);
501 match coroutine_kind {
502 CoroutineKind::Desugared(CoroutineDesugaring::Async, _) => {
503 candidates.vec.push(AsyncClosureCandidate);
504 }
505 _ => (),
506 }
507 }
508 ty::Closure(_, args) => {
511 if let Some(closure_kind) = args.as_closure().kind_ty().to_opt_closure_kind()
512 && !closure_kind.extends(goal_kind)
513 {
514 return;
515 }
516 candidates.vec.push(AsyncClosureCandidate);
517 }
518 ty::FnPtr(sig_tys, hdr) => {
520 if sig_tys.with(hdr).is_fn_trait_compatible() {
521 candidates.vec.push(AsyncClosureCandidate);
522 }
523 }
524 ty::FnDef(def_id, _) => {
526 let tcx = self.tcx();
527 if tcx.fn_sig(def_id).skip_binder().is_fn_trait_compatible()
528 && tcx.codegen_fn_attrs(def_id).target_features.is_empty()
529 {
530 candidates.vec.push(AsyncClosureCandidate);
531 }
532 }
533 _ => {}
534 }
535 }
536
537 fn assemble_async_fn_kind_helper_candidates(
538 &mut self,
539 obligation: &PolyTraitObligation<'tcx>,
540 candidates: &mut SelectionCandidateSet<'tcx>,
541 ) {
542 let self_ty = obligation.self_ty().skip_binder();
543 let target_kind_ty = obligation.predicate.skip_binder().trait_ref.args.type_at(1);
544
545 if !(self_ty.is_integral() || self_ty.is_ty_var()) {
547 return;
548 }
549 if !(target_kind_ty.is_integral() || self_ty.is_ty_var()) {
550 return;
551 }
552
553 if let Some(closure_kind) = self_ty.to_opt_closure_kind()
556 && let Some(goal_kind) = target_kind_ty.to_opt_closure_kind()
557 && closure_kind.extends(goal_kind)
558 {
559 candidates.vec.push(AsyncFnKindHelperCandidate);
560 }
561 }
562
563 fn assemble_fn_pointer_candidates(
565 &mut self,
566 obligation: &PolyTraitObligation<'tcx>,
567 candidates: &mut SelectionCandidateSet<'tcx>,
568 ) {
569 let self_ty = obligation.self_ty().skip_binder();
574 match *self_ty.kind() {
575 ty::Infer(ty::TyVar(_)) => {
576 {
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:576",
"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(576u32),
::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");
577 candidates.ambiguous = true; }
579 ty::FnPtr(sig_tys, hdr) => {
581 if sig_tys.with(hdr).is_fn_trait_compatible() {
582 candidates.vec.push(FnPointerCandidate);
583 }
584 }
585 ty::FnDef(def_id, _) => {
587 let tcx = self.tcx();
588 if tcx.fn_sig(def_id).skip_binder().is_fn_trait_compatible()
589 && tcx.codegen_fn_attrs(def_id).target_features.is_empty()
590 {
591 candidates.vec.push(FnPointerCandidate);
592 }
593 }
594 _ => {}
595 }
596 }
597
598 #[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(599u32),
::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))]
600 fn assemble_candidates_from_impls(
601 &mut self,
602 obligation: &PolyTraitObligation<'tcx>,
603 candidates: &mut SelectionCandidateSet<'tcx>,
604 ) {
605 let drcx = DeepRejectCtxt::relate_rigid_infer(self.tcx());
606 let obligation_args = obligation.predicate.skip_binder().trait_ref.args;
607 self.tcx().for_each_relevant_impl(
608 obligation.predicate.def_id(),
609 obligation.predicate.skip_binder().trait_ref.self_ty(),
610 |impl_def_id| {
611 let impl_trait_header = self.tcx().impl_trait_header(impl_def_id);
615 if !drcx
616 .args_may_unify(obligation_args, impl_trait_header.trait_ref.skip_binder().args)
617 {
618 return;
619 }
620
621 if self.tcx().defaultness(impl_def_id).is_default() {
625 return;
626 }
627
628 if self.reject_fn_ptr_impls(
629 impl_def_id,
630 obligation,
631 impl_trait_header.trait_ref.skip_binder().self_ty(),
632 ) {
633 return;
634 }
635
636 self.infcx.probe(|_| {
637 if let Ok(_args) = self.match_impl(impl_def_id, impl_trait_header, obligation) {
638 candidates.vec.push(ImplCandidate(impl_def_id));
639 }
640 });
641 },
642 );
643 }
644
645 x;#[instrument(level = "trace", skip(self), ret)]
650 fn reject_fn_ptr_impls(
651 &mut self,
652 impl_def_id: DefId,
653 obligation: &PolyTraitObligation<'tcx>,
654 impl_self_ty: Ty<'tcx>,
655 ) -> bool {
656 if !matches!(impl_self_ty.kind(), ty::Param(..)) {
658 return false;
659 }
660 let Some(fn_ptr_trait) = self.tcx().lang_items().fn_ptr_trait() else {
661 return false;
662 };
663
664 for &(predicate, _) in self.tcx().predicates_of(impl_def_id).predicates {
665 let ty::ClauseKind::Trait(pred) = predicate.kind().skip_binder() else { continue };
666 if fn_ptr_trait != pred.trait_ref.def_id {
667 continue;
668 }
669 trace!(?pred);
670 if pred.self_ty() != impl_self_ty {
672 continue;
673 }
674
675 let self_ty = obligation.self_ty().skip_binder();
676 match self_ty.kind() {
677 ty::FnPtr(..) => return false,
680
681 ty::Placeholder(..)
683 | ty::Dynamic(_, _)
684 | ty::Alias(_, _)
685 | ty::Infer(_)
686 | ty::Param(..)
687 | ty::Bound(_, _) => {}
688
689 ty::Bool
692 | ty::Char
693 | ty::Int(_)
694 | ty::Uint(_)
695 | ty::Float(_)
696 | ty::Adt(_, _)
697 | ty::Foreign(_)
698 | ty::Str
699 | ty::Array(_, _)
700 | ty::Pat(_, _)
701 | ty::Slice(_)
702 | ty::RawPtr(_, _)
703 | ty::Ref(_, _, _)
704 | ty::Closure(..)
705 | ty::CoroutineClosure(..)
706 | ty::Coroutine(_, _)
707 | ty::CoroutineWitness(..)
708 | ty::UnsafeBinder(_)
709 | ty::Never
710 | ty::Tuple(_)
711 | ty::Error(_) => return true,
712 ty::FnDef(_, _) => return true,
715 }
716
717 let obligation = Obligation::new(
720 self.tcx(),
721 obligation.cause.clone(),
722 obligation.param_env,
723 self.tcx().mk_predicate(obligation.predicate.map_bound(|mut pred| {
724 pred.trait_ref =
725 ty::TraitRef::new(self.tcx(), fn_ptr_trait, [pred.trait_ref.self_ty()]);
726 ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred))
727 })),
728 );
729 if let Ok(r) = self.evaluate_root_obligation(&obligation) {
730 if !r.may_apply() {
731 return true;
732 }
733 }
734 }
735 false
736 }
737
738 fn assemble_candidates_from_auto_impls(
739 &mut self,
740 obligation: &PolyTraitObligation<'tcx>,
741 candidates: &mut SelectionCandidateSet<'tcx>,
742 ) {
743 let self_ty = obligation.self_ty().skip_binder();
745 {
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:745",
"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(745u32),
::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");
746
747 let def_id = obligation.predicate.def_id();
748
749 let mut check_impls = || {
750 let mut has_impl = false;
760 self.tcx().for_each_relevant_impl(def_id, self_ty, |_| has_impl = true);
761 if !has_impl {
762 candidates.vec.push(AutoImplCandidate)
763 }
764 };
765
766 if self.tcx().trait_is_auto(def_id) {
767 match *self_ty.kind() {
768 ty::Dynamic(..) => {
769 }
774 ty::Foreign(..) => {
775 if self.tcx().is_default_trait(def_id) {
783 check_impls()
784 }
785 }
786 ty::Param(..)
787 | ty::Alias(
788 _,
789 ty::AliasTy {
790 kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. },
791 ..
792 },
793 )
794 | ty::Placeholder(..)
795 | ty::Bound(..) => {
796 }
810 ty::Infer(ty::TyVar(_) | ty::IntVar(_) | ty::FloatVar(_)) => {
811 candidates.ambiguous = true;
813 }
814 ty::Coroutine(coroutine_def_id, _) => {
815 if self.tcx().is_lang_item(def_id, LangItem::Unpin) {
816 match self.tcx().coroutine_movability(coroutine_def_id) {
817 hir::Movability::Static => {
818 }
821 hir::Movability::Movable => {
822 candidates.vec.push(BuiltinCandidate);
825 }
826 }
827 } else {
828 if self.should_stall_coroutine(coroutine_def_id) {
829 candidates.ambiguous = true;
830 } else {
831 candidates.vec.push(AutoImplCandidate);
833 }
834 }
835 }
836
837 ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
838 ::rustc_middle::util::bug::bug_fmt(format_args!("asked to assemble auto trait candidates of unexpected type: {0:?}",
self_ty));bug!(
839 "asked to assemble auto trait candidates of unexpected type: {:?}",
840 self_ty
841 );
842 }
843
844 ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => {
845 if candidates.vec.iter().any(|c| #[allow(non_exhaustive_omitted_patterns)] match c {
ProjectionCandidate { .. } => true,
_ => false,
}matches!(c, ProjectionCandidate { .. })) {
846 } else if self.typing_mode().is_coherence() {
856 candidates.ambiguous = true;
859 } else if self.infcx.can_define_opaque_ty(def_id) {
860 candidates.ambiguous = true;
864 } else {
865 candidates.vec.push(AutoImplCandidate)
866 }
867 }
868
869 ty::CoroutineWitness(..) => {
870 candidates.vec.push(AutoImplCandidate);
871 }
872
873 ty::Bool
874 | ty::Char
875 | ty::Int(_)
876 | ty::Uint(_)
877 | ty::Float(_)
878 | ty::Str
879 | ty::Array(_, _)
880 | ty::Pat(_, _)
881 | ty::Slice(_)
882 | ty::Adt(..)
883 | ty::RawPtr(_, _)
884 | ty::Ref(..)
885 | ty::FnDef(..)
886 | ty::FnPtr(..)
887 | ty::Closure(..)
888 | ty::CoroutineClosure(..)
889 | ty::Never
890 | ty::Tuple(_)
891 | ty::UnsafeBinder(_) => {
892 if self.tcx().trait_def(def_id).safety.is_unsafe()
895 && self_ty.has_unsafe_fields()
896 {
897 return;
898 }
899
900 check_impls();
901 }
902 ty::Error(_) => {
903 candidates.vec.push(AutoImplCandidate);
904 }
905 }
906 }
907 }
908
909 fn assemble_candidates_from_object_ty(
911 &mut self,
912 obligation: &PolyTraitObligation<'tcx>,
913 candidates: &mut SelectionCandidateSet<'tcx>,
914 ) {
915 {
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:915",
"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(915u32),
::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!(
916 self_ty = ?obligation.self_ty().skip_binder(),
917 "assemble_candidates_from_object_ty",
918 );
919
920 if self.tcx().is_sizedness_trait(obligation.predicate.def_id()) {
921 return;
924 }
925
926 self.infcx.probe(|_snapshot| {
927 let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
928 self.infcx.enter_forall(poly_trait_predicate, |placeholder_trait_predicate| {
929 let self_ty = placeholder_trait_predicate.self_ty();
930 let principal_trait_ref = match self_ty.kind() {
931 ty::Dynamic(data, ..) => {
932 if data.auto_traits().any(|did| did == obligation.predicate.def_id()) {
933 {
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:933",
"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(933u32),
::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!(
934 "assemble_candidates_from_object_ty: matched builtin bound, \
935 pushing candidate"
936 );
937 candidates.vec.push(BuiltinObjectCandidate);
938 return;
939 }
940
941 if let Some(principal) = data.principal() {
942 principal.with_self_ty(self.tcx(), self_ty)
943 } else {
944 return;
946 }
947 }
948 ty::Infer(ty::TyVar(_)) => {
949 {
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:949",
"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(949u32),
::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");
950 candidates.ambiguous = true; return;
952 }
953 _ => return,
954 };
955
956 {
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:956",
"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(956u32),
::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");
957
958 let candidate_supertraits = util::supertraits(self.tcx(), principal_trait_ref)
964 .enumerate()
965 .filter(|&(_, upcast_trait_ref)| {
966 self.infcx.probe(|_| {
967 self.match_normalize_trait_ref(
968 obligation,
969 placeholder_trait_predicate.trait_ref,
970 upcast_trait_ref,
971 )
972 .is_ok()
973 })
974 })
975 .map(|(idx, _)| ObjectCandidate(idx));
976
977 candidates.vec.extend(candidate_supertraits);
978 })
979 })
980 }
981
982 fn assemble_candidates_for_unsizing(
984 &mut self,
985 obligation: &PolyTraitObligation<'tcx>,
986 candidates: &mut SelectionCandidateSet<'tcx>,
987 ) {
988 let Some(trait_pred) = obligation.predicate.no_bound_vars() else {
1003 return;
1005 };
1006 let source = trait_pred.self_ty();
1007 let target = trait_pred.trait_ref.args.type_at(1);
1008
1009 {
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:1009",
"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(1009u32),
::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");
1010
1011 match (source.kind(), target.kind()) {
1012 (&ty::Dynamic(a_data, a_region), &ty::Dynamic(b_data, b_region)) => {
1014 let principal_def_id_a = a_data.principal_def_id();
1026 let principal_def_id_b = b_data.principal_def_id();
1027 if principal_def_id_a == principal_def_id_b || principal_def_id_b.is_none() {
1028 let a_auto_traits: FxIndexSet<DefId> = a_data
1032 .auto_traits()
1033 .chain(
1034 principal_def_id_a
1035 .map(|principal_def_id| {
1036 elaborate::supertrait_def_ids(self.tcx(), principal_def_id)
1037 .filter(|def_id| self.tcx().trait_is_auto(*def_id))
1038 })
1039 .into_flat_iter(),
1040 )
1041 .collect();
1042 let auto_traits_compatible = b_data
1043 .auto_traits()
1044 .all(|b| a_auto_traits.contains(&b));
1046 if auto_traits_compatible {
1047 candidates.vec.push(BuiltinUnsizeCandidate);
1048 }
1049 } else if principal_def_id_a.is_some() && principal_def_id_b.is_some() {
1050 let principal_a = a_data.principal().unwrap();
1052 let target_trait_did = principal_def_id_b.unwrap();
1053 let source_trait_ref = principal_a.with_self_ty(self.tcx(), source);
1054
1055 for (idx, upcast_trait_ref) in
1056 util::supertraits(self.tcx(), source_trait_ref).enumerate()
1057 {
1058 self.infcx.probe(|_| {
1059 if upcast_trait_ref.def_id() == target_trait_did
1060 && let Ok(nested) = self.match_upcast_principal(
1061 obligation,
1062 upcast_trait_ref,
1063 a_data,
1064 b_data,
1065 a_region,
1066 b_region,
1067 )
1068 {
1069 if nested.is_none() {
1070 candidates.ambiguous = true;
1071 }
1072 candidates.vec.push(TraitUpcastingUnsizeCandidate(idx));
1073 }
1074 })
1075 }
1076 }
1077 }
1078
1079 (_, &ty::Dynamic(_, _)) => {
1081 candidates.vec.push(BuiltinUnsizeCandidate);
1082 }
1083
1084 (&ty::Infer(ty::TyVar(_)), _) | (_, &ty::Infer(ty::TyVar(_))) => {
1088 {
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:1088",
"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(1088u32),
::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");
1089 candidates.ambiguous = true;
1090 }
1091
1092 (&ty::Array(..), &ty::Slice(_)) => {
1094 candidates.vec.push(BuiltinUnsizeCandidate);
1095 }
1096
1097 (&ty::Adt(def_id_a, _), &ty::Adt(def_id_b, _)) if def_id_a.is_struct() => {
1099 if def_id_a == def_id_b {
1100 candidates.vec.push(BuiltinUnsizeCandidate);
1101 }
1102 }
1103
1104 _ => {}
1105 };
1106 }
1107
1108 #[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(1108u32),
::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))]
1109 fn assemble_candidates_for_transmutability(
1110 &mut self,
1111 obligation: &PolyTraitObligation<'tcx>,
1112 candidates: &mut SelectionCandidateSet<'tcx>,
1113 ) {
1114 if obligation.predicate.has_non_region_param() {
1115 return;
1116 }
1117
1118 if obligation.has_non_region_infer() {
1119 candidates.ambiguous = true;
1120 return;
1121 }
1122
1123 candidates.vec.push(TransmutabilityCandidate);
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_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(1126u32),
::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:1134",
"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(1134u32),
::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))]
1127 fn assemble_candidates_for_trait_alias(
1128 &mut self,
1129 obligation: &PolyTraitObligation<'tcx>,
1130 candidates: &mut SelectionCandidateSet<'tcx>,
1131 ) {
1132 let self_ty = obligation.self_ty().skip_binder();
1134 debug!(?self_ty);
1135
1136 let def_id = obligation.predicate.def_id();
1137
1138 if self.tcx().is_trait_alias(def_id) {
1139 candidates.vec.push(TraitAliasCandidate);
1140 }
1141 }
1142
1143 #[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(1145u32),
::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))]
1146 fn assemble_builtin_copy_clone_candidate(
1147 &mut self,
1148 self_ty: Ty<'tcx>,
1149 candidates: &mut SelectionCandidateSet<'tcx>,
1150 ) {
1151 match *self_ty.kind() {
1152 ty::FnDef(..) | ty::FnPtr(..) | ty::Error(_) | ty::Tuple(..) | ty::Pat(..) => {
1155 candidates.vec.push(BuiltinCandidate);
1156 }
1157
1158 ty::Uint(_)
1160 | ty::Int(_)
1161 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
1162 | ty::Bool
1163 | ty::Float(_)
1164 | ty::Char
1165 | ty::RawPtr(..)
1166 | ty::Never
1167 | ty::Ref(_, _, hir::Mutability::Not)
1168 | ty::Array(..) => {}
1169
1170 ty::UnsafeBinder(_) => {}
1173
1174 ty::Dynamic(..) | ty::Str | ty::Slice(..) | ty::Foreign(..) => {}
1176
1177 ty::Ref(_, _, hir::Mutability::Mut) => {}
1179
1180 ty::Coroutine(coroutine_def_id, args) => {
1181 if self.should_stall_coroutine(coroutine_def_id) {
1182 candidates.ambiguous = true;
1183 return;
1184 }
1185
1186 match self.tcx().coroutine_movability(coroutine_def_id) {
1187 hir::Movability::Static => {}
1188 hir::Movability::Movable => {
1189 if self.tcx().features().coroutine_clone() {
1190 let resolved_upvars =
1191 self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty());
1192 if resolved_upvars.is_ty_var() {
1193 candidates.ambiguous = true;
1195 } else {
1196 candidates.vec.push(BuiltinCandidate);
1197 }
1198 }
1199 }
1200 }
1201 }
1202
1203 ty::Closure(_, args) => {
1204 let resolved_upvars =
1205 self.infcx.shallow_resolve(args.as_closure().tupled_upvars_ty());
1206 if resolved_upvars.is_ty_var() {
1207 candidates.ambiguous = true;
1209 } else {
1210 candidates.vec.push(BuiltinCandidate);
1211 }
1212 }
1213
1214 ty::CoroutineClosure(_, args) => {
1215 let resolved_upvars =
1216 self.infcx.shallow_resolve(args.as_coroutine_closure().tupled_upvars_ty());
1217 if resolved_upvars.is_ty_var() {
1218 candidates.ambiguous = true;
1220 } else {
1221 candidates.vec.push(BuiltinCandidate);
1222 }
1223 }
1224
1225 ty::CoroutineWitness(..) => {
1226 candidates.vec.push(SizedCandidate);
1227 }
1228
1229 ty::Adt(..) | ty::Alias(..) | ty::Param(..) | ty::Placeholder(..) => {}
1231
1232 ty::Infer(ty::TyVar(_)) => {
1233 candidates.ambiguous = true;
1234 }
1235
1236 ty::Bound(..) => {}
1238
1239 ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1240 bug!("asked to assemble builtin bounds of unexpected type: {:?}", self_ty);
1241 }
1242 }
1243 }
1244
1245 #[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(1246u32),
::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))]
1247 fn assemble_builtin_sized_candidate(
1248 &mut self,
1249 self_ty: Ty<'tcx>,
1250 candidates: &mut SelectionCandidateSet<'tcx>,
1251 sizedness: SizedTraitKind,
1252 ) {
1253 match *self_ty.kind() {
1254 ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
1256 | ty::Uint(_)
1257 | ty::Int(_)
1258 | ty::Bool
1259 | ty::Float(_)
1260 | ty::FnDef(..)
1261 | ty::FnPtr(..)
1262 | ty::RawPtr(..)
1263 | ty::Char
1264 | ty::Ref(..)
1265 | ty::Array(..)
1266 | ty::Closure(..)
1267 | ty::CoroutineClosure(..)
1268 | ty::Never
1269 | ty::Error(_) => {
1270 candidates.vec.push(SizedCandidate);
1271 }
1272
1273 ty::Coroutine(coroutine_def_id, _) => {
1274 if self.should_stall_coroutine(coroutine_def_id) {
1275 candidates.ambiguous = true;
1276 } else {
1277 candidates.vec.push(SizedCandidate);
1278 }
1279 }
1280
1281 ty::CoroutineWitness(..) => {
1282 candidates.vec.push(SizedCandidate);
1283 }
1284
1285 ty::Tuple(..) | ty::Pat(..) | ty::Adt(..) | ty::UnsafeBinder(_) => {
1287 candidates.vec.push(SizedCandidate);
1288 }
1289
1290 ty::Str | ty::Slice(_) | ty::Dynamic(..) => match sizedness {
1292 SizedTraitKind::Sized => {}
1293 SizedTraitKind::MetaSized => {
1294 candidates.vec.push(SizedCandidate);
1295 }
1296 },
1297
1298 ty::Foreign(..) => {}
1300
1301 ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => {}
1302
1303 ty::Infer(ty::TyVar(_)) => {
1304 candidates.ambiguous = true;
1305 }
1306
1307 ty::Bound(..) => {}
1309
1310 ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1311 bug!("asked to assemble builtin bounds of unexpected type: {:?}", self_ty);
1312 }
1313 }
1314 }
1315
1316 fn assemble_const_destruct_candidates(
1317 &mut self,
1318 _obligation: &PolyTraitObligation<'tcx>,
1319 candidates: &mut SelectionCandidateSet<'tcx>,
1320 ) {
1321 candidates.vec.push(BuiltinCandidate);
1322 }
1323
1324 fn assemble_candidate_for_tuple(
1325 &mut self,
1326 obligation: &PolyTraitObligation<'tcx>,
1327 candidates: &mut SelectionCandidateSet<'tcx>,
1328 ) {
1329 let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder());
1330 match self_ty.kind() {
1331 ty::Tuple(_) => {
1332 candidates.vec.push(BuiltinCandidate);
1333 }
1334 ty::Infer(ty::TyVar(_)) => {
1335 candidates.ambiguous = true;
1336 }
1337 ty::Bool
1338 | ty::Char
1339 | ty::Int(_)
1340 | ty::Uint(_)
1341 | ty::Float(_)
1342 | ty::Adt(_, _)
1343 | ty::Foreign(_)
1344 | ty::Str
1345 | ty::Array(_, _)
1346 | ty::Slice(_)
1347 | ty::RawPtr(_, _)
1348 | ty::Ref(_, _, _)
1349 | ty::FnDef(_, _)
1350 | ty::Pat(_, _)
1351 | ty::FnPtr(..)
1352 | ty::UnsafeBinder(_)
1353 | ty::Dynamic(_, _)
1354 | ty::Closure(..)
1355 | ty::CoroutineClosure(..)
1356 | ty::Coroutine(_, _)
1357 | ty::CoroutineWitness(..)
1358 | ty::Never
1359 | ty::Alias(..)
1360 | ty::Param(_)
1361 | ty::Bound(_, _)
1362 | ty::Error(_)
1363 | ty::Infer(_)
1364 | ty::Placeholder(_) => {}
1365 }
1366 }
1367
1368 fn assemble_candidates_for_fn_ptr_trait(
1369 &mut self,
1370 obligation: &PolyTraitObligation<'tcx>,
1371 candidates: &mut SelectionCandidateSet<'tcx>,
1372 ) {
1373 let self_ty = self.infcx.resolve_vars_if_possible(obligation.self_ty());
1374
1375 match self_ty.skip_binder().kind() {
1376 ty::FnPtr(..) => candidates.vec.push(BuiltinCandidate),
1377 ty::Bool
1378 | ty::Char
1379 | ty::Int(_)
1380 | ty::Uint(_)
1381 | ty::Float(_)
1382 | ty::Adt(..)
1383 | ty::Foreign(..)
1384 | ty::Str
1385 | ty::Array(..)
1386 | ty::Pat(..)
1387 | ty::Slice(_)
1388 | ty::RawPtr(_, _)
1389 | ty::Ref(..)
1390 | ty::FnDef(..)
1391 | ty::Placeholder(..)
1392 | ty::Dynamic(..)
1393 | ty::Closure(..)
1394 | ty::CoroutineClosure(..)
1395 | ty::Coroutine(..)
1396 | ty::CoroutineWitness(..)
1397 | ty::UnsafeBinder(_)
1398 | ty::Never
1399 | ty::Tuple(..)
1400 | ty::Alias(..)
1401 | ty::Param(..)
1402 | ty::Bound(..)
1403 | ty::Error(_)
1404 | ty::Infer(
1405 ty::InferTy::IntVar(_)
1406 | ty::InferTy::FloatVar(_)
1407 | ty::InferTy::FreshIntTy(_)
1408 | ty::InferTy::FreshFloatTy(_),
1409 ) => {}
1410 ty::Infer(ty::InferTy::TyVar(_) | ty::InferTy::FreshTy(_)) => {
1411 candidates.ambiguous = true;
1412 }
1413 }
1414 }
1415
1416 fn assemble_candidates_for_bikeshed_guaranteed_no_drop_trait(
1417 &mut self,
1418 obligation: &PolyTraitObligation<'tcx>,
1419 candidates: &mut SelectionCandidateSet<'tcx>,
1420 ) {
1421 match obligation.predicate.self_ty().skip_binder().kind() {
1422 ty::Ref(..)
1423 | ty::Adt(..)
1424 | ty::Tuple(_)
1425 | ty::Array(..)
1426 | ty::FnDef(..)
1427 | ty::FnPtr(..)
1428 | ty::Error(_)
1429 | ty::Uint(_)
1430 | ty::Int(_)
1431 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
1432 | ty::Bool
1433 | ty::Float(_)
1434 | ty::Char
1435 | ty::RawPtr(..)
1436 | ty::Never
1437 | ty::Pat(..)
1438 | ty::Dynamic(..)
1439 | ty::Str
1440 | ty::Slice(_)
1441 | ty::Foreign(..)
1442 | ty::Alias(..)
1443 | ty::Param(_)
1444 | ty::Placeholder(..)
1445 | ty::Closure(..)
1446 | ty::CoroutineClosure(..)
1447 | ty::Coroutine(..)
1448 | ty::UnsafeBinder(_)
1449 | ty::CoroutineWitness(..)
1450 | ty::Bound(..) => {
1451 candidates.vec.push(BikeshedGuaranteedNoDropCandidate);
1452 }
1453
1454 ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1455 candidates.ambiguous = true;
1456 }
1457 }
1458 }
1459
1460 fn assemble_candidates_for_field_trait(
1461 &mut self,
1462 obligation: &PolyTraitObligation<'tcx>,
1463 candidates: &mut SelectionCandidateSet<'tcx>,
1464 ) {
1465 if let ty::Adt(def, args) = obligation.predicate.self_ty().skip_binder().kind()
1466 && let Some(FieldInfo { base, ty, .. }) =
1467 def.field_representing_type_info(self.tcx(), args)
1468 && match self.infcx.evaluate_obligation(&PredicateObligation::new(
1473 self.tcx(),
1474 obligation.cause.clone(),
1475 obligation.param_env,
1476 TraitRef::new(
1477 self.tcx(),
1478 self.tcx().require_lang_item(LangItem::Sized, DUMMY_SP),
1479 [base],
1480 ),
1481 )) {
1482 Ok(res) if res.must_apply_modulo_regions() => true,
1483 _ => false,
1484 }
1485 && match self.infcx.evaluate_obligation(&PredicateObligation::new(
1486 self.tcx(),
1487 obligation.cause.clone(),
1488 obligation.param_env,
1489 TraitRef::new(
1490 self.tcx(),
1491 self.tcx().require_lang_item(LangItem::Sized, DUMMY_SP),
1492 [ty],
1493 ),
1494 )) {
1495 Ok(res) if res.must_apply_modulo_regions() => true,
1496 _ => false,
1497 }
1498 && match base.kind() {
1499 ty::Adt(def, _) => def.is_struct() && !def.repr().packed(),
1500 ty::Tuple(..) => true,
1501 _ => false,
1502 }
1503 {
1504 candidates.vec.push(BuiltinCandidate);
1505 }
1506 }
1507}