Skip to main content

rustc_middle/ty/context/
impl_interner.rs

1//! Implementation of [`rustc_type_ir::Interner`] for [`TyCtxt`].
2
3use std::ops::ControlFlow;
4use std::{debug_assert_matches, fmt};
5
6use rustc_data_structures::Limit;
7use rustc_data_structures::intern::Interned;
8use rustc_errors::ErrorGuaranteed;
9use rustc_hir as hir;
10use rustc_hir::def::{CtorKind, DefKind, Namespace};
11use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
12use rustc_hir::{CRATE_HIR_ID, LangItem};
13use rustc_span::{DUMMY_SP, Span, Symbol};
14use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverProjectionLangItem, SolverTraitLangItem};
15use rustc_type_ir::{
16    BoundVar, CollectAndApply, DebruijnIndex, Interner, TypeFoldable, Unnormalized, VisitorResult,
17    search_graph,
18};
19
20use crate::dep_graph::{DepKind, DepNodeIndex};
21use crate::infer::canonical::CanonicalVarKinds;
22use crate::traits::cache::WithDepNode;
23use crate::traits::solve::{
24    self, CanonicalInput, ExternalConstraints, ExternalConstraintsData, QueryResult, inspect,
25};
26use crate::ty::print::{FmtPrinter, Print};
27use crate::ty::{
28    self, BoundRegion, Clause, Const, List, ParamTy, Pattern, PolyExistentialPredicate, Predicate,
29    Region, RegionKind, Ty, TyCtxt,
30};
31
32#[allow(rustc::usage_of_ty_tykind)]
33impl<'tcx> Interner for TyCtxt<'tcx> {
34    fn next_trait_solver_globally(self) -> bool {
35        self.next_trait_solver_globally()
36    }
37
38    type DefId = DefId;
39    type LocalDefId = LocalDefId;
40    type TraitId = DefId;
41    type ForeignId = DefId;
42    type FunctionId = DefId;
43    type ClosureId = DefId;
44    type CoroutineClosureId = DefId;
45    type CoroutineId = DefId;
46    type AdtId = DefId;
47    type ImplId = DefId;
48    type AnonConstId = DefId;
49    type TraitAssocTyId = DefId;
50    type TraitAssocConstId = DefId;
51    type TraitAssocTermId = DefId;
52    type OpaqueTyId = DefId;
53    type LocalOpaqueTyId = LocalDefId;
54    type FreeTyAliasId = DefId;
55    type FreeConstAliasId = DefId;
56    type FreeTermAliasId = DefId;
57    type ImplOrTraitAssocTyId = DefId;
58    type ImplOrTraitAssocConstId = DefId;
59    type ImplOrTraitAssocTermId = DefId;
60    type InherentAssocTyId = DefId;
61    type InherentAssocConstId = DefId;
62    type InherentAssocTermId = DefId;
63    type Span = Span;
64
65    type GenericArgs = ty::GenericArgsRef<'tcx>;
66
67    type GenericArgsSlice = &'tcx [ty::GenericArg<'tcx>];
68    type GenericArg = ty::GenericArg<'tcx>;
69    type Term = ty::Term<'tcx>;
70    type BoundVarKinds = &'tcx List<ty::BoundVariableKind<'tcx>>;
71
72    type PredefinedOpaques = solve::PredefinedOpaques<'tcx>;
73
74    fn mk_predefined_opaques_in_body(
75        self,
76        data: &[(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)],
77    ) -> Self::PredefinedOpaques {
78        self.mk_predefined_opaques_in_body(data)
79    }
80    type LocalDefIds = &'tcx ty::List<LocalDefId>;
81    type CanonicalVarKinds = CanonicalVarKinds<'tcx>;
82    fn mk_canonical_var_kinds(
83        self,
84        kinds: &[ty::CanonicalVarKind<Self>],
85    ) -> Self::CanonicalVarKinds {
86        self.mk_canonical_var_kinds(kinds)
87    }
88
89    type ExternalConstraints = ExternalConstraints<'tcx>;
90    fn mk_external_constraints(
91        self,
92        data: ExternalConstraintsData<Self>,
93    ) -> ExternalConstraints<'tcx> {
94        self.mk_external_constraints(data)
95    }
96    type DepNodeIndex = DepNodeIndex;
97    fn with_cached_task<T>(self, task: impl FnOnce() -> T) -> (T, DepNodeIndex) {
98        self.dep_graph.with_anon_task(self, DepKind::TraitSelect, task)
99    }
100    type Ty = Ty<'tcx>;
101    type Tys = &'tcx List<Ty<'tcx>>;
102
103    type FnInputTys = &'tcx [Ty<'tcx>];
104    type ParamTy = ParamTy;
105    type Symbol = Symbol;
106
107    type ErrorGuaranteed = ErrorGuaranteed;
108    type BoundExistentialPredicates = &'tcx List<PolyExistentialPredicate<'tcx>>;
109
110    type AllocId = crate::mir::interpret::AllocId;
111    type Pat = Pattern<'tcx>;
112    type PatList = &'tcx List<Pattern<'tcx>>;
113    type Safety = hir::Safety;
114    type Const = ty::Const<'tcx>;
115    type Consts = &'tcx List<Self::Const>;
116
117    type ParamConst = ty::ParamConst;
118    type ValueConst = ty::Value<'tcx>;
119    type ExprConst = ty::Expr<'tcx>;
120    type ValTree = ty::ValTree<'tcx>;
121    type ScalarInt = ty::ScalarInt;
122    type InternedRegionKind = Interned<'tcx, ty::RegionKind<'tcx>>;
123    type EarlyParamRegion = ty::EarlyParamRegion;
124    type LateParamRegion = ty::LateParamRegion;
125
126    type RegionAssumptions = &'tcx ty::List<ty::ArgOutlivesPredicate<'tcx>>;
127
128    type ParamEnv = ty::ParamEnv<'tcx>;
129    type Predicate = Predicate<'tcx>;
130
131    type Clause = Clause<'tcx>;
132    type Clauses = ty::Clauses<'tcx>;
133
134    type Tracked<T: fmt::Debug + Clone> = WithDepNode<T>;
135    fn mk_tracked<T: fmt::Debug + Clone>(
136        self,
137        data: T,
138        dep_node: DepNodeIndex,
139    ) -> Self::Tracked<T> {
140        WithDepNode::new(dep_node, data)
141    }
142    fn get_tracked<T: fmt::Debug + Clone>(self, tracked: &Self::Tracked<T>) -> T {
143        tracked.get(self)
144    }
145
146    fn with_global_cache<R>(self, f: impl FnOnce(&mut search_graph::GlobalCache<Self>) -> R) -> R {
147        f(&mut *self.new_solver_evaluation_cache.lock())
148    }
149
150    fn canonical_param_env_cache_get_or_insert<R>(
151        self,
152        param_env: ty::ParamEnv<'tcx>,
153        f: impl FnOnce() -> ty::CanonicalParamEnvCacheEntry<Self>,
154        from_entry: impl FnOnce(&ty::CanonicalParamEnvCacheEntry<Self>) -> R,
155    ) -> R {
156        let mut cache = self.new_solver_canonical_param_env_cache.lock();
157        let entry = cache.entry(param_env).or_insert_with(f);
158        from_entry(entry)
159    }
160
161    fn assert_evaluation_is_concurrent(&self) {
162        // Turns out, the assumption for this function isn't perfect.
163        // See trait-system-refactor-initiative#234.
164    }
165
166    fn expand_abstract_consts<T: TypeFoldable<TyCtxt<'tcx>>>(self, t: T) -> T {
167        self.expand_abstract_consts(t)
168    }
169
170    type GenericsOf = &'tcx ty::Generics;
171
172    fn generics_of(self, def_id: DefId) -> &'tcx ty::Generics {
173        self.generics_of(def_id)
174    }
175
176    type VariancesOf = &'tcx [ty::Variance];
177
178    fn variances_of(self, def_id: DefId) -> Self::VariancesOf {
179        self.variances_of(def_id)
180    }
181
182    fn opt_alias_variances(
183        self,
184        kind: impl Into<ty::AliasTermKind<'tcx>>,
185    ) -> Option<&'tcx [ty::Variance]> {
186        self.opt_alias_variances(kind)
187    }
188
189    fn type_of(self, def_id: DefId) -> ty::EarlyBinder<'tcx, Ty<'tcx>> {
190        self.type_of(def_id)
191    }
192    fn type_of_opaque_hir_typeck(self, def_id: LocalDefId) -> ty::EarlyBinder<'tcx, Ty<'tcx>> {
193        self.type_of_opaque_hir_typeck(def_id)
194    }
195    fn is_type_const(self, def_id: DefId) -> bool {
196        self.is_type_const(def_id)
197    }
198    fn const_of_item(self, def_id: DefId) -> ty::EarlyBinder<'tcx, Const<'tcx>> {
199        self.const_of_item(def_id)
200    }
201    fn anon_const_kind(self, def_id: DefId) -> ty::AnonConstKind {
202        self.anon_const_kind(def_id)
203    }
204
205    fn def_span(self, def_id: DefId) -> Span {
206        self.def_span(def_id)
207    }
208
209    type AdtDef = ty::AdtDef<'tcx>;
210    fn adt_def(self, adt_def_id: DefId) -> Self::AdtDef {
211        self.adt_def(adt_def_id)
212    }
213
214    fn alias_const_kind_from_def_id(self, def_id: Self::DefId) -> ty::AliasConstKind<'tcx> {
215        match self.def_kind(def_id) {
216            DefKind::AssocConst { .. } => {
217                if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id)) {
218                    ty::AliasConstKind::Inherent { def_id }
219                } else {
220                    ty::AliasConstKind::Projection { def_id }
221                }
222            }
223            DefKind::Const { .. } => ty::AliasConstKind::Free { def_id },
224            DefKind::AnonConst | DefKind::Ctor(_, CtorKind::Const) => {
225                ty::AliasConstKind::Anon { def_id }
226            }
227            kind => crate::util::bug::bug_fmt(format_args!("unexpected DefKind in AliasConst: {0:?}",
        kind))bug!("unexpected DefKind in AliasConst: {kind:?}"),
