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