1use std::{debug_assert_matches, fmt};
4
5use rustc_attr_ir::lang_items::LangItem;
6use rustc_data_structures::intern::Interned;
7use rustc_errors::ErrorGuaranteed;
8use rustc_hir as hir;
9use rustc_hir::def::{CtorKind, DefKind};
10use rustc_hir::def_id::{DefId, LocalDefId};
11use rustc_span::{DUMMY_SP, Span, Symbol, bug};
12use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverProjectionLangItem, SolverTraitLangItem};
13use rustc_type_ir::solve::CanonicalInputData;
14use rustc_type_ir::{
15 BoundVar, CollectAndApply, DebruijnIndex, Interner, RegionVid, TypeFoldable, Unnormalized,
16 VisitorResult, WithCachedTypeInfo, search_graph, try_visit,
17};
18
19use crate::dep_graph::{DepKind, DepNodeIndex};
20use crate::infer::canonical::CanonicalVarKinds;
21use crate::traits::cache::WithDepNode;
22use crate::traits::solve::{
23 self, CanonicalInput, ExternalConstraints, ExternalConstraintsData, QueryResult, inspect,
24};
25use crate::ty::{
26 self, BoundRegion, Clause, Const, List, ParamTy, Pattern, PolyExistentialPredicate, Predicate,
27 Region, RegionKind, RequiredDepth, Ty, TyCtxt,
28};
29
30#[allow(rustc::usage_of_ty_tykind)]
31impl<'tcx> Interner for TyCtxt<'tcx> {
32 fn next_trait_solver_globally(self) -> bool {
33 self.next_trait_solver_globally()
34 }
35
36 type DefId = DefId;
37 type LocalDefId = LocalDefId;
38 type TraitId = DefId;
39 type ForeignId = DefId;
40 type FunctionId = DefId;
41 type ClosureId = DefId;
42 type CoroutineClosureId = DefId;
43 type CoroutineId = DefId;
44 type AdtId = DefId;
45 type ImplId = DefId;
46 type AnonConstId = DefId;
47 type TraitAssocTyId = DefId;
48 type TraitAssocConstId = DefId;
49 type TraitAssocTermId = DefId;
50 type OpaqueTyId = DefId;
51 type LocalOpaqueTyId = LocalDefId;
52 type FreeTyAliasId = DefId;
53 type FreeConstAliasId = DefId;
54 type FreeTermAliasId = DefId;
55 type ImplOrTraitAssocTyId = DefId;
56 type ImplOrTraitAssocConstId = DefId;
57 type ImplOrTraitAssocTermId = DefId;
58 type InherentAssocTyId = DefId;
59 type InherentAssocConstId = DefId;
60 type InherentAssocTermId = DefId;
61 type Span = Span;
62
63 type GenericArgs = ty::GenericArgsRef<'tcx>;
64
65 type GenericArgsSlice = &'tcx [ty::GenericArg<'tcx>];
66 type GenericArg = ty::GenericArg<'tcx>;
67 type Term = ty::Term<'tcx>;
68 type BoundVarKinds = &'tcx List<ty::BoundVariableKind<'tcx>>;
69
70 type PredefinedOpaques = solve::PredefinedOpaques<'tcx>;
71
72 fn mk_predefined_opaques_in_body(
73 self,
74 data: &[(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)],
75 ) -> Self::PredefinedOpaques {
76 self.mk_predefined_opaques_in_body(data)
77 }
78 type LocalDefIds = &'tcx ty::List<LocalDefId>;
79 type CanonicalVarKinds = CanonicalVarKinds<'tcx>;
80 fn mk_canonical_var_kinds(
81 self,
82 kinds: &[ty::CanonicalVarKind<Self>],
83 ) -> Self::CanonicalVarKinds {
84 self.mk_canonical_var_kinds(kinds)
85 }
86
87 type ExternalConstraints = ExternalConstraints<'tcx>;
88 fn mk_external_constraints(
89 self,
90 data: ExternalConstraintsData<Self>,
91 ) -> ExternalConstraints<'tcx> {
92 self.mk_external_constraints(data)
93 }
94 type DepNodeIndex = DepNodeIndex;
95 fn with_cached_task<T>(self, task: impl FnOnce() -> T) -> (T, DepNodeIndex) {
96 self.dep_graph.with_anon_task(self, DepKind::TraitSelect, task)
97 }
98 type Ty = Ty<'tcx>;
99 type Tys = &'tcx List<Ty<'tcx>>;
100
101 type FnInputTys = &'tcx [Ty<'tcx>];
102 type ParamTy = ParamTy;
103 type Symbol = Symbol;
104
105 type ErrorGuaranteed = ErrorGuaranteed;
106 type BoundExistentialPredicates = &'tcx List<PolyExistentialPredicate<'tcx>>;
107
108 type AllocId = crate::mir::interpret::AllocId;
109 type Pat = Pattern<'tcx>;
110 type PatList = &'tcx List<Pattern<'tcx>>;
111 type Safety = hir::Safety;
112 type Consts = &'tcx List<ty::Const<'tcx>>;
113
114 type ParamConst = ty::ParamConst;
115 type ValueConst = ty::Value<'tcx>;
116 type ExprConst = ty::Expr<'tcx>;
117 type ValTree = ty::ValTree<'tcx>;
118 type ScalarInt = ty::ScalarInt;
119 type InternedRegionKind = Interned<'tcx, ty::RegionKind<'tcx>>;
120 type InternedConstKind = Interned<'tcx, WithCachedTypeInfo<ty::ConstKind<'tcx>>>;
121 type EarlyParamRegion = ty::EarlyParamRegion;
122 type LateParamRegionKind = ty::LateParamRegionKind;
123
124 type RegionAssumptions = &'tcx ty::List<ty::ArgOutlivesClause<'tcx>>;
125
126 type ParamEnv = ty::ParamEnv<'tcx>;
127 type Predicate = Predicate<'tcx>;
128
129 type Clause = Clause<'tcx>;
130 type Clauses = ty::Clauses<'tcx>;
131
132 type Tracked<T: fmt::Debug + Clone> = WithDepNode<T>;
133 fn mk_tracked<T: fmt::Debug + Clone>(
134 self,
135 data: T,
136 dep_node: DepNodeIndex,
137 ) -> Self::Tracked<T> {
138 WithDepNode::new(dep_node, data)
139 }
140 fn get_tracked<T: fmt::Debug + Clone>(self, tracked: &Self::Tracked<T>) -> T {
141 tracked.get(self)
142 }
143
144 fn with_global_cache<R>(self, f: impl FnOnce(&mut search_graph::GlobalCache<Self>) -> R) -> R {
145 f(&mut *self.caches.new_solver_evaluation_cache.lock())
146 }
147
148 fn with_canonical_param_env_cache<R>(
149 self,
150 f: impl FnOnce(&mut ty::CanonicalParamEnvCache<Self>) -> R,
151 ) -> R {
152 f(&mut *self.caches.new_solver_canonical_param_env_cache.lock())
153 }
154
155 fn assert_evaluation_is_concurrent(&self) {
156 }
159
160 fn expand_abstract_consts<T: TypeFoldable<TyCtxt<'tcx>>>(self, t: T) -> T {
161 self.expand_abstract_consts(t)
162 }
163
164 type GenericsOf = &'tcx ty::Generics;
165
166 fn generics_of(self, def_id: DefId) -> &'tcx ty::Generics {
167 self.generics_of(def_id)
168 }
169
170 type VariancesOf = &'tcx [ty::Variance];
171
172 fn variances_of(self, def_id: DefId) -> Self::VariancesOf {
173 self.variances_of(def_id)
174 }
175
176 fn opt_alias_variances(
177 self,
178 kind: impl Into<ty::AliasTermKind<'tcx>>,
179 ) -> Option<&'tcx [ty::Variance]> {
180 self.opt_alias_variances(kind)
181 }
182
183 fn type_of(self, def_id: DefId) -> ty::EarlyBinder<'tcx, Ty<'tcx>> {
184 self.type_of(def_id)
185 }
186 fn type_of_opaque_hir_typeck(self, def_id: LocalDefId) -> ty::EarlyBinder<'tcx, Ty<'tcx>> {
187 self.type_of_opaque_hir_typeck(def_id)
188 }
189 fn is_direct_const(self, alias: ty::AliasConstKind<'tcx>) -> bool {
190 match alias {
191 ty::AliasConstKind::Projection { def_id }
192 | ty::AliasConstKind::InherentSelf { def_id }
193 | ty::AliasConstKind::InherentImpl { def_id }
194 | ty::AliasConstKind::Free { def_id } => self.is_direct_const(def_id),
195 ty::AliasConstKind::Anon { .. } => false,
196 }
197 }
198 fn const_of_item(
199 self,
200 alias: ty::AliasConstKind<'tcx>,
201 ) -> Option<ty::EarlyBinder<'tcx, Const<'tcx>>> {
202 match alias {
203 ty::AliasConstKind::Projection { def_id }
204 | ty::AliasConstKind::InherentSelf { def_id }
205 | ty::AliasConstKind::InherentImpl { def_id }
206 | ty::AliasConstKind::Free { def_id } => self.const_of_item(def_id),
207 ty::AliasConstKind::Anon { .. } => None,
208 }
209 }
210 fn anon_const_kind(self, def_id: DefId) -> ty::AnonConstKind {
211 self.anon_const_kind(def_id)
212 }
213
214 fn def_span(self, def_id: DefId) -> Span {
215 self.def_span(def_id)
216 }
217
218 type AdtDef = ty::AdtDef<'tcx>;
219 fn adt_def(self, adt_def_id: DefId) -> Self::AdtDef {
220 self.adt_def(adt_def_id)
221 }
222
223 fn trait_ref_and_own_args_for_alias(
224 self,
225 def_id: DefId,
226 args: ty::GenericArgsRef<'tcx>,
227 ) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) {
228 if true {
{
match self.def_kind(def_id) {
DefKind::AssocTy | DefKind::AssocConst => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"DefKind::AssocTy | DefKind::AssocConst",
::core::option::Option::None);
}
}
};
};debug_assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst);
229 let trait_def_id = self.parent(def_id);
230 if true {
{
match self.def_kind(trait_def_id) {
DefKind::Trait => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"DefKind::Trait", ::core::option::Option::None);
}
}
};
};debug_assert_matches!(self.def_kind(trait_def_id), DefKind::Trait);
231 let trait_ref = ty::TraitRef::from_assoc(self, trait_def_id, args);
232 (trait_ref, &args[trait_ref.args.len()..])
233 }
234
235 fn mk_args(self, args: &[Self::GenericArg]) -> ty::GenericArgsRef<'tcx> {
236 self.mk_args(args)
237 }
238
239 fn mk_args_from_iter<I, T>(self, args: I) -> T::Output
240 where
241 I: Iterator<Item = T>,
242 T: CollectAndApply<Self::GenericArg, ty::GenericArgsRef<'tcx>>,
243 {
244 self.mk_args_from_iter(args)
245 }
246
247 fn check_alias_term_args_compatible(
248 self,
249 kind: ty::AliasTermKind<'tcx>,
250 args: ty::GenericArgsRef<'tcx>,
251 ) -> bool {
252 self.check_alias_term_args_compatible(kind, args)
253 }
254
255 fn debug_assert_args_compatible(self, def_id: DefId, args: ty::GenericArgsRef<'tcx>) {
256 self.debug_assert_args_compatible(def_id, args);
257 }
258
259 fn debug_assert_alias_term_args_compatible(
260 self,
261 kind: ty::AliasTermKind<'tcx>,
262 args: ty::GenericArgsRef<'tcx>,
263 ) {
264 self.debug_assert_alias_term_args_compatible(kind, args);
265 }
266
267 fn debug_assert_existential_args_compatible(
271 self,
272 def_id: Self::DefId,
273 args: Self::GenericArgs,
274 ) {
275 if truecfg!(debug_assertions) {
278 self.debug_assert_args_compatible(
279 def_id,
280 self.mk_args_from_iter(
281 [self.types.trait_object_dummy_self.into()].into_iter().chain(args.iter()),
282 ),
283 );
284 }
285 }
286
287 fn mk_type_list_from_iter<I, T>(self, args: I) -> T::Output
288 where
289 I: Iterator<Item = T>,
290 T: CollectAndApply<Ty<'tcx>, &'tcx List<Ty<'tcx>>>,
291 {
292 self.mk_type_list_from_iter(args)
293 }
294
295 fn mk_ct_from_kind(self, kind: ty::ConstKind<'tcx>) -> ty::Const<'tcx> {
296 self.mk_ct_from_kind(kind)
297 }
298
299 fn projection_parent(self, def_id: Self::TraitAssocTermId) -> Self::TraitId {
300 self.parent(def_id)
301 }
302
303 fn impl_or_trait_assoc_term_parent(self, def_id: Self::ImplOrTraitAssocTyId) -> DefId {
304 self.parent(def_id)
305 }
306
307 fn inherent_alias_term_parent(self, def_id: Self::InherentAssocTermId) -> Self::ImplId {
308 self.parent(def_id)
309 }
310
311 fn recursion_limit(self) -> usize {
312 self.recursion_limit().0
313 }
314
315 type Features = &'tcx rustc_feature::Features;
316
317 fn features(self) -> Self::Features {
318 self.features()
319 }
320
321 fn assumptions_on_binders(self) -> bool {
322 self.assumptions_on_binders()
323 }
324
325 fn renormalize_rigid_aliases(self) -> bool {
326 self.renormalize_rigid_aliases()
327 }
328
329 fn coroutine_hidden_types(
330 self,
331 def_id: DefId,
332 ) -> ty::EarlyBinder<'tcx, ty::Binder<'tcx, ty::CoroutineWitnessTypes<TyCtxt<'tcx>>>> {
333 self.coroutine_hidden_types(def_id)
334 }
335
336 fn fn_sig(self, def_id: DefId) -> ty::EarlyBinder<'tcx, ty::PolyFnSig<'tcx>> {
337 self.fn_sig(def_id)
338 }
339
340 fn coroutine_movability(self, def_id: DefId) -> rustc_ast::Movability {
341 self.coroutine_movability(def_id)
342 }
343
344 fn coroutine_for_closure(self, def_id: DefId) -> DefId {
345 self.coroutine_for_closure(def_id)
346 }
347
348 fn generics_require_sized_self(self, def_id: DefId) -> bool {
349 self.generics_require_sized_self(def_id)
350 }
351
352 fn item_bounds(
353 self,
354 def_id: DefId,
355 ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
356 self.item_bounds(def_id).map_bound(IntoIterator::into_iter)
357 }
358
359 fn item_self_bounds(
360 self,
361 def_id: DefId,
362 ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
363 self.item_self_bounds(def_id).map_bound(IntoIterator::into_iter)
364 }
365
366 fn item_non_self_bounds(
367 self,
368 def_id: DefId,
369 ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
370 self.item_non_self_bounds(def_id).map_bound(IntoIterator::into_iter)
371 }
372
373 fn clauses_of(
374 self,
375 def_id: DefId,
376 ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
377 ty::EarlyBinder::bind_iter(
378 self.clauses_of(def_id)
379 .instantiate_identity(self)
380 .clauses
381 .into_iter()
382 .map(Unnormalized::skip_normalization),
383 )
384 }
385
386 fn own_clauses_of(
387 self,
388 def_id: DefId,
389 ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
390 ty::EarlyBinder::bind_iter(
391 self.clauses_of(def_id)
392 .instantiate_own_identity()
393 .map(|(clause, _)| clause.skip_normalization()),
394 )
395 }
396
397 fn explicit_super_clauses_of(
398 self,
399 def_id: DefId,
400 ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = (ty::Clause<'tcx>, Span)>> {
401 self.explicit_super_clauses_of(def_id).map_bound(|preds| preds.into_iter().copied())
402 }
403
404 fn explicit_implied_clauses_of(
405 self,
406 def_id: DefId,
407 ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = (ty::Clause<'tcx>, Span)>> {
408 self.explicit_implied_clauses_of(def_id).map_bound(|preds| preds.into_iter().copied())
409 }
410
411 fn impl_super_outlives(
412 self,
413 impl_def_id: DefId,
414 ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
415 self.impl_super_outlives(impl_def_id)
416 }
417
418 fn supertrait_def_ids(self, trait_def_id: DefId) -> impl Iterator<Item = DefId> {
419 rustc_type_ir::elaborate::supertrait_def_ids(self, trait_def_id)
420 }
421
422 fn impl_is_const(self, def_id: DefId) -> bool {
423 if true {
{
match self.def_kind(def_id) {
DefKind::Impl { of_trait: true } => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"DefKind::Impl { of_trait: true }",
::core::option::Option::None);
}
}
};
};debug_assert_matches!(self.def_kind(def_id), DefKind::Impl { of_trait: true });
424 self.is_conditionally_const(def_id)
425 }
426
427 fn fn_is_const(self, def_id: DefId) -> bool {
428 if true {
{
match self.def_kind(def_id) {
DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(_, CtorKind::Fn) =>
{}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(_, CtorKind::Fn)",
::core::option::Option::None);
}
}
};
};debug_assert_matches!(
429 self.def_kind(def_id),
430 DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(_, CtorKind::Fn)
431 );
432 self.is_conditionally_const(def_id)
433 }
434
435 fn closure_is_const(self, def_id: DefId) -> bool {
436 if true {
{
match self.def_kind(def_id) {
DefKind::Closure => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"DefKind::Closure", ::core::option::Option::None);
}
}
};
};debug_assert_matches!(self.def_kind(def_id), DefKind::Closure);
437 #[allow(non_exhaustive_omitted_patterns)] match self.constness(def_id) {
hir::Constness::Const { always: false } => true,
_ => false,
}matches!(self.constness(def_id), hir::Constness::Const { always: false })
438 }
439
440 fn alias_has_const_conditions(self, def_id: DefId) -> bool {
441 if true {
{
match self.def_kind(def_id) {
DefKind::AssocTy | DefKind::OpaqueTy => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"DefKind::AssocTy | DefKind::OpaqueTy",
::core::option::Option::None);
}
}
};
};debug_assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::OpaqueTy);
442 self.is_conditionally_const(def_id)
443 }
444
445 fn const_conditions(
446 self,
447 def_id: DefId,
448 ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Binder<'tcx, ty::TraitRef<'tcx>>>> {
449 ty::EarlyBinder::bind_iter(
450 self.const_conditions(def_id)
451 .instantiate_identity(self)
452 .into_iter()
453 .map(|(c, _)| c.skip_normalization()),
454 )
455 }
456
457 fn explicit_implied_const_bounds(
458 self,
459 def_id: DefId,
460 ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Binder<'tcx, ty::TraitRef<'tcx>>>> {
461 ty::EarlyBinder::bind_iter(
462 self.explicit_implied_const_bounds(def_id)
463 .iter_identity_copied()
464 .map(Unnormalized::skip_normalization)
465 .map(|(c, _)| c),
466 )
467 }
468
469 fn impl_self_is_guaranteed_unsized(self, impl_def_id: DefId) -> bool {
470 self.impl_self_is_guaranteed_unsized(impl_def_id)
471 }
472
473 fn has_target_features(self, def_id: DefId) -> bool {
474 !self.codegen_fn_attrs(def_id).target_features.is_empty()
475 }
476
477 fn require_projection_lang_item(self, lang_item: SolverProjectionLangItem) -> DefId {
478 self.require_lang_item(solver_lang_item_to_lang_item(lang_item), DUMMY_SP)
479 }
480
481 fn require_trait_lang_item(self, lang_item: SolverTraitLangItem) -> DefId {
482 self.require_lang_item(solver_trait_lang_item_to_lang_item(lang_item), DUMMY_SP)
483 }
484
485 fn require_adt_lang_item(self, lang_item: SolverAdtLangItem) -> DefId {
486 self.require_lang_item(solver_adt_lang_item_to_lang_item(lang_item), DUMMY_SP)
487 }
488
489 fn is_projection_lang_item(self, def_id: DefId, lang_item: SolverProjectionLangItem) -> bool {
490 self.is_lang_item(def_id, solver_lang_item_to_lang_item(lang_item))
491 }
492
493 fn is_trait_lang_item(self, def_id: DefId, lang_item: SolverTraitLangItem) -> bool {
494 self.is_lang_item(def_id, solver_trait_lang_item_to_lang_item(lang_item))
495 }
496
497 fn is_adt_lang_item(self, def_id: DefId, lang_item: SolverAdtLangItem) -> bool {
498 self.is_lang_item(def_id, solver_adt_lang_item_to_lang_item(lang_item))
499 }
500
501 fn is_default_trait(self, def_id: DefId) -> bool {
502 self.is_default_trait(def_id)
503 }
504
505 fn is_sizedness_trait(self, def_id: DefId) -> bool {
506 self.is_sizedness_trait(def_id)
507 }
508
509 fn as_projection_lang_item(self, def_id: DefId) -> Option<SolverProjectionLangItem> {
510 lang_item_to_solver_lang_item(self.lang_items().from_def_id(def_id)?)
511 }
512
513 fn as_trait_lang_item(self, def_id: DefId) -> Option<SolverTraitLangItem> {
514 lang_item_to_solver_trait_lang_item(self.lang_items().from_def_id(def_id)?)
515 }
516
517 fn as_adt_lang_item(self, def_id: DefId) -> Option<SolverAdtLangItem> {
518 lang_item_to_solver_adt_lang_item(self.lang_items().from_def_id(def_id)?)
519 }
520
521 fn associated_type_def_ids(self, def_id: DefId) -> impl IntoIterator<Item = DefId> {
522 self.associated_items(def_id)
523 .in_definition_order()
524 .filter(|assoc_item| assoc_item.is_type())
525 .map(|assoc_item| assoc_item.def_id)
526 }
527
528 fn for_each_relevant_impl<R: VisitorResult>(
531 self,
532 trait_ref: ty::TraitRef<'tcx>,
533 f: impl FnMut(DefId) -> R,
534 ) -> R {
535 let self_ty = trait_ref.args.type_at(0);
536 if true {
if !!#[allow(non_exhaustive_omitted_patterns)] match self_ty.kind() {
ty::Infer(ty::TyVar(_)) | ty::Param(_) | ty::Bound(_, _) =>
true,
_ => false,
} {
{
::core::panicking::panic_fmt(format_args!("we should not have them as self ty in the next solver"));
}
};
};debug_assert!(
537 !matches!(self_ty.kind(), ty::Infer(ty::TyVar(_)) | ty::Param(_) | ty::Bound(_, _)),
538 "we should not have them as self ty in the next solver"
539 );
540 TyCtxt::for_each_relevant_impl(self, trait_ref.def_id, self_ty, f)
541 }
542 fn for_each_blanket_impl<R: VisitorResult>(
543 self,
544 trait_def_id: DefId,
545 mut f: impl FnMut(DefId) -> R,
546 ) -> R {
547 let trait_impls = self.trait_impls_of(trait_def_id);
548 for &impl_def_id in trait_impls.blanket_impls() {
549 match ::rustc_ast_ir::visit::VisitorResult::branch(f(impl_def_id)) {
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};try_visit!(f(impl_def_id));
550 }
551
552 R::output()
553 }
554
555 fn has_item_definition(self, def_id: DefId) -> bool {
556 self.defaultness(def_id).has_value()
557 }
558
559 fn impl_specializes(self, impl_def_id: Self::DefId, victim_def_id: Self::DefId) -> bool {
560 self.specializes((impl_def_id, victim_def_id))
561 }
562
563 fn impl_is_default(self, impl_def_id: DefId) -> bool {
564 self.defaultness(impl_def_id).is_default()
565 }
566
567 fn impl_trait_ref(self, impl_def_id: DefId) -> ty::EarlyBinder<'tcx, ty::TraitRef<'tcx>> {
568 self.impl_trait_ref(impl_def_id)
569 }
570
571 fn impl_polarity(self, impl_def_id: DefId) -> ty::ImplPolarity {
572 self.impl_polarity(impl_def_id)
573 }
574
575 fn is_fully_generic_for_reflection(self, impl_def_id: Self::ImplId) -> bool {
576 self.impl_is_fully_generic_for_reflection(impl_def_id)
577 }
578
579 fn trait_is_auto(self, trait_def_id: DefId) -> bool {
580 self.trait_is_auto(trait_def_id)
581 }
582
583 fn trait_is_marker(self, trait_def_id: DefId) -> bool {
584 self.trait_def(trait_def_id).is_marker
585 }
586
587 fn trait_is_coinductive(self, trait_def_id: DefId) -> bool {
588 self.trait_is_coinductive(trait_def_id)
589 }
590
591 fn trait_is_alias(self, trait_def_id: DefId) -> bool {
592 self.trait_is_alias(trait_def_id)
593 }
594
595 fn trait_is_dyn_compatible(self, trait_def_id: DefId) -> bool {
596 self.is_dyn_compatible(trait_def_id)
597 }
598
599 fn trait_is_fundamental(self, def_id: DefId) -> bool {
600 self.trait_def(def_id).is_fundamental
601 }
602
603 fn trait_is_unsafe(self, trait_def_id: Self::DefId) -> bool {
604 self.trait_def(trait_def_id).safety.is_unsafe()
605 }
606
607 fn is_impl_trait_in_trait(self, def_id: DefId) -> bool {
608 self.is_impl_trait_in_trait(def_id)
609 }
610
611 fn delay_bug(self, msg: impl ToString) -> ErrorGuaranteed {
612 self.dcx().span_delayed_bug(DUMMY_SP, msg.to_string())
613 }
614
615 fn span_delayed_bug(self, span: Self::Span, msg: impl ToString) -> ErrorGuaranteed {
616 self.dcx().span_delayed_bug(span, msg.to_string())
617 }
618
619 fn is_general_coroutine(self, coroutine_def_id: DefId) -> bool {
620 self.is_general_coroutine(coroutine_def_id)
621 }
622
623 fn coroutine_is_async(self, coroutine_def_id: DefId) -> bool {
624 self.coroutine_is_async(coroutine_def_id)
625 }
626
627 fn coroutine_is_gen(self, coroutine_def_id: DefId) -> bool {
628 self.coroutine_is_gen(coroutine_def_id)
629 }
630
631 fn coroutine_is_async_gen(self, coroutine_def_id: DefId) -> bool {
632 self.coroutine_is_async_gen(coroutine_def_id)
633 }
634
635 type UnsizingParams = &'tcx rustc_index::bit_set::DenseBitSet<u32>;
636 fn unsizing_params_for_adt(self, adt_def_id: DefId) -> Self::UnsizingParams {
637 self.unsizing_params_for_adt(adt_def_id)
638 }
639
640 fn anonymize_bound_vars<T: TypeFoldable<TyCtxt<'tcx>>>(
641 self,
642 binder: ty::Binder<'tcx, T>,
643 ) -> ty::Binder<'tcx, T> {
644 self.anonymize_bound_vars(binder)
645 }
646
647 fn opaque_types_defined_by(self, defining_anchor: LocalDefId) -> Self::LocalDefIds {
648 self.opaque_types_defined_by(defining_anchor)
649 }
650
651 fn opaque_types_and_coroutines_defined_by(
652 self,
653 defining_anchor: Self::LocalDefId,
654 ) -> Self::LocalDefIds {
655 let coroutines_defined_by = self
656 .nested_bodies_within(defining_anchor)
657 .iter()
658 .filter(|def_id| self.is_coroutine(def_id.to_def_id()));
659 self.mk_local_def_ids_from_iter(
660 self.opaque_types_defined_by(defining_anchor).iter().chain(coroutines_defined_by),
661 )
662 }
663
664 type Probe = &'tcx inspect::Probe<TyCtxt<'tcx>>;
665 fn mk_probe(self, probe: inspect::Probe<Self>) -> &'tcx inspect::Probe<TyCtxt<'tcx>> {
666 self.arena.alloc(probe)
667 }
668 type CanonicalInput = CanonicalInput<'tcx>;
669 fn mk_canonical_input(self, data: CanonicalInputData<Self>) -> CanonicalInput<'tcx> {
670 self.intern_canonical_input(data)
671 }
672 fn evaluate_root_goal_for_proof_tree_raw(
673 self,
674 canonical_goal: CanonicalInput<'tcx>,
675 root_depth: usize,
676 ) -> (QueryResult<'tcx>, &'tcx inspect::Probe<TyCtxt<'tcx>>, RequiredDepth) {
677 self.evaluate_root_goal_for_proof_tree_raw((canonical_goal, root_depth))
678 }
679
680 fn item_name(self, id: DefId) -> Symbol {
681 self.opt_item_name(id).unwrap_or_else(|| {
682 ::rustc_span::macros::bug_impl(None,
format_args!("item_name: no name for {0:?}", self.def_path(id)),
Location::caller());bug!("item_name: no name for {:?}", self.def_path(id));
683 })
684 }
685
686 fn get_anon_re_bounds_lifetime(self, idx: usize, var_idx: usize) -> Option<Region<'tcx>> {
687 if let Some(inner) = self.lifetimes.anon_re_bounds.get(idx) {
688 inner.get(var_idx).copied()
689 } else {
690 None
691 }
692 }
693
694 fn get_anon_re_canonical_bounds_lifetime(self, idx: usize) -> Option<Region<'tcx>> {
695 self.lifetimes.anon_re_canonical_bounds.get(idx).copied()
696 }
697
698 fn get_re_static_lifetime(self) -> Region<'tcx> {
699 self.lifetimes.re_static
700 }
701
702 fn intern_re_var(self, rv: RegionVid) -> Region<'tcx> {
703 self.lifetimes
705 .re_vars
706 .get(rv.as_usize())
707 .copied()
708 .unwrap_or_else(|| self.intern_region(ty::ReVar(rv)))
709 }
710
711 fn intern_region(self, region_kind: RegionKind<'tcx>) -> Region<'tcx> {
712 self.intern_region(region_kind)
713 }
714
715 fn intern_bound_region(
716 self,
717 debruijn: DebruijnIndex,
718 bound_region: BoundRegion<'tcx>,
719 ) -> Region<'tcx> {
720 if let ty::BoundRegion { var, kind: ty::BoundRegionKind::Anon } = bound_region
722 && let Some(inner) = self.lifetimes.anon_re_bounds.get(debruijn.as_usize())
723 && let Some(re) = inner.get(var.as_usize()).copied()
724 {
725 re
726 } else {
727 self.intern_region(ty::ReBound(ty::BoundVarIndexKind::Bound(debruijn), bound_region))
728 }
729 }
730
731 fn intern_canonical_bound(self, var: BoundVar) -> Region<'tcx> {
732 if let Some(re) = self.lifetimes.anon_re_canonical_bounds.get(var.as_usize()).copied() {
734 re
735 } else {
736 self.intern_region(ty::ReBound(
737 ty::BoundVarIndexKind::Canonical,
738 BoundRegion { var, kind: ty::BoundRegionKind::Anon },
739 ))
740 }
741 }
742}
743
744impl<'tcx, T: Clone + Copy> rustc_type_ir::intern::Interned<TyCtxt<'tcx>> for Interned<'tcx, T> {
745 type Value = T;
746 fn get(self) -> T {
747 *self.0
748 }
749}
750
751macro_rules! bidirectional_lang_item_map {
754 (
755 $solver_ty:ident, fn $to_solver:ident, fn $from_solver:ident;
756 $($name:ident),+ $(,)?
757 ) => {
758 fn $from_solver(lang_item: $solver_ty) -> LangItem {
759 match lang_item {
760 $($solver_ty::$name => LangItem::$name,)+
761 }
762 }
763
764 fn $to_solver(lang_item: LangItem) -> Option<$solver_ty> {
765 Some(match lang_item {
766 $(LangItem::$name => $solver_ty::$name,)+
767 _ => return None,
768 })
769 }
770 }
771}
772
773fn solver_lang_item_to_lang_item(lang_item: SolverProjectionLangItem)
-> LangItem {
match lang_item {
SolverProjectionLangItem::AsyncFnKindUpvars =>
LangItem::AsyncFnKindUpvars,
SolverProjectionLangItem::AsyncFnOnceOutput =>
LangItem::AsyncFnOnceOutput,
SolverProjectionLangItem::CallOnceFuture => LangItem::CallOnceFuture,
SolverProjectionLangItem::CallRefFuture => LangItem::CallRefFuture,
SolverProjectionLangItem::CoroutineReturn =>
LangItem::CoroutineReturn,
SolverProjectionLangItem::CoroutineYield => LangItem::CoroutineYield,
SolverProjectionLangItem::FieldBase => LangItem::FieldBase,
SolverProjectionLangItem::FieldType => LangItem::FieldType,
SolverProjectionLangItem::FutureOutput => LangItem::FutureOutput,
SolverProjectionLangItem::Metadata => LangItem::Metadata,
}
}
fn lang_item_to_solver_lang_item(lang_item: LangItem)
-> Option<SolverProjectionLangItem> {
Some(match lang_item {
LangItem::AsyncFnKindUpvars =>
SolverProjectionLangItem::AsyncFnKindUpvars,
LangItem::AsyncFnOnceOutput =>
SolverProjectionLangItem::AsyncFnOnceOutput,
LangItem::CallOnceFuture =>
SolverProjectionLangItem::CallOnceFuture,
LangItem::CallRefFuture =>
SolverProjectionLangItem::CallRefFuture,
LangItem::CoroutineReturn =>
SolverProjectionLangItem::CoroutineReturn,
LangItem::CoroutineYield =>
SolverProjectionLangItem::CoroutineYield,
LangItem::FieldBase => SolverProjectionLangItem::FieldBase,
LangItem::FieldType => SolverProjectionLangItem::FieldType,
LangItem::FutureOutput => SolverProjectionLangItem::FutureOutput,
LangItem::Metadata => SolverProjectionLangItem::Metadata,
_ => return None,
})
}bidirectional_lang_item_map! {
774 SolverProjectionLangItem, fn lang_item_to_solver_lang_item, fn solver_lang_item_to_lang_item;
775
776AsyncFnKindUpvars,
778 AsyncFnOnceOutput,
779 CallOnceFuture,
780 CallRefFuture,
781 CoroutineReturn,
782 CoroutineYield,
783 FieldBase,
784 FieldType,
785 FutureOutput,
786 Metadata,
787}
789
790fn solver_adt_lang_item_to_lang_item(lang_item: SolverAdtLangItem)
-> LangItem {
match lang_item {
SolverAdtLangItem::DynMetadata => LangItem::DynMetadata,
SolverAdtLangItem::Option => LangItem::Option,
SolverAdtLangItem::OwnedBox => LangItem::OwnedBox,
SolverAdtLangItem::Poll => LangItem::Poll,
}
}
fn lang_item_to_solver_adt_lang_item(lang_item: LangItem)
-> Option<SolverAdtLangItem> {
Some(match lang_item {
LangItem::DynMetadata => SolverAdtLangItem::DynMetadata,
LangItem::Option => SolverAdtLangItem::Option,
LangItem::OwnedBox => SolverAdtLangItem::OwnedBox,
LangItem::Poll => SolverAdtLangItem::Poll,
_ => return None,
})
}bidirectional_lang_item_map! {
791 SolverAdtLangItem, fn lang_item_to_solver_adt_lang_item, fn solver_adt_lang_item_to_lang_item;
792
793DynMetadata,
795 Option,
796 OwnedBox,
797 Poll,
798}
800
801fn solver_trait_lang_item_to_lang_item(lang_item: SolverTraitLangItem)
-> LangItem {
match lang_item {
SolverTraitLangItem::AsyncFn => LangItem::AsyncFn,
SolverTraitLangItem::AsyncFnKindHelper => LangItem::AsyncFnKindHelper,
SolverTraitLangItem::AsyncFnMut => LangItem::AsyncFnMut,
SolverTraitLangItem::AsyncFnOnce => LangItem::AsyncFnOnce,
SolverTraitLangItem::AsyncIterator => LangItem::AsyncIterator,
SolverTraitLangItem::BikeshedGuaranteedNoDrop =>
LangItem::BikeshedGuaranteedNoDrop,
SolverTraitLangItem::Clone => LangItem::Clone,
SolverTraitLangItem::Copy => LangItem::Copy,
SolverTraitLangItem::Coroutine => LangItem::Coroutine,
SolverTraitLangItem::Destruct => LangItem::Destruct,
SolverTraitLangItem::DiscriminantKind => LangItem::DiscriminantKind,
SolverTraitLangItem::Drop => LangItem::Drop,
SolverTraitLangItem::Field => LangItem::Field,
SolverTraitLangItem::Fn => LangItem::Fn,
SolverTraitLangItem::FnMut => LangItem::FnMut,
SolverTraitLangItem::FnOnce => LangItem::FnOnce,
SolverTraitLangItem::FnPtrTrait => LangItem::FnPtrTrait,
SolverTraitLangItem::FusedIterator => LangItem::FusedIterator,
SolverTraitLangItem::Future => LangItem::Future,
SolverTraitLangItem::Iterator => LangItem::Iterator,
SolverTraitLangItem::MetaSized => LangItem::MetaSized,
SolverTraitLangItem::PointeeSized => LangItem::PointeeSized,
SolverTraitLangItem::PointeeTrait => LangItem::PointeeTrait,
SolverTraitLangItem::Sized => LangItem::Sized,
SolverTraitLangItem::TransmuteTrait => LangItem::TransmuteTrait,
SolverTraitLangItem::TrivialClone => LangItem::TrivialClone,
SolverTraitLangItem::TryAsDyn => LangItem::TryAsDyn,
SolverTraitLangItem::Tuple => LangItem::Tuple,
SolverTraitLangItem::Unpin => LangItem::Unpin,
SolverTraitLangItem::Unsize => LangItem::Unsize,
}
}
fn lang_item_to_solver_trait_lang_item(lang_item: LangItem)
-> Option<SolverTraitLangItem> {
Some(match lang_item {
LangItem::AsyncFn => SolverTraitLangItem::AsyncFn,
LangItem::AsyncFnKindHelper =>
SolverTraitLangItem::AsyncFnKindHelper,
LangItem::AsyncFnMut => SolverTraitLangItem::AsyncFnMut,
LangItem::AsyncFnOnce => SolverTraitLangItem::AsyncFnOnce,
LangItem::AsyncIterator => SolverTraitLangItem::AsyncIterator,
LangItem::BikeshedGuaranteedNoDrop =>
SolverTraitLangItem::BikeshedGuaranteedNoDrop,
LangItem::Clone => SolverTraitLangItem::Clone,
LangItem::Copy => SolverTraitLangItem::Copy,
LangItem::Coroutine => SolverTraitLangItem::Coroutine,
LangItem::Destruct => SolverTraitLangItem::Destruct,
LangItem::DiscriminantKind =>
SolverTraitLangItem::DiscriminantKind,
LangItem::Drop => SolverTraitLangItem::Drop,
LangItem::Field => SolverTraitLangItem::Field,
LangItem::Fn => SolverTraitLangItem::Fn,
LangItem::FnMut => SolverTraitLangItem::FnMut,
LangItem::FnOnce => SolverTraitLangItem::FnOnce,
LangItem::FnPtrTrait => SolverTraitLangItem::FnPtrTrait,
LangItem::FusedIterator => SolverTraitLangItem::FusedIterator,
LangItem::Future => SolverTraitLangItem::Future,
LangItem::Iterator => SolverTraitLangItem::Iterator,
LangItem::MetaSized => SolverTraitLangItem::MetaSized,
LangItem::PointeeSized => SolverTraitLangItem::PointeeSized,
LangItem::PointeeTrait => SolverTraitLangItem::PointeeTrait,
LangItem::Sized => SolverTraitLangItem::Sized,
LangItem::TransmuteTrait => SolverTraitLangItem::TransmuteTrait,
LangItem::TrivialClone => SolverTraitLangItem::TrivialClone,
LangItem::TryAsDyn => SolverTraitLangItem::TryAsDyn,
LangItem::Tuple => SolverTraitLangItem::Tuple,
LangItem::Unpin => SolverTraitLangItem::Unpin,
LangItem::Unsize => SolverTraitLangItem::Unsize,
_ => return None,
})
}bidirectional_lang_item_map! {
802 SolverTraitLangItem, fn lang_item_to_solver_trait_lang_item, fn solver_trait_lang_item_to_lang_item;
803
804AsyncFn,
806 AsyncFnKindHelper,
807 AsyncFnMut,
808 AsyncFnOnce,
809 AsyncIterator,
810 BikeshedGuaranteedNoDrop,
811 Clone,
812 Copy,
813 Coroutine,
814 Destruct,
815 DiscriminantKind,
816 Drop,
817 Field,
818 Fn,
819 FnMut,
820 FnOnce,
821 FnPtrTrait,
822 FusedIterator,
823 Future,
824 Iterator,
825 MetaSized,
826 PointeeSized,
827 PointeeTrait,
828 Sized,
829 TransmuteTrait,
830 TrivialClone,
831 TryAsDyn,
832 Tuple,
833 Unpin,
834 Unsize,
835}