228        }
229    }
230
231    fn alias_term_kind_from_def_id(self, def_id: DefId) -> ty::AliasTermKind<'tcx> {
232        match self.def_kind(def_id) {
233            DefKind::AssocTy => {
234                if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id)) {
235                    ty::AliasTermKind::InherentTy { def_id }
236                } else {
237                    ty::AliasTermKind::ProjectionTy { def_id }
238                }
239            }
240            DefKind::AssocConst { .. } => {
241                if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id)) {
242                    ty::AliasTermKind::InherentConst { def_id }
243                } else {
244                    ty::AliasTermKind::ProjectionConst { def_id }
245                }
246            }
247            DefKind::OpaqueTy => ty::AliasTermKind::OpaqueTy { def_id },
248            DefKind::TyAlias => ty::AliasTermKind::FreeTy { def_id },
249            DefKind::Const { .. } => ty::AliasTermKind::FreeConst { def_id },
250            DefKind::AnonConst | DefKind::Ctor(_, CtorKind::Const) => {
251                ty::AliasTermKind::AnonConst { def_id }
252            }
253            kind => crate::util::bug::bug_fmt(format_args!("unexpected DefKind in AliasTy: {0:?}",
        kind))bug!("unexpected DefKind in AliasTy: {kind:?}"),
