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;
15use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable};
16use crate::{self as ty, CollectAndApply, Interner, UpcastFrom};
17
18pub trait Ty<I: Interner<Ty = Self>>:
19    Copy
20    + Debug
21    + Hash
22    + Eq
23    + Into<I::GenericArg>
24    + Into<I::Term>
25    + IntoKind<Kind = ty::TyKind<I>>
26    + TypeSuperVisitable<I>
27    + TypeSuperFoldable<I>
28    + Relate<I>
29    + Flags
30{
31    fn new_unit(interner: I) -> Self;
32
33    fn new_bool(interner: I) -> Self;
34
35    fn new_u8(interner: I) -> Self;
36
37    fn new_usize(interner: I) -> Self;
38
39    fn new_infer(interner: I, var: ty::InferTy) -> Self;
40
41    fn new_var(interner: I, var: ty::TyVid) -> Self;
42
43    fn new_param(interner: I, param: I::ParamTy) -> Self;
44
45    fn new_placeholder(interner: I, param: I::PlaceholderTy) -> Self;
46
47    fn new_bound(interner: I, debruijn: ty::DebruijnIndex, var: I::BoundTy) -> Self;
48
49    fn new_anon_bound(interner: I, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self;
50
51    fn new_alias(interner: I, kind: ty::AliasTyKind, alias_ty: ty::AliasTy<I>) -> Self;
52
53    fn new_projection_from_args(interner: I, def_id: I::DefId, args: I::GenericArgs) -> Self {
54        Ty::new_alias(
55            interner,
56            ty::AliasTyKind::Projection,
57            ty::AliasTy::new_from_args(interner, def_id, args),
58        )
59    }
60
61    fn new_projection(
62        interner: I,
63        def_id: I::DefId,
64        args: impl IntoIterator<Item: Into<I::GenericArg>>,
65    ) -> Self {
66        Ty::new_alias(
67            interner,
68            ty::AliasTyKind::Projection,
69            ty::AliasTy::new(interner, def_id, args),
70        )
71    }
72
73    fn new_error(interner: I, guar: I::ErrorGuaranteed) -> Self;
74
75    fn new_adt(interner: I, adt_def: I::AdtDef, args: I::GenericArgs) -> Self;
76
77    fn new_foreign(interner: I, def_id: I::DefId) -> Self;
78
79    fn new_dynamic(
80        interner: I,
81        preds: I::BoundExistentialPredicates,
82        region: I::Region,
83        kind: ty::DynKind,
84    ) -> Self;
85
86    fn new_coroutine(interner: I, def_id: I::DefId, args: I::GenericArgs) -> Self;
87
88    fn new_coroutine_closure(interner: I, def_id: I::DefId, args: I::GenericArgs) -> Self;
89
90    fn new_closure(interner: I, def_id: I::DefId, args: I::GenericArgs) -> Self;
91
92    fn new_coroutine_witness(interner: I, def_id: I::DefId, args: I::GenericArgs) -> Self;
93
94    fn new_ptr(interner: I, ty: Self, mutbl: Mutability) -> Self;
95
96    fn new_ref(interner: I, region: I::Region, ty: Self, mutbl: Mutability) -> Self;
97
98    fn new_array_with_const_len(interner: I, ty: Self, len: I::Const) -> Self;
99
100    fn new_slice(interner: I, ty: Self) -> Self;
101
102    fn new_tup(interner: I, tys: &[I::Ty]) -> Self;
103
104    fn new_tup_from_iter<It, T>(interner: I, iter: It) -> T::Output
105    where
106        It: Iterator<Item = T>,
107        T: CollectAndApply<Self, Self>;
108
109    fn new_fn_def(interner: I, def_id: I::DefId, args: I::GenericArgs) -> Self;
110
111    fn new_fn_ptr(interner: I, sig: ty::Binder<I, ty::FnSig<I>>) -> Self;
112
113    fn new_pat(interner: I, ty: Self, pat: I::Pat) -> Self;
114
115    fn new_unsafe_binder(interner: I, ty: ty::Binder<I, I::Ty>) -> Self;
116
117    fn tuple_fields(self) -> I::Tys;
118
119    fn to_opt_closure_kind(self) -> Option<ty::ClosureKind>;
120
121    fn from_closure_kind(interner: I, kind: ty::ClosureKind) -> Self;
122
123    fn from_coroutine_closure_kind(interner: I, kind: ty::ClosureKind) -> Self;
124
125    fn is_ty_var(self) -> bool {
126        matches!(self.kind(), ty::Infer(ty::TyVar(_)))
127    }
128
129    fn is_ty_error(self) -> bool {
130        matches!(self.kind(), ty::Error(_))
131    }
132
133    fn is_floating_point(self) -> bool {
134        matches!(self.kind(), ty::Float(_) | ty::Infer(ty::FloatVar(_)))
135    }
136
137    fn is_integral(self) -> bool {
138        matches!(self.kind(), ty::Infer(ty::IntVar(_)) | ty::Int(_) | ty::Uint(_))
139    }
140
141    fn is_fn_ptr(self) -> bool {
142        matches!(self.kind(), ty::FnPtr(..))
143    }
144
145    /// Checks whether this type is an ADT that has unsafe fields.
146    fn has_unsafe_fields(self) -> bool;
147
148    fn fn_sig(self, interner: I) -> ty::Binder<I, ty::FnSig<I>> {
149        self.kind().fn_sig(interner)
150    }
151
152    fn discriminant_ty(self, interner: I) -> I::Ty;
153
154    fn is_known_rigid(self) -> bool {
155        self.kind().is_known_rigid()
156    }
157
158    fn is_guaranteed_unsized_raw(self) -> bool {
159        match self.kind() {
160            ty::Dynamic(_, _, ty::Dyn) | ty::Slice(_) | ty::Str => true,
161            ty::Bool
162            | ty::Char
163            | ty::Int(_)
164            | ty::Uint(_)
165            | ty::Float(_)
166            | ty::Adt(_, _)
167            | ty::Foreign(_)
168            | ty::Array(_, _)
169            | ty::Pat(_, _)
170            | ty::RawPtr(_, _)
171            | ty::Ref(_, _, _)
172            | ty::FnDef(_, _)
173            | ty::FnPtr(_, _)
174            | ty::UnsafeBinder(_)
175            | ty::Closure(_, _)
176            | ty::CoroutineClosure(_, _)
177            | ty::Coroutine(_, _)
178            | ty::CoroutineWitness(_, _)
179            | ty::Never
180            | ty::Tuple(_)
181            | ty::Alias(_, _)
182            | ty::Param(_)
183            | ty::Bound(_, _)
184            | ty::Placeholder(_)
185            | ty::Infer(_)
186            | ty::Error(_)
187            | ty::Dynamic(_, _, ty::DynStar) => false,
188        }
189    }
190}
191
192pub trait Tys<I: Interner<Tys = Self>>:
193    Copy + Debug + Hash + Eq + SliceLike<Item = I::Ty> + TypeFoldable<I> + Default
194{
195    fn inputs(self) -> I::FnInputTys;
196
197    fn output(self) -> I::Ty;
198}
199
200pub trait Abi<I: Interner<Abi = Self>>: Copy + Debug + Hash + Eq {
201    fn rust() -> Self;
202
203    /// Whether this ABI is `extern "Rust"`.
204    fn is_rust(self) -> bool;
205}
206
207pub trait Safety<I: Interner<Safety = Self>>: Copy + Debug + Hash + Eq {
208    fn safe() -> Self;
209
210    fn is_safe(self) -> bool;
211
212    fn prefix_str(self) -> &'static str;
213}
214
215pub trait Region<I: Interner<Region = Self>>:
216    Copy
217    + Debug
218    + Hash
219    + Eq
220    + Into<I::GenericArg>
221    + IntoKind<Kind = ty::RegionKind<I>>
222    + Flags
223    + Relate<I>
224{
225    fn new_bound(interner: I, debruijn: ty::DebruijnIndex, var: I::BoundRegion) -> Self;
226
227    fn new_anon_bound(interner: I, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self;
228
229    fn new_static(interner: I) -> Self;
230
231    fn is_bound(self) -> bool {
232        matches!(self.kind(), ty::ReBound(..))
233    }
234}
235
236pub trait Const<I: Interner<Const = Self>>:
237    Copy
238    + Debug
239    + Hash
240    + Eq
241    + Into<I::GenericArg>
242    + Into<I::Term>
243    + IntoKind<Kind = ty::ConstKind<I>>
244    + TypeSuperVisitable<I>
245    + TypeSuperFoldable<I>
246    + Relate<I>
247    + Flags
248{
249    fn new_infer(interner: I, var: ty::InferConst) -> Self;
250
251    fn new_var(interner: I, var: ty::ConstVid) -> Self;
252
253    fn new_bound(interner: I, debruijn: ty::DebruijnIndex, var: I::BoundConst) -> Self;
254
255    fn new_anon_bound(interner: I, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self;
256
257    fn new_unevaluated(interner: I, uv: ty::UnevaluatedConst<I>) -> Self;
258
259    fn new_expr(interner: I, expr: I::ExprConst) -> Self;
260
261    fn new_error(interner: I, guar: I::ErrorGuaranteed) -> Self;
262
263    fn new_error_with_message(interner: I, msg: impl ToString) -> Self {
264        Self::new_error(interner, interner.delay_bug(msg))
265    }
266
267    fn is_ct_var(self) -> bool {
268        matches!(self.kind(), ty::ConstKind::Infer(ty::InferConst::Var(_)))
269    }
270
271    fn is_ct_error(self) -> bool {
272        matches!(self.kind(), ty::ConstKind::Error(_))
273    }
274}
275
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
281pub trait ExprConst<I: Interner<ExprConst = Self>>: Copy + Debug + Hash + Eq + Relate<I> {
282    fn args(self) -> I::GenericArgs;
283}
284
285pub trait GenericsOf<I: Interner<GenericsOf = Self>> {
286    fn count(&self) -> usize;
287}
288
289pub trait GenericArg<I: Interner<GenericArg = Self>>:
290    Copy
291    + Debug
292    + Hash
293    + Eq
294    + IntoKind<Kind = ty::GenericArgKind<I>>
295    + TypeVisitable<I>
296    + Relate<I>
297    + From<I::Ty>
298    + From<I::Region>
299    + From<I::Const>
300{
301    fn as_type(&self) -> Option<I::Ty> {
302        if let ty::GenericArgKind::Type(ty) = self.kind() { Some(ty) } else { None }
303    }
304
305    fn expect_ty(&self) -> I::Ty {
306        self.as_type().expect("expected a type")
307    }
308
309    fn as_const(&self) -> Option<I::Const> {
310        if let ty::GenericArgKind::Const(c) = self.kind() { Some(c) } else { None }
311    }
312
313    fn expect_const(&self) -> I::Const {
314        self.as_const().expect("expected a const")
315    }
316
317    fn as_region(&self) -> Option<I::Region> {
318        if let ty::GenericArgKind::Lifetime(c) = self.kind() { Some(c) } else { None }
319    }
320
321    fn expect_region(&self) -> I::Region {
322        self.as_region().expect("expected a const")
323    }
324
325    fn is_non_region_infer(self) -> bool {
326        match self.kind() {
327            ty::GenericArgKind::Lifetime(_) => false,
328            ty::GenericArgKind::Type(ty) => ty.is_ty_var(),
329            ty::GenericArgKind::Const(ct) => ct.is_ct_var(),
330        }
331    }
332}
333
334pub trait Term<I: Interner<Term = Self>>:
335    Copy + Debug + Hash + Eq + IntoKind<Kind = ty::TermKind<I>> + TypeFoldable<I> + Relate<I>
336{
337    fn as_type(&self) -> Option<I::Ty> {
338        if let ty::TermKind::Ty(ty) = self.kind() { Some(ty) } else { None }
339    }
340
341    fn expect_ty(&self) -> I::Ty {
342        self.as_type().expect("expected a type, but found a const")
343    }
344
345    fn as_const(&self) -> Option<I::Const> {
346        if let ty::TermKind::Const(c) = self.kind() { Some(c) } else { None }
347    }
348
349    fn expect_const(&self) -> I::Const {
350        self.as_const().expect("expected a const, but found a type")
351    }
352
353    fn is_infer(self) -> bool {
354        match self.kind() {
355            ty::TermKind::Ty(ty) => ty.is_ty_var(),
356            ty::TermKind::Const(ct) => ct.is_ct_var(),
357        }
358    }
359
360    fn is_error(self) -> bool {
361        match self.kind() {
362            ty::TermKind::Ty(ty) => ty.is_ty_error(),
363            ty::TermKind::Const(ct) => ct.is_ct_error(),
364        }
365    }
366
367    fn to_alias_term(self) -> Option<ty::AliasTerm<I>> {
368        match self.kind() {
369            ty::TermKind::Ty(ty) => match ty.kind() {
370                ty::Alias(_kind, alias_ty) => Some(alias_ty.into()),
371                _ => None,
372            },
373            ty::TermKind::Const(ct) => match ct.kind() {
374                ty::ConstKind::Unevaluated(uv) => Some(uv.into()),
375                _ => None,
376            },
377        }
378    }
379}
380
381pub trait GenericArgs<I: Interner<GenericArgs = Self>>:
382    Copy + Debug + Hash + Eq + SliceLike<Item = I::GenericArg> + Default + Relate<I>
383{
384    fn rebase_onto(
385        self,
386        interner: I,
387        source_def_id: I::DefId,
388        target: I::GenericArgs,
389    ) -> I::GenericArgs;
390
391    fn type_at(self, i: usize) -> I::Ty;
392
393    fn region_at(self, i: usize) -> I::Region;
394
395    fn const_at(self, i: usize) -> I::Const;
396
397    fn identity_for_item(interner: I, def_id: I::DefId) -> I::GenericArgs;
398
399    fn extend_with_error(
400        interner: I,
401        def_id: I::DefId,
402        original_args: &[I::GenericArg],
403    ) -> I::GenericArgs;
404
405    fn split_closure_args(self) -> ty::ClosureArgsParts<I>;
406    fn split_coroutine_closure_args(self) -> ty::CoroutineClosureArgsParts<I>;
407    fn split_coroutine_args(self) -> ty::CoroutineArgsParts<I>;
408
409    fn as_closure(self) -> ty::ClosureArgs<I> {
410        ty::ClosureArgs { args: self }
411    }
412    fn as_coroutine_closure(self) -> ty::CoroutineClosureArgs<I> {
413        ty::CoroutineClosureArgs { args: self }
414    }
415    fn as_coroutine(self) -> ty::CoroutineArgs<I> {
416        ty::CoroutineArgs { args: self }
417    }
418}
419
420pub trait Predicate<I: Interner<Predicate = Self>>:
421    Copy
422    + Debug
423    + Hash
424    + Eq
425    + TypeSuperVisitable<I>
426    + TypeSuperFoldable<I>
427    + Flags
428    + UpcastFrom<I, ty::PredicateKind<I>>
429    + UpcastFrom<I, ty::Binder<I, ty::PredicateKind<I>>>
430    + UpcastFrom<I, ty::ClauseKind<I>>
431    + UpcastFrom<I, ty::Binder<I, ty::ClauseKind<I>>>
432    + UpcastFrom<I, I::Clause>
433    + UpcastFrom<I, ty::NormalizesTo<I>>
434    + UpcastFrom<I, ty::TraitRef<I>>
435    + UpcastFrom<I, ty::Binder<I, ty::TraitRef<I>>>
436    + UpcastFrom<I, ty::TraitPredicate<I>>
437    + UpcastFrom<I, ty::OutlivesPredicate<I, I::Ty>>
438    + UpcastFrom<I, ty::OutlivesPredicate<I, I::Region>>
439    + IntoKind<Kind = ty::Binder<I, ty::PredicateKind<I>>>
440    + Elaboratable<I>
441{
442    fn as_clause(self) -> Option<I::Clause>;
443
444    fn as_normalizes_to(self) -> Option<ty::Binder<I, ty::NormalizesTo<I>>> {
445        let kind = self.kind();
446        match kind.skip_binder() {
447            ty::PredicateKind::NormalizesTo(pred) => Some(kind.rebind(pred)),
448            _ => None,
449        }
450    }
451
452    // FIXME: Eventually uplift the impl out of rustc and make this defaulted.
453    fn allow_normalization(self) -> bool;
454}
455
456pub trait Clause<I: Interner<Clause = Self>>:
457    Copy
458    + Debug
459    + Hash
460    + Eq
461    + TypeFoldable<I>
462    + UpcastFrom<I, ty::Binder<I, ty::ClauseKind<I>>>
463    + UpcastFrom<I, ty::TraitRef<I>>
464    + UpcastFrom<I, ty::Binder<I, ty::TraitRef<I>>>
465    + UpcastFrom<I, ty::TraitPredicate<I>>
466    + UpcastFrom<I, ty::Binder<I, ty::TraitPredicate<I>>>
467    + UpcastFrom<I, ty::ProjectionPredicate<I>>
468    + UpcastFrom<I, ty::Binder<I, ty::ProjectionPredicate<I>>>
469    + IntoKind<Kind = ty::Binder<I, ty::ClauseKind<I>>>
470    + Elaboratable<I>
471{
472    fn as_predicate(self) -> I::Predicate;
473
474    fn as_trait_clause(self) -> Option<ty::Binder<I, ty::TraitPredicate<I>>> {
475        self.kind()
476            .map_bound(|clause| if let ty::ClauseKind::Trait(t) = clause { Some(t) } else { None })
477            .transpose()
478    }
479
480    fn as_host_effect_clause(self) -> Option<ty::Binder<I, ty::HostEffectPredicate<I>>> {
481        self.kind()
482            .map_bound(
483                |clause| if let ty::ClauseKind::HostEffect(t) = clause { Some(t) } else { None },
484            )
485            .transpose()
486    }
487
488    fn as_projection_clause(self) -> Option<ty::Binder<I, ty::ProjectionPredicate<I>>> {
489        self.kind()
490            .map_bound(
491                |clause| {
492                    if let ty::ClauseKind::Projection(p) = clause { Some(p) } else { None }
493                },
494            )
495            .transpose()
496    }
497
498    /// Performs a instantiation suitable for going from a
499    /// poly-trait-ref to supertraits that must hold if that
500    /// poly-trait-ref holds. This is slightly different from a normal
501    /// instantiation in terms of what happens with bound regions.
502    fn instantiate_supertrait(self, cx: I, trait_ref: ty::Binder<I, ty::TraitRef<I>>) -> Self;
503}
504
505/// Common capabilities of placeholder kinds
506pub trait PlaceholderLike: Copy + Debug + Hash + Eq {
507    fn universe(self) -> ty::UniverseIndex;
508    fn var(self) -> ty::BoundVar;
509
510    fn with_updated_universe(self, ui: ty::UniverseIndex) -> Self;
511
512    fn new(ui: ty::UniverseIndex, var: ty::BoundVar) -> Self;
513}
514
515pub trait IntoKind {
516    type Kind;
517
518    fn kind(self) -> Self::Kind;
519}
520
521pub trait BoundVarLike<I: Interner> {
522    fn var(self) -> ty::BoundVar;
523
524    fn assert_eq(self, var: I::BoundVarKind);
525}
526
527pub trait ParamLike {
528    fn index(self) -> u32;
529}
530
531pub trait AdtDef<I: Interner>: Copy + Debug + Hash + Eq {
532    fn def_id(self) -> I::DefId;
533
534    fn is_struct(self) -> bool;
535
536    /// Returns the type of the struct tail.
537    ///
538    /// Expects the `AdtDef` to be a struct. If it is not, then this will panic.
539    fn struct_tail_ty(self, interner: I) -> Option<ty::EarlyBinder<I, I::Ty>>;
540
541    fn is_phantom_data(self) -> bool;
542
543    fn is_manually_drop(self) -> bool;
544
545    // FIXME: perhaps use `all_fields` and expose `FieldDef`.
546    fn all_field_tys(self, interner: I) -> ty::EarlyBinder<I, impl IntoIterator<Item = I::Ty>>;
547
548    fn sized_constraint(self, interner: I) -> Option<ty::EarlyBinder<I, I::Ty>>;
549
550    fn is_fundamental(self) -> bool;
551
552    fn destructor(self, interner: I) -> Option<AdtDestructorKind>;
553}
554
555pub trait ParamEnv<I: Interner>: Copy + Debug + Hash + Eq + TypeFoldable<I> {
556    fn caller_bounds(self) -> impl SliceLike<Item = I::Clause>;
557}
558
559pub trait Features<I: Interner>: Copy {
560    fn generic_const_exprs(self) -> bool;
561
562    fn coroutine_clone(self) -> bool;
563
564    fn associated_const_equality(self) -> bool;
565}
566
567pub trait DefId<I: Interner>: Copy + Debug + Hash + Eq + TypeFoldable<I> {
568    fn is_local(self) -> bool;
569
570    fn as_local(self) -> Option<I::LocalDefId>;
571}
572
573pub trait BoundExistentialPredicates<I: Interner>:
574    Copy + Debug + Hash + Eq + Relate<I> + SliceLike<Item = ty::Binder<I, ty::ExistentialPredicate<I>>>
575{
576    fn principal_def_id(self) -> Option<I::DefId>;
577
578    fn principal(self) -> Option<ty::Binder<I, ty::ExistentialTraitRef<I>>>;
579
580    fn auto_traits(self) -> impl IntoIterator<Item = I::DefId>;
581
582    fn projection_bounds(
583        self,
584    ) -> impl IntoIterator<Item = ty::Binder<I, ty::ExistentialProjection<I>>>;
585}
586
587pub trait Span<I: Interner>: Copy + Debug + Hash + Eq + TypeFoldable<I> {
588    fn dummy() -> Self;
589}
590
591pub trait SliceLike: Sized + Copy {
592    type Item: Copy;
593    type IntoIter: Iterator<Item = Self::Item> + DoubleEndedIterator;
594
595    fn iter(self) -> Self::IntoIter;
596
597    fn as_slice(&self) -> &[Self::Item];
598
599    fn get(self, idx: usize) -> Option<Self::Item> {
600        self.as_slice().get(idx).copied()
601    }
602
603    fn len(self) -> usize {
604        self.as_slice().len()
605    }
606
607    fn is_empty(self) -> bool {
608        self.len() == 0
609    }
610
611    fn contains(self, t: &Self::Item) -> bool
612    where
613        Self::Item: PartialEq,
614    {
615        self.as_slice().contains(t)
616    }
617
618    fn to_vec(self) -> Vec<Self::Item> {
619        self.as_slice().to_vec()
620    }
621
622    fn last(self) -> Option<Self::Item> {
623        self.as_slice().last().copied()
624    }
625
626    fn split_last(&self) -> Option<(&Self::Item, &[Self::Item])> {
627        self.as_slice().split_last()
628    }
629}
630
631impl<'a, T: Copy> SliceLike for &'a [T] {
632    type Item = T;
633    type IntoIter = std::iter::Copied<std::slice::Iter<'a, T>>;
634
635    fn iter(self) -> Self::IntoIter {
636        self.iter().copied()
637    }
638
639    fn as_slice(&self) -> &[Self::Item] {
640        *self
641    }
642}
643
644impl<'a, T: Copy, const N: usize> SliceLike for &'a [T; N] {
645    type Item = T;
646    type IntoIter = std::iter::Copied<std::slice::Iter<'a, T>>;
647
648    fn iter(self) -> Self::IntoIter {
649        self.into_iter().copied()
650    }
651
652    fn as_slice(&self) -> &[Self::Item] {
653        *self
654    }
655}
656
657impl<'a, S: SliceLike> SliceLike for &'a S {
658    type Item = S::Item;
659    type IntoIter = S::IntoIter;
660
661    fn iter(self) -> Self::IntoIter {
662        (*self).iter()
663    }
664
665    fn as_slice(&self) -> &[Self::Item] {
666        (*self).as_slice()
667    }
668}