Skip to main content

rustc_type_ir/
inherent.rs

1//! Set of traits which are used to emulate the inherent impls that are present in `rustc_middle`.
2//! It is customary to glob-import `rustc_type_ir::inherent::*` to bring all of these traits into
3//! scope when programming in interner-agnostic settings, and to avoid importing any of these
4//! directly elsewhere (i.e. specify the full path for an implementation downstream).
5
6use std::fmt::Debug;
7use std::hash::Hash;
8
9use rustc_ast_ir::Mutability;
10
11use crate::elaborate::Elaboratable;
12use crate::fold::{TypeFoldable, TypeSuperFoldable};
13use crate::relate::Relate;
14use crate::solve::{AdtDestructorKind, SizedTraitKind};
15use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable};
16use crate::{
17    self as ty, ClauseKind, CollectAndApply, FieldInfo, Interner, PredicateKind, Region, UpcastFrom,
18};
19
20#[rust_analyzer::prefer_underscore_import]
21pub trait Ty<I: Interner<Ty = Self>>:
22    Copy
23    + Debug
24    + Hash
25    + Eq
26    + Into<I::GenericArg>
27    + Into<I::Term>
28    + IntoKind<Kind = ty::TyKind<I>>
29    + TypeSuperVisitable<I>
30    + TypeSuperFoldable<I>
31    + Relate<I>
32    + Flags
33{
34    fn new_unit(interner: I) -> Self;
35
36    fn new_bool(interner: I) -> Self;
37
38    fn new_u8(interner: I) -> Self;
39
40    fn new_usize(interner: I) -> Self;
41
42    fn new_infer(interner: I, var: ty::InferTy) -> Self;
43
44    fn new_var(interner: I, var: ty::TyVid) -> Self;
45
46    fn new_param(interner: I, param: I::ParamTy) -> Self;
47
48    fn new_placeholder(interner: I, param: ty::PlaceholderType<I>) -> Self;
49
50    fn new_bound(interner: I, debruijn: ty::DebruijnIndex, var: ty::BoundTy<I>) -> Self;
51
52    fn new_anon_bound(interner: I, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self;
53
54    fn new_canonical_bound(interner: I, var: ty::BoundVar) -> Self;
55
56    fn new_alias(interner: I, is_rigid: ty::IsRigid, alias_ty: ty::AliasTy<I>) -> Self;
57
58    fn new_projection_from_args(
59        interner: I,
60        is_rigid: ty::IsRigid,
61        def_id: I::TraitAssocTyId,
62        args: I::GenericArgs,
63    ) -> Self {
64        Self::new_alias(
65            interner,
66            is_rigid,
67            ty::AliasTy::new_from_args(interner, ty::AliasTyKind::Projection { def_id }, args),
68        )
69    }
70
71    fn new_projection(
72        interner: I,
73        is_rigid: ty::IsRigid,
74        def_id: I::TraitAssocTyId,
75        args: impl IntoIterator<Item: Into<I::GenericArg>>,
76    ) -> Self {
77        Self::new_alias(
78            interner,
79            is_rigid,
80            ty::AliasTy::new(interner, ty::AliasTyKind::Projection { def_id }, args),
81        )
82    }
83
84    fn new_error(interner: I, guar: I::ErrorGuaranteed) -> Self;
85
86    fn new_adt(interner: I, adt_def: I::AdtDef, args: I::GenericArgs) -> Self;
87
88    fn new_foreign(interner: I, def_id: I::ForeignId) -> Self;
89
90    fn new_dynamic(interner: I, preds: I::BoundExistentialPredicates, region: Region<I>) -> Self;
91
92    fn new_coroutine(interner: I, def_id: I::CoroutineId, args: I::GenericArgs) -> Self;
93
94    fn new_coroutine_closure(
95        interner: I,
96        def_id: I::CoroutineClosureId,
97        args: I::GenericArgs,
98    ) -> Self;
99
100    fn new_closure(interner: I, def_id: I::ClosureId, args: I::GenericArgs) -> Self;
101
102    fn new_coroutine_witness(interner: I, def_id: I::CoroutineId, args: I::GenericArgs) -> Self;
103
104    fn new_coroutine_witness_for_coroutine(
105        interner: I,
106        def_id: I::CoroutineId,
107        coroutine_args: I::GenericArgs,
108    ) -> Self;
109
110    fn new_ptr(interner: I, ty: Self, mutbl: Mutability) -> Self;
111
112    fn new_ref(interner: I, region: Region<I>, ty: Self, mutbl: Mutability) -> Self;
113
114    fn new_array_with_const_len(interner: I, ty: Self, len: I::Const) -> Self;
115
116    fn new_slice(interner: I, ty: Self) -> Self;
117
118    fn new_tup(interner: I, tys: &[I::Ty]) -> Self;
119
120    fn new_tup_from_iter<It, T>(interner: I, iter: It) -> T::Output
121    where
122        It: Iterator<Item = T>,
123        T: CollectAndApply<Self, Self>;
124
125    fn new_fn_def(interner: I, def_id: I::FunctionId, args: ty::Binder<I, I::GenericArgs>) -> Self;
126
127    fn new_fn_ptr(interner: I, sig: ty::Binder<I, ty::FnSig<I>>) -> Self;
128
129    fn new_pat(interner: I, ty: Self, pat: I::Pat) -> Self;
130
131    fn new_unsafe_binder(interner: I, ty: ty::Binder<I, I::Ty>) -> Self;
132
133    fn tuple_fields(self) -> I::Tys;
134
135    fn to_opt_closure_kind(self) -> Option<ty::ClosureKind>;
136
137    fn from_closure_kind(interner: I, kind: ty::ClosureKind) -> Self;
138
139    fn from_coroutine_closure_kind(interner: I, kind: ty::ClosureKind) -> Self;
140
141    fn is_ty_var(self) -> bool {
142        #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
    ty::Infer(ty::TyVar(_)) => true,
    _ => false,
}matches!(self.kind(), ty::Infer(ty::TyVar(_)))
143    }
144
145    fn is_ty_error(self) -> bool {
146        #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
    ty::Error(_) => true,
    _ => false,
}matches!(self.kind(), ty::Error(_))
147    }
148
149    fn is_floating_point(self) -> bool {
150        #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
    ty::Float(_) | ty::Infer(ty::FloatVar(_)) => true,
    _ => false,
}matches!(self.kind(), ty::Float(_) | ty::Infer(ty::FloatVar(_)))
151    }
152
153    fn is_integral(self) -> bool {
154        #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
    ty::Infer(ty::IntVar(_)) | ty::Int(_) | ty::Uint(_) => true,
    _ => false,
}matches!(self.kind(), ty::Infer(ty::IntVar(_)) | ty::Int(_) | ty::Uint(_))
155    }
156
157    fn is_fn_ptr(self) -> bool {
158        #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
    ty::FnPtr(..) => true,
    _ => false,
}matches!(self.kind(), ty::FnPtr(..))
159    }
160
161    /// Checks whether this type is an ADT that has unsafe fields.
162    fn has_unsafe_fields(self) -> bool;
163
164    fn fn_sig(self, interner: I) -> ty::Binder<I, ty::FnSig<I>> {
165        self.kind().fn_sig(interner)
166    }
167
168    fn discriminant_ty(self, interner: I) -> I::Ty;
169
170    fn is_known_rigid(self) -> bool {
171        self.kind().is_known_rigid()
172    }
173
174    fn is_guaranteed_unsized_raw(self) -> bool {
175        match self.kind() {
176            ty::Dynamic(_, _) | ty::Slice(_) | ty::Str => true,
177            ty::Bool
178            | ty::Char
179            | ty::Int(_)
180            | ty::Uint(_)
181            | ty::Float(_)
182            | ty::Adt(_, _)
183            | ty::Foreign(_)
184            | ty::Array(_, _)
185            | ty::Pat(_, _)
186            | ty::RawPtr(_, _)
187            | ty::Ref(_, _, _)
188            | ty::FnDef(_, _)
189            | ty::FnPtr(_, _)
190            | ty::UnsafeBinder(_)
191            | ty::Closure(_, _)
192            | ty::CoroutineClosure(_, _)
193            | ty::Coroutine(_, _)
194            | ty::CoroutineWitness(_, _)
195            | ty::Never
196            | ty::Tuple(_)
197            | ty::Alias(_, _)
198            | ty::Param(_)
199            | ty::Bound(_, _)
200            | ty::Placeholder(_)
201            | ty::Infer(_)
202            | ty::Error(_) => false,
203        }
204    }
205}
206
207#[rust_analyzer::prefer_underscore_import]
208pub trait Tys<I: Interner<Tys = Self>>:
209    Copy + Debug + Hash + Eq + SliceLike<Item = I::Ty> + TypeFoldable<I> + Default
210{
211    fn inputs(self) -> I::FnInputTys;
212
213    fn output(self) -> I::Ty;
214}
215
216#[rust_analyzer::prefer_underscore_import]
217pub trait Safety<I: Interner<Safety = Self>>: Copy + Debug + Hash + Eq {
218    /// The `safe` safety mode.
219    fn safe() -> Self;
220
221    /// The `unsafe` safety mode.
222    fn unsafe_mode() -> Self;
223
224    /// Is the safety mode `Safe`?
225    fn is_safe(self) -> bool;
226
227    /// The string prefix for this safety mode.
228    fn prefix_str(self) -> &'static str;
229}
230
231pub trait Const<I: Interner<Const = Self>>:
232    Copy
233    + Debug
234    + Hash
235    + Eq
236    + Into<I::GenericArg>
237    + Into<I::Term>
238    + IntoKind<Kind = ty::ConstKind<I>>
239    + TypeSuperVisitable<I>
240    + TypeSuperFoldable<I>
241    + Relate<I>
242    + Flags
243{
244    fn new_infer(interner: I, var: ty::InferConst) -> Self;
245
246    fn new_var(interner: I, var: ty::ConstVid) -> Self;
247
248    fn new_bound(interner: I, debruijn: ty::DebruijnIndex, bound_const: ty::BoundConst<I>) -> Self;
249
250    fn new_anon_bound(interner: I, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self;
251
252    fn new_canonical_bound(interner: I, var: ty::BoundVar) -> Self;
253
254    fn new_placeholder(interner: I, param: ty::PlaceholderConst<I>) -> Self;
255
256    fn new_alias(interner: I, is_rigid: ty::IsRigid, alias_const: ty::AliasConst<I>) -> Self;
257
258    fn new_expr(interner: I, expr: I::ExprConst) -> Self;
259
260    fn new_error(interner: I, guar: I::ErrorGuaranteed) -> Self;
261
262    fn new_error_with_message(interner: I, msg: impl ToString) -> Self {
263        Self::new_error(interner, interner.delay_bug(msg))
264    }
265
266    fn is_ct_var(self) -> bool {
267        #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
    ty::ConstKind::Infer(ty::InferConst::Var(_)) => true,
    _ => false,
}matches!(self.kind(), ty::ConstKind::Infer(ty::InferConst::Var(_)))
268    }
269
270    fn is_ct_error(self) -> bool {
271        #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
    ty::ConstKind::Error(_) => true,
    _ => false,
}matches!(self.kind(), ty::ConstKind::Error(_))
272    }
273}
274
275#[rust_analyzer::prefer_underscore_import]
276pub trait ValueConst<I: Interner<ValueConst = Self>>: Copy + Debug + Hash + Eq {
277    fn ty(self) -> I::Ty;
278    fn valtree(self) -> I::ValTree;
279}
280
281#[rust_analyzer::prefer_underscore_import]
282pub trait ExprConst<I: Interner<ExprConst = Self>>: Copy + Debug + Hash + Eq + Relate<I> {
283    fn args(self) -> I::GenericArgs;
284}
285
286#[rust_analyzer::prefer_underscore_import]
287pub trait GenericsOf<I: Interner<GenericsOf = Self>> {
288    fn count(&self) -> usize;
289}
290
291#[rust_analyzer::prefer_underscore_import]
292pub trait GenericArg<I: Interner<GenericArg = Self>>:
293    Copy
294    + Debug
295    + Hash
296    + Eq
297    + IntoKind<Kind = ty::GenericArgKind<I>>
298    + TypeVisitable<I>
299    + Relate<I>
300    + From<I::Ty>
301    + From<Region<I>>
302    + From<I::Const>
303    + From<I::Term>
304{
305    fn as_term(&self) -> Option<I::Term> {
306        match self.kind() {
307            ty::GenericArgKind::Lifetime(_) => None,
308            ty::GenericArgKind::Type(ty) => Some(ty.into()),
309            ty::GenericArgKind::Const(ct) => Some(ct.into()),
310        }
311    }
312
313    fn as_type(&self) -> Option<I::Ty> {
314        if let ty::GenericArgKind::Type(ty) = self.kind() { Some(ty) } else { None }
315    }
316
317    fn expect_ty(&self) -> I::Ty {
318        self.as_type().expect("expected a type")
319    }
320
321    fn as_const(&self) -> Option<I::Const> {
322        if let ty::GenericArgKind::Const(c) = self.kind() { Some(c) } else { None }
323    }
324
325    fn expect_const(&self) -> I::Const {
326        self.as_const().expect("expected a const")
327    }
328
329    fn as_region(&self) -> Option<Region<I>> {
330        if let ty::GenericArgKind::Lifetime(c) = self.kind() { Some(c) } else { None }
331    }
332
333    fn expect_region(&self) -> Region<I> {
334        self.as_region().expect("expected a const")
335    }
336
337    fn is_non_region_infer(self) -> bool {
338        match self.kind() {
339            ty::GenericArgKind::Lifetime(_) => false,
340            ty::GenericArgKind::Type(ty) => ty.is_ty_var(),
341            ty::GenericArgKind::Const(ct) => ct.is_ct_var(),
342        }
343    }
344}
345
346#[rust_analyzer::prefer_underscore_import]
347pub trait Term<I: Interner<Term = Self>>:
348    Copy + Debug + Hash + Eq + IntoKind<Kind = ty::TermKind<I>> + TypeFoldable<I> + Relate<I>
349{
350    fn as_type(&self) -> Option<I::Ty> {
351        if let ty::TermKind::Ty(ty) = self.kind() { Some(ty) } else { None }
352    }
353
354    fn expect_ty(&self) -> I::Ty {
355        self.as_type().expect("expected a type, but found a const")
356    }
357
358    fn as_const(&self) -> Option<I::Const> {
359        if let ty::TermKind::Const(c) = self.kind() { Some(c) } else { None }
360    }
361
362    fn expect_const(&self) -> I::Const {
363        self.as_const().expect("expected a const, but found a type")
364    }
365
366    fn is_infer(self) -> bool {
367        match self.kind() {
368            ty::TermKind::Ty(ty) => ty.is_ty_var(),
369            ty::TermKind::Const(ct) => ct.is_ct_var(),
370        }
371    }
372
373    fn is_error(self) -> bool {
374        match self.kind() {
375            ty::TermKind::Ty(ty) => ty.is_ty_error(),
376            ty::TermKind::Const(ct) => ct.is_ct_error(),
377        }
378    }
379
380    fn to_alias_term(self) -> Option<ty::AliasTerm<I>> {
381        match self.kind() {
382            ty::TermKind::Ty(ty) => match ty.kind() {
383                ty::Alias(_, alias_ty) => Some(alias_ty.into()),
384                _ => None,
385            },
386            ty::TermKind::Const(ct) => match ct.kind() {
387                ty::ConstKind::Alias(_, alias_const) => Some(alias_const.into()),
388                _ => None,
389            },
390        }
391    }
392
393    fn is_non_rigid_alias(self) -> bool {
394        match self.kind() {
395            ty::TermKind::Ty(ty) => match ty.kind() {
396                ty::Alias(is_rigid, _) => is_rigid == ty::IsRigid::No,
397                _ => false,
398            },
399            ty::TermKind::Const(ct) => match ct.kind() {
400                ty::ConstKind::Alias(is_rigid, _) => is_rigid == ty::IsRigid::No,
401                _ => false,
402            },
403        }
404    }
405}
406
407#[rust_analyzer::prefer_underscore_import]
408pub trait GenericArgs<I: Interner<GenericArgs = Self>>:
409    Copy + Debug + Hash + Eq + SliceLike<Item = I::GenericArg> + Default + Relate<I>
410{
411    fn rebase_onto(
412        self,
413        interner: I,
414        source_def_id: I::DefId,
415        target: I::GenericArgs,
416    ) -> I::GenericArgs;
417
418    fn type_at(self, i: usize) -> I::Ty;
419
420    fn region_at(self, i: usize) -> Region<I>;
421
422    fn const_at(self, i: usize) -> I::Const;
423
424    fn identity_for_item(interner: I, def_id: I::DefId) -> I::GenericArgs;
425
426    fn extend_with_error(
427        interner: I,
428        def_id: I::DefId,
429        original_args: &[I::GenericArg],
430    ) -> I::GenericArgs;
431
432    fn split_closure_args(self) -> ty::ClosureArgsParts<I>;
433    fn split_coroutine_closure_args(self) -> ty::CoroutineClosureArgsParts<I>;
434    fn split_coroutine_args(self) -> ty::CoroutineArgsParts<I>;
435
436    fn as_closure(self) -> ty::ClosureArgs<I> {
437        ty::ClosureArgs { args: self }
438    }
439    fn as_coroutine_closure(self) -> ty::CoroutineClosureArgs<I> {
440        ty::CoroutineClosureArgs { args: self }
441    }
442    fn as_coroutine(self) -> ty::CoroutineArgs<I> {
443        ty::CoroutineArgs { args: self }
444    }
445}
446
447#[rust_analyzer::prefer_underscore_import]
448pub trait Predicate<I: Interner<Predicate = Self>>:
449    Copy
450    + Debug
451    + Hash
452    + Eq
453    + TypeSuperVisitable<I>
454    + TypeSuperFoldable<I>
455    + Flags
456    + UpcastFrom<I, ty::PredicateKind<I>>
457    + UpcastFrom<I, ty::Binder<I, ty::PredicateKind<I>>>
458    + UpcastFrom<I, ty::ClauseKind<I>>
459    + UpcastFrom<I, ty::Binder<I, ty::ClauseKind<I>>>
460    + UpcastFrom<I, I::Clause>
461    + UpcastFrom<I, ty::NormalizesTo<I>>
462    + UpcastFrom<I, ty::TraitRef<I>>
463    + UpcastFrom<I, ty::Binder<I, ty::TraitRef<I>>>
464    + UpcastFrom<I, ty::TraitPredicate<I>>
465    + UpcastFrom<I, ty::ProjectionPredicate<I>>
466    + UpcastFrom<I, ty::OutlivesPredicate<I, I::Ty>>
467    + UpcastFrom<I, ty::OutlivesPredicate<I, Region<I>>>
468    + IntoKind<Kind = ty::Binder<I, ty::PredicateKind<I>>>
469    + Elaboratable<I>
470{
471    fn as_clause(self) -> Option<I::Clause>;
472
473    fn allow_normalization(self) -> bool {
474        match self.kind().skip_binder() {
475            PredicateKind::Clause(ClauseKind::WellFormed(_)) => false,
476            PredicateKind::Clause(ClauseKind::Trait(_))
477            | PredicateKind::Clause(ClauseKind::HostEffect(..))
478            | PredicateKind::Clause(ClauseKind::RegionOutlives(_))
479            | PredicateKind::Clause(ClauseKind::TypeOutlives(_))
480            | PredicateKind::Clause(ClauseKind::Projection(_))
481            | PredicateKind::Clause(ClauseKind::ConstArgHasType(..))
482            | PredicateKind::Clause(ClauseKind::UnstableFeature(_))
483            | PredicateKind::DynCompatible(_)
484            | PredicateKind::Subtype(_)
485            | PredicateKind::Coerce(_)
486            | PredicateKind::Clause(ClauseKind::ConstEvaluatable(_))
487            | PredicateKind::ConstEquate(_, _)
488            | PredicateKind::NormalizesTo(..)
489            | PredicateKind::Ambiguous => true,
490        }
491    }
492}
493
494#[rust_analyzer::prefer_underscore_import]
495pub trait Clause<I: Interner<Clause = Self>>:
496    Copy
497    + Debug
498    + Hash
499    + Eq
500    + TypeFoldable<I>
501    + Flags
502    + UpcastFrom<I, ty::Binder<I, ty::ClauseKind<I>>>
503    + UpcastFrom<I, ty::TraitRef<I>>
504    + UpcastFrom<I, ty::Binder<I, ty::TraitRef<I>>>
505    + UpcastFrom<I, ty::TraitPredicate<I>>
506    + UpcastFrom<I, ty::Binder<I, ty::TraitPredicate<I>>>
507    + UpcastFrom<I, ty::ProjectionPredicate<I>>
508    + UpcastFrom<I, ty::Binder<I, ty::ProjectionPredicate<I>>>
509    + IntoKind<Kind = ty::Binder<I, ty::ClauseKind<I>>>
510    + Elaboratable<I>
511{
512    fn as_predicate(self) -> I::Predicate;
513
514    fn as_type_outlives_clause(self) -> Option<ty::Binder<I, ty::OutlivesPredicate<I, I::Ty>>> {
515        self.kind()
516            .map_bound(|clause| {
517                if let ty::ClauseKind::TypeOutlives(outlives) = clause {
518                    Some(outlives)
519                } else {
520                    None
521                }
522            })
523            .transpose()
524    }
525
526    fn as_trait_clause(self) -> Option<ty::Binder<I, ty::TraitPredicate<I>>> {
527        self.kind()
528            .map_bound(|clause| if let ty::ClauseKind::Trait(t) = clause { Some(t) } else { None })
529            .transpose()
530    }
531
532    fn as_host_effect_clause(self) -> Option<ty::Binder<I, ty::HostEffectPredicate<I>>> {
533        self.kind()
534            .map_bound(
535                |clause| if let ty::ClauseKind::HostEffect(t) = clause { Some(t) } else { None },
536            )
537            .transpose()
538    }
539
540    fn as_projection_clause(self) -> Option<ty::Binder<I, ty::ProjectionPredicate<I>>> {
541        self.kind()
542            .map_bound(
543                |clause| {
544                    if let ty::ClauseKind::Projection(p) = clause { Some(p) } else { None }
545                },
546            )
547            .transpose()
548    }
549
550    /// Performs a instantiation suitable for going from a
551    /// poly-trait-ref to supertraits that must hold if that
552    /// poly-trait-ref holds. This is slightly different from a normal
553    /// instantiation in terms of what happens with bound regions.
554    fn instantiate_supertrait(self, cx: I, trait_ref: ty::Binder<I, ty::TraitRef<I>>) -> Self;
555}
556
557#[rust_analyzer::prefer_underscore_import]
558pub trait Clauses<I: Interner<Clauses = Self>>:
559    Copy
560    + Debug
561    + Hash
562    + Eq
563    + TypeSuperVisitable<I>
564    + TypeSuperFoldable<I>
565    + Flags
566    + SliceLike<Item = I::Clause>
567{
568}
569
570#[rust_analyzer::prefer_underscore_import]
571pub trait IntoKind {
572    type Kind;
573
574    fn kind(self) -> Self::Kind;
575}
576
577#[rust_analyzer::prefer_underscore_import]
578pub trait ParamLike: Copy + Debug + Hash + Eq {
579    fn index(self) -> u32;
580}
581
582#[rust_analyzer::prefer_underscore_import]
583pub trait AdtDef<I: Interner>: Copy + Debug + Hash + Eq {
584    fn def_id(self) -> I::AdtId;
585
586    fn is_struct(self) -> bool;
587
588    fn is_packed(self) -> bool;
589
590    /// Returns the type of the struct tail.
591    ///
592    /// Expects the `AdtDef` to be a struct. If it is not, then this will panic.
593    fn struct_tail_ty(self, interner: I) -> Option<ty::EarlyBinder<I, I::Ty>>;
594
595    fn is_phantom_data(self) -> bool;
596
597    fn is_manually_drop(self) -> bool;
598
599    fn field_representing_type_info(
600        self,
601        interner: I,
602        args: I::GenericArgs,
603    ) -> Option<FieldInfo<I>>;
604
605    // FIXME: perhaps use `all_fields` and expose `FieldDef`.
606    fn all_field_tys(self, interner: I) -> ty::EarlyBinder<I, impl IntoIterator<Item = I::Ty>>;
607
608    fn sizedness_constraint(
609        self,
610        interner: I,
611        sizedness: SizedTraitKind,
612    ) -> Option<ty::EarlyBinder<I, I::Ty>>;
613
614    fn is_fundamental(self) -> bool;
615
616    fn destructor(self, interner: I) -> Option<AdtDestructorKind>;
617}
618
619#[rust_analyzer::prefer_underscore_import]
620pub trait ParamEnv<I: Interner>: Copy + Debug + Hash + Eq + TypeFoldable<I> {
621    fn caller_bounds(self) -> impl SliceLike<Item = I::Clause>;
622}
623
624#[rust_analyzer::prefer_underscore_import]
625pub trait Features<I: Interner>: Copy {
626    fn generic_const_exprs(self) -> bool;
627
628    fn generic_const_args(self) -> bool;
629
630    fn coroutine_clone(self) -> bool;
631
632    fn feature_bound_holds_in_crate(self, symbol: I::Symbol) -> bool;
633}
634
635#[rust_analyzer::prefer_underscore_import]
636pub trait DefId<I: Interner, Local = <I as Interner>::LocalDefId>:
637    Copy + Debug + Hash + Eq + TypeFoldable<I>
638{
639    fn is_local(self) -> bool;
640
641    fn as_local(self) -> Option<Local>;
642}
643
644pub trait SpecificDefId<I: Interner, Local = <I as Interner>::LocalDefId>:
645    DefId<I, Local> + Into<I::DefId> + TryFrom<I::DefId, Error: std::fmt::Debug>
646{
647}
648
649impl<
650    I: Interner,
651    T: DefId<I, Local> + Into<I::DefId> + TryFrom<I::DefId, Error: std::fmt::Debug>,
652    Local,
653> SpecificDefId<I, Local> for T
654{
655}
656
657#[rust_analyzer::prefer_underscore_import]
658pub trait BoundExistentialPredicates<I: Interner>:
659    Copy + Debug + Hash + Eq + Relate<I> + SliceLike<Item = ty::Binder<I, ty::ExistentialPredicate<I>>>
660{
661    fn principal_def_id(self) -> Option<I::TraitId>;
662
663    fn principal(self) -> Option<ty::Binder<I, ty::ExistentialTraitRef<I>>>;
664
665    fn auto_traits(self) -> impl IntoIterator<Item = I::TraitId>;
666
667    fn projection_bounds(
668        self,
669    ) -> impl IntoIterator<Item = ty::Binder<I, ty::ExistentialProjection<I>>>;
670}
671
672#[rust_analyzer::prefer_underscore_import]
673pub trait Span<I: Interner>: Copy + Debug + Hash + Eq + TypeFoldable<I> {
674    fn dummy() -> Self;
675}
676
677#[rust_analyzer::prefer_underscore_import]
678pub trait OpaqueTypeStorageEntries: Debug + Copy + Default {
679    /// Whether the number of opaques has changed in a way that necessitates
680    /// reevaluating a goal. For now, this is only when the number of non-duplicated
681    /// entries changed.
682    fn needs_reevaluation(self, canonicalized: usize) -> bool;
683}
684
685pub trait BoundVarKinds<I: Interner>:
686    Copy + Debug + Hash + Eq + SliceLike<Item = ty::BoundVariableKind<I>> + Default
687{
688    fn from_vars(cx: I, iter: impl IntoIterator<Item = ty::BoundVariableKind<I>>) -> Self;
689}
690
691pub trait SliceLike: Sized + Copy {
692    type Item: Copy;
693    type IntoIter: Iterator<Item = Self::Item> + DoubleEndedIterator;
694
695    fn iter(self) -> Self::IntoIter;
696
697    fn as_slice(&self) -> &[Self::Item];
698
699    fn get(self, idx: usize) -> Option<Self::Item> {
700        self.as_slice().get(idx).copied()
701    }
702
703    fn len(self) -> usize {
704        self.as_slice().len()
705    }
706
707    fn is_empty(self) -> bool {
708        self.len() == 0
709    }
710
711    fn contains(self, t: &Self::Item) -> bool
712    where
713        Self::Item: PartialEq,
714    {
715        self.as_slice().contains(t)
716    }
717
718    fn to_vec(self) -> Vec<Self::Item> {
719        self.as_slice().to_vec()
720    }
721
722    fn last(self) -> Option<Self::Item> {
723        self.as_slice().last().copied()
724    }
725
726    fn split_last(&self) -> Option<(&Self::Item, &[Self::Item])> {
727        self.as_slice().split_last()
728    }
729}
730
731impl<'a, T: Copy> SliceLike for &'a [T] {
732    type Item = T;
733    type IntoIter = std::iter::Copied<std::slice::Iter<'a, T>>;
734
735    fn iter(self) -> Self::IntoIter {
736        self.iter().copied()
737    }
738
739    fn as_slice(&self) -> &[Self::Item] {
740        *self
741    }
742}
743
744impl<'a, T: Copy, const N: usize> SliceLike for &'a [T; N] {
745    type Item = T;
746    type IntoIter = std::iter::Copied<std::slice::Iter<'a, T>>;
747
748    fn iter(self) -> Self::IntoIter {
749        self.into_iter().copied()
750    }
751
752    fn as_slice(&self) -> &[Self::Item] {
753        *self
754    }
755}
756
757impl<'a, S: SliceLike> SliceLike for &'a S {
758    type Item = S::Item;
759    type IntoIter = S::IntoIter;
760
761    fn iter(self) -> Self::IntoIter {
762        (*self).iter()
763    }
764
765    fn as_slice(&self) -> &[Self::Item] {
766        (*self).as_slice()
767    }
768}
769
770#[rust_analyzer::prefer_underscore_import]
771pub trait Symbol<I>: Copy + Hash + PartialEq + Eq + Debug {
772    fn is_kw_underscore_lifetime(self) -> bool;
773}