254        }
255    }
256
257    fn trait_ref_and_own_args_for_alias(
258        self,
259        def_id: DefId,
260        args: ty::GenericArgsRef<'tcx>,
261    ) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) {
262        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 { .. });
263        let trait_def_id = self.parent(def_id);
264        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);
265        let trait_ref = ty::TraitRef::from_assoc(self, trait_def_id, args);
266        (trait_ref, &args[trait_ref.args.len()..])
267    }
268
269    fn mk_args(self, args: &[Self::GenericArg]) -> ty::GenericArgsRef<'tcx> {
270        self.mk_args(args)
271    }
272
273    fn mk_args_from_iter<I, T>(self, args: I) -> T::Output
274    where
275        I: Iterator<Item = T>,
276        T: CollectAndApply<Self::GenericArg, ty::GenericArgsRef<'tcx>>,
277    {
278        self.mk_args_from_iter(args)
279    }
280
281    fn check_args_compatible(self, def_id: DefId, args: ty::GenericArgsRef<'tcx>) -> bool {
282        self.check_args_compatible(def_id, args)
283    }
284
285    fn debug_assert_args_compatible(self, def_id: DefId, args: ty::GenericArgsRef<'tcx>) {
286        self.debug_assert_args_compatible(def_id, args);
287    }
288
289    /// Assert that the args from an `ExistentialTraitRef` or `ExistentialProjection`
290    /// are compatible with the `DefId`. Since we're missing a `Self` type, stick on
291    /// a dummy self type and forward to `debug_assert_args_compatible`.
292    fn debug_assert_existential_args_compatible(
293        self,
294        def_id: Self::DefId,
295        args: Self::GenericArgs,
296    ) {
297        // FIXME: We could perhaps add a `skip: usize` to `debug_assert_args_compatible`
298        // to avoid needing to reintern the set of args...
299        if truecfg!(debug_assertions) {
300            self.debug_assert_args_compatible(
301                def_id,
302                self.mk_args_from_iter(
303                    [self.types.trait_object_dummy_self.into()].into_iter().chain(args.iter()),
304                ),
305            );
306        }
307    }
308
309    fn mk_type_list_from_iter<I, T>(self, args: I) -> T::Output
310    where
311        I: Iterator<Item = T>,
312        T: CollectAndApply<Ty<'tcx>, &'tcx List<Ty<'tcx>>>,
313    {
314        self.mk_type_list_from_iter(args)
315    }
316
317    fn projection_parent(self, def_id: Self::TraitAssocTermId) -> Self::TraitId {
318        self.parent(def_id)
319    }
320
321    fn impl_or_trait_assoc_term_parent(self, def_id: Self::ImplOrTraitAssocTyId) -> DefId {
322        self.parent(def_id)
323    }
324
325    fn inherent_alias_term_parent(self, def_id: Self::InherentAssocTermId) -> Self::ImplId {
326        self.parent(def_id)
327    }
328
329    fn recursion_limit(self) -> usize {
330        self.recursion_limit().0
331    }
332
333    type Features = &'tcx rustc_feature::Features;
334
335    fn features(self) -> Self::Features {
336        self.features()
337    }
338
339    fn assumptions_on_binders(self) -> bool {
340        self.assumptions_on_binders()
341    }
342
343    fn renormalize_rigid_aliases(self) -> bool {
344        self.renormalize_rigid_aliases()
345    }
346
347    fn coroutine_hidden_types(
348        self,
349        def_id: DefId,
350    ) -> ty::EarlyBinder<'tcx, ty::Binder<'tcx, ty::CoroutineWitnessTypes<TyCtxt<'tcx>>>> {
351        self.coroutine_hidden_types(def_id)
352    }
353
354    fn fn_sig(self, def_id: DefId) -> ty::EarlyBinder<'tcx, ty::PolyFnSig<'tcx>> {
355        self.fn_sig(def_id)
356    }
357
358    fn coroutine_movability(self, def_id: DefId) -> rustc_ast::Movability {
359        self.coroutine_movability(def_id)
360    }
361
362    fn coroutine_for_closure(self, def_id: DefId) -> DefId {
363        self.coroutine_for_closure(def_id)
364    }
365
366    fn generics_require_sized_self(self, def_id: DefId) -> bool {
367        self.generics_require_sized_self(def_id)
368    }
369
370    fn item_bounds(
371        self,
372        def_id: DefId,
373    ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
374        self.item_bounds(def_id).map_bound(IntoIterator::into_iter)
375    }
376
377    fn item_self_bounds(
378        self,
379        def_id: DefId,
380    ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
381        self.item_self_bounds(def_id).map_bound(IntoIterator::into_iter)
382    }
383
384    fn item_non_self_bounds(
385        self,
386        def_id: DefId,
387    ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
388        self.item_non_self_bounds(def_id).map_bound(IntoIterator::into_iter)
389    }
390
391    fn clauses_of(
392        self,
393        def_id: DefId,
394    ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
395        ty::EarlyBinder::bind_iter(
396            self.clauses_of(def_id)
397                .instantiate_identity(self)
398                .clauses
399                .into_iter()
400                .map(Unnormalized::skip_normalization),
401        )
402    }
403
404    fn own_clauses_of(
405        self,
406        def_id: DefId,
407    ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
408        ty::EarlyBinder::bind_iter(
409            self.clauses_of(def_id)
410                .instantiate_own_identity()
411                .map(|(clause, _)| clause.skip_normalization()),
412        )
413    }
414
415    fn explicit_super_clauses_of(
416        self,
417        def_id: DefId,
418    ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = (ty::Clause<'tcx>, Span)>> {
419        self.explicit_super_clauses_of(def_id).map_bound(|preds| preds.into_iter().copied())
420    }
421
422    fn explicit_implied_clauses_of(
423        self,
424        def_id: DefId,
425    ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = (ty::Clause<'tcx>, Span)>> {
426        self.explicit_implied_clauses_of(def_id).map_bound(|preds| preds.into_iter().copied())
427    }
428
429    fn impl_super_outlives(
430        self,
431        impl_def_id: DefId,
432    ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
433        self.impl_super_outlives(impl_def_id)
434    }
435
436    fn impl_is_const(self, def_id: DefId) -> bool {
437        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 });
438        self.is_conditionally_const(def_id)
439    }
440
441    fn fn_is_const(self, def_id: DefId) -> bool {
442        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!(
443            self.def_kind(def_id),
444            DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(_, CtorKind::Fn)
445        );
446        self.is_conditionally_const(def_id)
447    }
448
449    fn closure_is_const(self, def_id: DefId) -> bool {
450        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);
451        #[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 })
452    }
453
454    fn alias_has_const_conditions(self, def_id: DefId) -> bool {
455        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);
456        self.is_conditionally_const(def_id)
457    }
458
459    fn const_conditions(
460        self,
461        def_id: DefId,
462    ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Binder<'tcx, ty::TraitRef<'tcx>>>> {
463        ty::EarlyBinder::bind_iter(
464            self.const_conditions(def_id)
465                .instantiate_identity(self)
466                .into_iter()
467                .map(|(c, _)| c.skip_normalization()),
468        )
469    }
470
471    fn explicit_implied_const_bounds(
472        self,
473        def_id: DefId,
474    ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Binder<'tcx, ty::TraitRef<'tcx>>>> {
475        ty::EarlyBinder::bind_iter(
476            self.explicit_implied_const_bounds(def_id)
477                .iter_identity_copied()
478                .map(Unnormalized::skip_normalization)
479                .map(|(c, _)| c),
480        )
481    }
482
483    fn impl_self_is_guaranteed_unsized(self, impl_def_id: DefId) -> bool {
484        self.impl_self_is_guaranteed_unsized(impl_def_id)
485    }
486
487    fn has_target_features(self, def_id: DefId) -> bool {
488        !self.codegen_fn_attrs(def_id).target_features.is_empty()
489    }
490
491    fn require_projection_lang_item(self, lang_item: SolverProjectionLangItem) -> DefId {
492        self.require_lang_item(solver_lang_item_to_lang_item(lang_item), DUMMY_SP)
493    }
494
495    fn require_trait_lang_item(self, lang_item: SolverTraitLangItem) -> DefId {
496        self.require_lang_item(solver_trait_lang_item_to_lang_item(lang_item), DUMMY_SP)
497    }
498
499    fn require_adt_lang_item(self, lang_item: SolverAdtLangItem) -> DefId {
500        self.require_lang_item(solver_adt_lang_item_to_lang_item(lang_item), DUMMY_SP)
501    }
502
503    fn is_projection_lang_item(self, def_id: DefId, lang_item: SolverProjectionLangItem) -> bool {
504        self.is_lang_item(def_id, solver_lang_item_to_lang_item(lang_item))
505    }
506
507    fn is_trait_lang_item(self, def_id: DefId, lang_item: SolverTraitLangItem) -> bool {
508        self.is_lang_item(def_id, solver_trait_lang_item_to_lang_item(lang_item))
509    }
510
511    fn is_adt_lang_item(self, def_id: DefId, lang_item: SolverAdtLangItem) -> bool {
512        self.is_lang_item(def_id, solver_adt_lang_item_to_lang_item(lang_item))
513    }
514
515    fn is_default_trait(self, def_id: DefId) -> bool {
516        self.is_default_trait(def_id)
517    }
518
519    fn is_sizedness_trait(self, def_id: DefId) -> bool {
520        self.is_sizedness_trait(def_id)
521    }
522
523    fn as_projection_lang_item(self, def_id: DefId) -> Option<SolverProjectionLangItem> {
524        lang_item_to_solver_lang_item(self.lang_items().from_def_id(def_id)?)
525    }
526
527    fn as_trait_lang_item(self, def_id: DefId) -> Option<SolverTraitLangItem> {
528        lang_item_to_solver_trait_lang_item(self.lang_items().from_def_id(def_id)?)
529    }
530
531    fn as_adt_lang_item(self, def_id: DefId) -> Option<SolverAdtLangItem> {
532        lang_item_to_solver_adt_lang_item(self.lang_items().from_def_id(def_id)?)
533    }
534
535    fn associated_type_def_ids(self, def_id: DefId) -> impl IntoIterator<Item = DefId> {
536        self.associated_items(def_id)
537            .in_definition_order()
538            .filter(|assoc_item| assoc_item.is_type())
539            .map(|assoc_item| assoc_item.def_id)
540    }
541
542    // This implementation is a bit different from `TyCtxt::for_each_relevant_impl`,
543    // since we want to skip over blanket impls for non-rigid aliases, and also we
544    // only want to consider types that *actually* unify with float/int vars.
545    fn for_each_relevant_impl<R: VisitorResult>(
546        self,
547        trait_ref: ty::TraitRef<'tcx>,
548        mut f: impl FnMut(DefId) -> R,
549    ) -> R {
550        macro_rules! ret {
551            ($e: expr) => {
552                match $e.branch() {
553                    ControlFlow::Break(b) => return R::from_residual(b),
554                    ControlFlow::Continue(()) => {}
555                }
556            };
557        }
558
559        let trait_def_id = trait_ref.def_id;
560        let self_ty = trait_ref.self_ty();
561        let tcx = self;
562        let trait_impls = tcx.trait_impls_of(trait_def_id);
563        let mut consider_impls_for_simplified_type = |simp| {
564            if let Some(impls_for_type) = trait_impls.non_blanket_impls().get(&simp) {
565                for &impl_def_id in impls_for_type {
566                    match f(impl_def_id).branch() {
    ControlFlow::Break(b) => return R::from_residual(b),
    ControlFlow::Continue(()) => {}
}ret!(f(impl_def_id))
567                }
568            }
569
570            R::output()
571        };
572
573        match self_ty.kind() {
574            ty::Bool
575            | ty::Char
576            | ty::Int(_)
577            | ty::Uint(_)
578            | ty::Float(_)
579            | ty::Adt(_, _)
580            | ty::Foreign(_)
581            | ty::Str
582            | ty::Array(_, _)
583            | ty::Pat(_, _)
584            | ty::Slice(_)
585            | ty::RawPtr(_, _)
586            | ty::Ref(_, _, _)
587            | ty::FnDef(_, _)
588            | ty::FnPtr(..)
589            | ty::Dynamic(_, _)
590            | ty::Closure(..)
591            | ty::CoroutineClosure(..)
592            | ty::Coroutine(_, _)
593            | ty::Never
594            | ty::Tuple(_)
595            | ty::UnsafeBinder(_) => {
596                if let Some(simp) = ty::fast_reject::simplify_type(
597                    tcx,
598                    self_ty,
599                    ty::fast_reject::TreatParams::AsRigid,
600                ) {
601                    match consider_impls_for_simplified_type(simp).branch() {
    ControlFlow::Break(b) => return R::from_residual(b),
    ControlFlow::Continue(()) => {}
};ret!(consider_impls_for_simplified_type(simp));
602                }
603            }
604
605            // HACK: For integer and float variables we have to manually look at all impls
606            // which have some integer or float as a self type.
607            ty::Infer(ty::IntVar(_)) => {
608                use ty::IntTy::*;
609                use ty::UintTy::*;
610                // This causes a compiler error if any new integer kinds are added.
611                let (I8 | I16 | I32 | I64 | I128 | Isize): ty::IntTy;
612                let (U8 | U16 | U32 | U64 | U128 | Usize): ty::UintTy;
613                let possible_integers = [
614                    // signed integers
615                    ty::SimplifiedType::Int(I8),
616                    ty::SimplifiedType::Int(I16),
617                    ty::SimplifiedType::Int(I32),
618                    ty::SimplifiedType::Int(I64),
619                    ty::SimplifiedType::Int(I128),
620                    ty::SimplifiedType::Int(Isize),
621                    // unsigned integers
622                    ty::SimplifiedType::Uint(U8),
623                    ty::SimplifiedType::Uint(U16),
624                    ty::SimplifiedType::Uint(U32),
625                    ty::SimplifiedType::Uint(U64),
626                    ty::SimplifiedType::Uint(U128),
627                    ty::SimplifiedType::Uint(Usize),
628                ];
629                for simp in possible_integers {
630                    match consider_impls_for_simplified_type(simp).branch() {
    ControlFlow::Break(b) => return R::from_residual(b),
    ControlFlow::Continue(()) => {}
};ret!(consider_impls_for_simplified_type(simp));
631                }
632            }
633
634            ty::Infer(ty::FloatVar(_)) => {
635                // This causes a compiler error if any new float kinds are added.
636                let (ty::FloatTy::F16 | ty::FloatTy::F32 | ty::FloatTy::F64 | ty::FloatTy::F128);
637                let possible_floats = [
638                    ty::SimplifiedType::Float(ty::FloatTy::F16),
639                    ty::SimplifiedType::Float(ty::FloatTy::F32),
640                    ty::SimplifiedType::Float(ty::FloatTy::F64),
641                    ty::SimplifiedType::Float(ty::FloatTy::F128),
642                ];
643
644                for simp in possible_floats {
645                    match consider_impls_for_simplified_type(simp).branch() {
    ControlFlow::Break(b) => return R::from_residual(b),
    ControlFlow::Continue(()) => {}
};ret!(consider_impls_for_simplified_type(simp));
646                }
647            }
648
649            // The only traits applying to aliases and placeholders are blanket impls.
650            //
651            // Impls which apply to an alias after normalization are handled by
652            // `assemble_candidates_after_normalizing_self_ty`.
653            ty::Alias(ty::IsRigid::Yes, _) | ty::Placeholder(..) | ty::Error(_) => (),
654            // FIXME(-Znext-solver=no): Need to support aliases not marked as
655            // rigid for the old solver.
656            ty::Alias(ty::IsRigid::No, _) => (),
657
658            // FIXME: These should ideally not exist as a self type. It would be nice for
659            // the builtin auto trait impls of coroutines to instead directly recurse
660            // into the witness.
661            ty::CoroutineWitness(..) => (),
662
663            // These variants should not exist as a self type.
664            ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_))
665            | ty::Param(_)
666            | ty::Bound(_, _) => crate::util::bug::bug_fmt(format_args!("unexpected self type: {0}", self_ty))bug!("unexpected self type: {self_ty}"),
667        }
668
669        #[allow(rustc::usage_of_type_ir_traits)]
670        self.for_each_blanket_impl(trait_def_id, f)
671    }
672    fn for_each_blanket_impl<R: VisitorResult>(
673        self,
674        trait_def_id: DefId,
675        mut f: impl FnMut(DefId) -> R,
676    ) -> R {
677        let trait_impls = self.trait_impls_of(trait_def_id);
678        for &impl_def_id in trait_impls.blanket_impls() {
679            match f(impl_def_id).branch() {
680                ControlFlow::Break(b) => return R::from_residual(b),
681                ControlFlow::Continue(()) => {}
682            }
683        }
684
685        R::output()
686    }
687
688    fn has_item_definition(self, def_id: DefId) -> bool {
689        self.defaultness(def_id).has_value()
690    }
691
692    fn impl_specializes(self, impl_def_id: Self::DefId, victim_def_id: Self::DefId) -> bool {
693        self.specializes((impl_def_id, victim_def_id))
694    }
695
696    fn impl_is_default(self, impl_def_id: DefId) -> bool {
697        self.defaultness(impl_def_id).is_default()
698    }
699
700    fn impl_trait_ref(self, impl_def_id: DefId) -> ty::EarlyBinder<'tcx, ty::TraitRef<'tcx>> {
701        self.impl_trait_ref(impl_def_id)
702    }
703
704    fn impl_polarity(self, impl_def_id: DefId) -> ty::ImplPolarity {
705        self.impl_polarity(impl_def_id)
706    }
707
708    fn is_fully_generic_for_reflection(self, impl_def_id: Self::ImplId) -> bool {
709        self.impl_is_fully_generic_for_reflection(impl_def_id)
710    }
711
712    fn trait_is_auto(self, trait_def_id: DefId) -> bool {
713        self.trait_is_auto(trait_def_id)
714    }
715
716    fn trait_is_coinductive(self, trait_def_id: DefId) -> bool {
717        self.trait_is_coinductive(trait_def_id)
718    }
719
720    fn trait_is_alias(self, trait_def_id: DefId) -> bool {
721        self.trait_is_alias(trait_def_id)
722    }
723
724    fn trait_is_dyn_compatible(self, trait_def_id: DefId) -> bool {
725        self.is_dyn_compatible(trait_def_id)
726    }
727
728    fn trait_is_fundamental(self, def_id: DefId) -> bool {
729        self.trait_def(def_id).is_fundamental
730    }
731
732    fn trait_is_unsafe(self, trait_def_id: Self::DefId) -> bool {
733        self.trait_def(trait_def_id).safety.is_unsafe()
734    }
735
736    fn is_impl_trait_in_trait(self, def_id: DefId) -> bool {
737        self.is_impl_trait_in_trait(def_id)
738    }
739
740    fn delay_bug(self, msg: impl ToString) -> ErrorGuaranteed {
741        self.dcx().span_delayed_bug(DUMMY_SP, msg.to_string())
742    }
743
744    fn is_general_coroutine(self, coroutine_def_id: DefId) -> bool {
745        self.is_general_coroutine(coroutine_def_id)
746    }
747
748    fn coroutine_is_async(self, coroutine_def_id: DefId) -> bool {
749        self.coroutine_is_async(coroutine_def_id)
750    }
751
752    fn coroutine_is_gen(self, coroutine_def_id: DefId) -> bool {
753        self.coroutine_is_gen(coroutine_def_id)
754    }
755
756    fn coroutine_is_async_gen(self, coroutine_def_id: DefId) -> bool {
757        self.coroutine_is_async_gen(coroutine_def_id)
758    }
759
760    type UnsizingParams = &'tcx rustc_index::bit_set::DenseBitSet<u32>;
761    fn unsizing_params_for_adt(self, adt_def_id: DefId) -> Self::UnsizingParams {
762        self.unsizing_params_for_adt(adt_def_id)
763    }
764
765    fn anonymize_bound_vars<T: TypeFoldable<TyCtxt<'tcx>>>(
766        self,
767        binder: ty::Binder<'tcx, T>,
768    ) -> ty::Binder<'tcx, T> {
769        self.anonymize_bound_vars(binder)
770    }
771
772    fn opaque_types_defined_by(self, defining_anchor: LocalDefId) -> Self::LocalDefIds {
773        self.opaque_types_defined_by(defining_anchor)
774    }
775
776    fn opaque_types_and_coroutines_defined_by(
777        self,
778        defining_anchor: Self::LocalDefId,
779    ) -> Self::LocalDefIds {
780        let coroutines_defined_by = self
781            .nested_bodies_within(defining_anchor)
782            .iter()
783            .filter(|def_id| self.is_coroutine(def_id.to_def_id()));
784        self.mk_local_def_ids_from_iter(
785            self.opaque_types_defined_by(defining_anchor).iter().chain(coroutines_defined_by),
786        )
787    }
788
789    type Probe = &'tcx inspect::Probe<TyCtxt<'tcx>>;
790    fn mk_probe(self, probe: inspect::Probe<Self>) -> &'tcx inspect::Probe<TyCtxt<'tcx>> {
791        self.arena.alloc(probe)
792    }
793    fn evaluate_root_goal_for_proof_tree_raw(
794        self,
795        canonical_goal: CanonicalInput<'tcx>,
796        root_depth: usize,
797    ) -> (QueryResult<'tcx>, &'tcx inspect::Probe<TyCtxt<'tcx>>) {
798        self.evaluate_root_goal_for_proof_tree_raw((canonical_goal, root_depth))
799    }
800
801    fn emit_next_solver_overflow_fcw(self, predicate: ty::Predicate<'tcx>, span: Span) {
802        self.emit_node_span_lint(
803            rustc_session::lint::builtin::RECURSION_DEPTH_EXCEEDING_LIMIT,
804            CRATE_HIR_ID,
805            span,
806            rustc_errors::DiagDecorator(|diag| {
807                // FIXME: share this with overflow error in fulfillment instead of duplicating.
808                let pred_str = {
809                    let s = predicate.to_string();
810                    if s.len() > 50 {
811                        let mut p: FmtPrinter<'_, '_> =
812                            FmtPrinter::new_with_limit(self, Namespace::TypeNS, Limit(6));
813                        predicate.print(&mut p).unwrap();
814                        p.into_buffer()
815                    } else {
816                        s
817                    }
818                };
819                diag.primary_message(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("overflow evaluating the requirement `{0}`",
                pred_str))
    })format!(
820                    "overflow evaluating the requirement `{pred_str}`",
821                ));
822                diag.help(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("consider increasing the recursion limit by adding a `#![recursion_limit = \"{0}\"]` attribute to your crate (`{1}`)",
                self.recursion_limit() * 2, self.crate_name(LOCAL_CRATE)))
    })format!(
823                    "consider increasing the recursion limit by adding a \
824                     `#![recursion_limit = \"{}\"]` attribute to your crate (`{}`)",
825                    self.recursion_limit() * 2,
826                    self.crate_name(LOCAL_CRATE),
827                ));
828                diag.help(
829                    "or consider adding a manual `impl` of auto traits like `Send` for intermediate types, if auto traits are involved",
830                );
831                diag.note("this lint is attached to the whole crate and can't be disabled on a per-function basis");
832            }),
833        )
834    }
835
836    fn item_name(self, id: DefId) -> Symbol {
837        self.opt_item_name(id).unwrap_or_else(|| {
838            crate::util::bug::bug_fmt(format_args!("item_name: no name for {0:?}",
        self.def_path(id)));bug!("item_name: no name for {:?}", self.def_path(id));
839        })
840    }
841
842    fn get_anon_re_bounds_lifetime(self, idx: usize, var_idx: usize) -> Option<Region<'tcx>> {
843        if let Some(inner) = self.lifetimes.anon_re_bounds.get(idx) {
844            inner.get(var_idx).copied()
845        } else {
846            None
847        }
848    }
849
850    fn get_anon_re_canonical_bounds_lifetime(self, idx: usize) -> Option<Region<'tcx>> {
851        self.lifetimes.anon_re_canonical_bounds.get(idx).copied()
852    }
853
854    fn get_re_static_lifetime(self) -> Region<'tcx> {
855        self.lifetimes.re_static
856    }
857
858    fn intern_region(self, region_kind: RegionKind<'tcx>) -> Region<'tcx> {
859        self.intern_region(region_kind)
860    }
861
862    fn intern_bound_region(
863        self,
864        debruijn: DebruijnIndex,
865        bound_region: BoundRegion<'tcx>,
866    ) -> Region<'tcx> {
867        // Use a pre-interned one when possible.
868        if let ty::BoundRegion { var, kind: ty::BoundRegionKind::Anon } = bound_region
869            && let Some(inner) = self.lifetimes.anon_re_bounds.get(debruijn.as_usize())
870            && let Some(re) = inner.get(var.as_usize()).copied()
871        {
872            re
873        } else {
874            self.intern_region(ty::ReBound(ty::BoundVarIndexKind::Bound(debruijn), bound_region))
875        }
876    }
877
878    fn intern_canonical_bound(self, var: BoundVar) -> Region<'tcx> {
879        // Use a pre-interned one when possible.
880        if let Some(re) = self.lifetimes.anon_re_canonical_bounds.get(var.as_usize()).copied() {
881            re
882        } else {
883            self.intern_region(ty::ReBound(
884                ty::BoundVarIndexKind::Canonical,
885                BoundRegion { var, kind: ty::BoundRegionKind::Anon },
886            ))
887        }
888    }
889}
890
891impl<'tcx, T: std::fmt::Debug + Clone + Copy> rustc_type_ir::intern::Interned<TyCtxt<'tcx>>
892    for Interned<'tcx, T>
893{
894    type Value = T;
895    fn get(self) -> T {
896        *self.0
897    }
898}
899
900/// Defines trivial conversion functions between the main [`LangItem`] enum,
901/// and some other lang-item enum that is a subset of it.
902macro_rules! bidirectional_lang_item_map {
903    (
904        $solver_ty:ident, fn $to_solver:ident, fn $from_solver:ident;
905        $($name:ident),+ $(,)?
906    ) => {
907        fn $from_solver(lang_item: $solver_ty) -> LangItem {
908            match lang_item {
909                $($solver_ty::$name => LangItem::$name,)+
910            }
911        }
912
913        fn $to_solver(lang_item: LangItem) -> Option<$solver_ty> {
914            Some(match lang_item {
915                $(LangItem::$name => $solver_ty::$name,)+
916                _ => return None,
917            })
918        }
919    }
920}
921
922fn 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! {
923    SolverProjectionLangItem, fn lang_item_to_solver_lang_item, fn solver_lang_item_to_lang_item;
924
925// tidy-alphabetical-start
926    AsyncFnKindUpvars,
927    AsyncFnOnceOutput,
928    CallOnceFuture,
929    CallRefFuture,
930    CoroutineReturn,
931    CoroutineYield,
932    FieldBase,
933    FieldType,
934    FutureOutput,
935    Metadata,
936// tidy-alphabetical-end
937}
938
939fn solver_adt_lang_item_to_lang_item(lang_item: SolverAdtLangItem)
    -> LangItem {
    match lang_item {
        SolverAdtLangItem::DynMetadata => LangItem::DynMetadata,
        SolverAdtLangItem::Option => LangItem::Option,
        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::Poll => SolverAdtLangItem::Poll,
            _ => return None,
        })
}bidirectional_lang_item_map! {
940    SolverAdtLangItem, fn lang_item_to_solver_adt_lang_item, fn solver_adt_lang_item_to_lang_item;
941
942// tidy-alphabetical-start
943    DynMetadata,
944    Option,
945    Poll,
946// tidy-alphabetical-end
947}
948
949fn 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! {
950    SolverTraitLangItem, fn lang_item_to_solver_trait_lang_item, fn solver_trait_lang_item_to_lang_item;
951
952// tidy-alphabetical-start
953    AsyncFn,
954    AsyncFnKindHelper,
955    AsyncFnMut,
956    AsyncFnOnce,
957    AsyncIterator,
958    BikeshedGuaranteedNoDrop,
959    Clone,
960    Copy,
961    Coroutine,
962    Destruct,
963    DiscriminantKind,
964    Drop,
965    Field,
966    Fn,
967    FnMut,
968    FnOnce,
969    FnPtrTrait,
970    FusedIterator,
971    Future,
972    Iterator,
973    MetaSized,
974    PointeeSized,
975    PointeeTrait,
976    Sized,
977    TransmuteTrait,
978    TrivialClone,
979    TryAsDyn,
980    Tuple,
981    Unpin,
982    Unsize,
983// tidy-alphabetical-end
984}