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