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_term(&self) -> Option<I::Term> {
302        match self.kind() {
303            ty::GenericArgKind::Lifetime(_) => None,
304            ty::GenericArgKind::Type(ty) => Some(ty.into()),
305            ty::GenericArgKind::Const(ct) => Some(ct.into()),
306        }
307    }
308
309    fn as_type(&self) -> Option<I::Ty> {
310        if let ty::GenericArgKind::Type(ty) = self.kind() { Some(ty) } else { None }
311    }
312
313    fn expect_ty(&self) -> I::Ty {
314        self.as_type().expect("expected a type")
315    }
316
317    fn as_const(&self) -> Option<I::Const> {
318        if let ty::GenericArgKind::Const(c) = self.kind() { Some(c) } else { None }
319    }
320
321    fn expect_const(&self) -> I::Const {
322        self.as_const().expect("expected a const")
323    }
324
325    fn as_region(&self) -> Option<I::Region> {
326        if let ty::GenericArgKind::Lifetime(c) = self.kind() { Some(c) } else { None }
327    }
328
329    fn expect_region(&self) -> I::Region {
330        self.as_region().expect("expected a const")
331    }
332
333    fn is_non_region_infer(self) -> bool {
334        match self.kind() {
335            ty::GenericArgKind::Lifetime(_) => false,
336            ty::GenericArgKind::Type(ty) => ty.is_ty_var(),
337            ty::GenericArgKind::Const(ct) => ct.is_ct_var(),
338        }
339    }
340}
341
342pub trait Term<I: Interner<Term = Self>>:
343    Copy + Debug + Hash + Eq + IntoKind<Kind = ty::TermKind<I>> + TypeFoldable<I> + Relate<I>
344{
345    fn as_type(&self) -> Option<I::Ty> {
346        if let ty::TermKind::Ty(ty) = self.kind() { Some(ty) } else { None }
347    }
348
349    fn expect_ty(&self) -> I::Ty {
350        self.as_type().expect("expected a type, but found a const")
351    }
352
353    fn as_const(&self) -> Option<I::Const> {
354        if let ty::TermKind::Const(c) = self.kind() { Some(c) } else { None }
355    }
356
357    fn expect_const(&self) -> I::Const {
358        self.as_const().expect("expected a const, but found a type")
359    }
360
361    fn is_infer(self) -> bool {
362        match self.kind() {
363            ty::TermKind::Ty(ty) => ty.is_ty_var(),
364            ty::TermKind::Const(ct) => ct.is_ct_var(),
365        }
366    }
367
368    fn is_error(self) -> bool {
369        match self.kind() {
370            ty::TermKind::Ty(ty) => ty.is_ty_error(),
371            ty::TermKind::Const(ct) => ct.is_ct_error(),
372        }
373    }
374
375    fn to_alias_term(self) -> Option<ty::AliasTerm<I>> {
376        match self.kind() {
377            ty::TermKind::Ty(ty) => match ty.kind() {
378                ty::Alias(_kind, alias_ty) => Some(alias_ty.into()),
379                _ => None,
380            },
381            ty::TermKind::Const(ct) => match ct.kind() {
382                ty::ConstKind::Unevaluated(uv) => Some(uv.into()),
383                _ => None,
384            },
385        }
386    }
387}
388
389pub trait GenericArgs<I: Interner<GenericArgs = Self>>:
390    Copy + Debug + Hash + Eq + SliceLike<Item = I::GenericArg> + Default + Relate<I>
391{
392    fn rebase_onto(
393        self,
394        interner: I,
395        source_def_id: I::DefId,
396        target: I::GenericArgs,
397    ) -> I::GenericArgs;
398
399    fn type_at(self, i: usize) -> I::Ty;
400
401    fn region_at(self, i: usize) -> I::Region;
402
403    fn const_at(self, i: usize) -> I::Const;
404
405    fn identity_for_item(interner: I, def_id: I::DefId) -> I::GenericArgs;
406
407    fn extend_with_error(
408        interner: I,
409        def_id: I::DefId,
410        original_args: &[I::GenericArg],
411    ) -> I::GenericArgs;
412
413    fn split_closure_args(self) -> ty::ClosureArgsParts<I>;
414    fn split_coroutine_closure_args(self) -> ty::CoroutineClosureArgsParts<I>;
415    fn split_coroutine_args(self) -> ty::CoroutineArgsParts<I>;
416
417    fn as_closure(self) -> ty::ClosureArgs<I> {
418        ty::ClosureArgs { args: self }
419    }
420    fn as_coroutine_closure(self) -> ty::CoroutineClosureArgs<I> {
421        ty::CoroutineClosureArgs { args: self }
422    }
423    fn as_coroutine(self) -> ty::CoroutineArgs<I> {
424        ty::CoroutineArgs { args: self }
425    }
426}
427
428pub trait Predicate<I: Interner<Predicate = Self>>:
429    Copy
430    + Debug
431    + Hash
432    + Eq
433    + TypeSuperVisitable<I>
434    + TypeSuperFoldable<I>
435    + Flags
436    + UpcastFrom<I, ty::PredicateKind<I>>
437    + UpcastFrom<I, ty::Binder<I, ty::PredicateKind<I>>>
438    + UpcastFrom<I, ty::ClauseKind<I>>
439    + UpcastFrom<I, ty::Binder<I, ty::ClauseKind<I>>>
440    + UpcastFrom<I, I::Clause>
441    + UpcastFrom<I, ty::NormalizesTo<I>>
442    + UpcastFrom<I, ty::TraitRef<I>>
443    + UpcastFrom<I, ty::Binder<I, ty::TraitRef<I>>>
444    + UpcastFrom<I, ty::TraitPredicate<I>>
445    + UpcastFrom<I, ty::OutlivesPredicate<I, I::Ty>>
446    + UpcastFrom<I, ty::OutlivesPredicate<I, I::Region>>
447    + IntoKind<Kind = ty::Binder<I, ty::PredicateKind<I>>>
448    + Elaboratable<I>
449{
450    fn as_clause(self) -> Option<I::Clause>;
451
452    fn as_normalizes_to(self) -> Option<ty::Binder<I, ty::NormalizesTo<I>>> {
453        let kind = self.kind();
454        match kind.skip_binder() {
455            ty::PredicateKind::NormalizesTo(pred) => Some(kind.rebind(pred)),
456            _ => None,
457        }
458    }
459
460    // FIXME: Eventually uplift the impl out of rustc and make this defaulted.
461    fn allow_normalization(self) -> bool;
462}
463
464pub trait Clause<I: Interner<Clause = Self>>:
465    Copy
466    + Debug
467    + Hash
468    + Eq
469    + TypeFoldable<I>
470    + UpcastFrom<I, ty::Binder<I, ty::ClauseKind<I>>>
471    + UpcastFrom<I, ty::TraitRef<I>>
472    + UpcastFrom<I, ty::Binder<I, ty::TraitRef<I>>>
473    + UpcastFrom<I, ty::TraitPredicate<I>>
474    + UpcastFrom<I, ty::Binder<I, ty::TraitPredicate<I>>>
475    + UpcastFrom<I, ty::ProjectionPredicate<I>>
476    + UpcastFrom<I, ty::Binder<I, ty::ProjectionPredicate<I>>>
477    + IntoKind<Kind = ty::Binder<I, ty::ClauseKind<I>>>
478    + Elaboratable<I>
479{
480    fn as_predicate(self) -> I::Predicate;
481
482    fn as_trait_clause(self) -> Option<ty::Binder<I, ty::TraitPredicate<I>>> {
483        self.kind()
484            .map_bound(|clause| if let ty::ClauseKind::Trait(t) = clause { Some(t) } else { None })
485            .transpose()
486    }
487
488    fn as_host_effect_clause(self) -> Option<ty::Binder<I, ty::HostEffectPredicate<I>>> {
489        self.kind()
490            .map_bound(
491                |clause| if let ty::ClauseKind::HostEffect(t) = clause { Some(t) } else { None },
492            )
493            .transpose()
494    }
495
496    fn as_projection_clause(self) -> Option<ty::Binder<I, ty::ProjectionPredicate<I>>> {
497        self.kind()
498            .map_bound(
499                |clause| {
500                    if let ty::ClauseKind::Projection(p) = clause { Some(p) } else { None }
501                },
502            )
503            .transpose()
504    }
505
506    /// Performs a instantiation suitable for going from a
507    /// poly-trait-ref to supertraits that must hold if that
508    /// poly-trait-ref holds. This is slightly different from a normal
509    /// instantiation in terms of what happens with bound regions.
510    fn instantiate_supertrait(self, cx: I, trait_ref: ty::Binder<I, ty::TraitRef<I>>) -> Self;
511}
512
513/// Common capabilities of placeholder kinds
514pub trait PlaceholderLike: Copy + Debug + Hash + Eq {
515    fn universe(self) -> ty::UniverseIndex;
516    fn var(self) -> ty::BoundVar;
517
518    fn with_updated_universe(self, ui: ty::UniverseIndex) -> Self;
519
520    fn new(ui: ty::UniverseIndex, var: ty::BoundVar) -> Self;
521}
522
523pub trait IntoKind {
524    type Kind;
525
526    fn kind(self) -> Self::Kind;
527}
528
529pub trait BoundVarLike<I: Interner> {
530    fn var(self) -> ty::BoundVar;
531
532    fn assert_eq(self, var: I::BoundVarKind);
533}
534
535pub trait ParamLike {
536    fn index(self) -> u32;
537}
538
539pub trait AdtDef<I: Interner>: Copy + Debug + Hash + Eq {
540    fn def_id(self) -> I::DefId;
541
542    fn is_struct(self) -> bool;
543
544    /// Returns the type of the struct tail.
545    ///
546    /// Expects the `AdtDef` to be a struct. If it is not, then this will panic.
547    fn struct_tail_ty(self, interner: I) -> Option<ty::EarlyBinder<I, I::Ty>>;
548
549    fn is_phantom_data(self) -> bool;
550
551    fn is_manually_drop(self) -> bool;
552
553    // FIXME: perhaps use `all_fields` and expose `FieldDef`.
554    fn all_field_tys(self, interner: I) -> ty::EarlyBinder<I, impl IntoIterator<Item = I::Ty>>;
555
556    fn sized_constraint(self, interner: I) -> Option<ty::EarlyBinder<I, I::Ty>>;
557
558    fn is_fundamental(self) -> bool;
559
560    fn destructor(self, interner: I) -> Option<AdtDestructorKind>;
561}
562
563pub trait ParamEnv<I: Interner>: Copy + Debug + Hash + Eq + TypeFoldable<I> {
564    fn caller_bounds(self) -> impl SliceLike<Item = I::Clause>;
565}
566
567pub trait Features<I: Interner>: Copy {
568    fn generic_const_exprs(self) -> bool;
569
570    fn coroutine_clone(self) -> bool;
571
572    fn associated_const_equality(self) -> bool;
573}
574
575pub trait DefId<I: Interner>: Copy + Debug + Hash + Eq + TypeFoldable<I> {
576    fn is_local(self) -> bool;
577
578    fn as_local(self) -> Option<I::LocalDefId>;
579}
580
581pub trait BoundExistentialPredicates<I: Interner>:
582    Copy + Debug + Hash + Eq + Relate<I> + SliceLike<Item = ty::Binder<I, ty::ExistentialPredicate<I>>>
583{
584    fn principal_def_id(self) -> Option<I::DefId>;
585
586    fn principal(self) -> Option<ty::Binder<I, ty::ExistentialTraitRef<I>>>;
587
588    fn auto_traits(self) -> impl IntoIterator<Item = I::DefId>;
589
590    fn projection_bounds(
591        self,
592    ) -> impl IntoIterator<Item = ty::Binder<I, ty::ExistentialProjection<I>>>;
593}
594
595pub trait Span<I: Interner>: Copy + Debug + Hash + Eq + TypeFoldable<I> {
596    fn dummy() -> Self;
597}
598
599pub trait SliceLike: Sized + Copy {
600    type Item: Copy;
601    type IntoIter: Iterator<Item = Self::Item> + DoubleEndedIterator;
602
603    fn iter(self) -> Self::IntoIter;
604
605    fn as_slice(&self) -> &[Self::Item];
606
607    fn get(self, idx: usize) -> Option<Self::Item> {
608        self.as_slice().get(idx).copied()
609    }
610
611    fn len(self) -> usize {
612        self.as_slice().len()
613    }
614
615    fn is_empty(self) -> bool {
616        self.len() == 0
617    }
618
619    fn contains(self, t: &Self::Item) -> bool
620    where
621        Self::Item: PartialEq,
622    {
623        self.as_slice().contains(t)
624    }
625
626    fn to_vec(self) -> Vec<Self::Item> {
627        self.as_slice().to_vec()
628    }
629
630    fn last(self) -> Option<Self::Item> {
631        self.as_slice().last().copied()
632    }
633
634    fn split_last(&self) -> Option<(&Self::Item, &[Self::Item])> {
635        self.as_slice().split_last()
636    }
637}
638
639impl<'a, T: Copy> SliceLike for &'a [T] {
640    type Item = T;
641    type IntoIter = std::iter::Copied<std::slice::Iter<'a, T>>;
642
643    fn iter(self) -> Self::IntoIter {
644        self.iter().copied()
645    }
646
647    fn as_slice(&self) -> &[Self::Item] {
648        *self
649    }
650}
651
652impl<'a, T: Copy, const N: usize> SliceLike for &'a [T; N] {
653    type Item = T;
654    type IntoIter = std::iter::Copied<std::slice::Iter<'a, T>>;
655
656    fn iter(self) -> Self::IntoIter {
657        self.into_iter().copied()
658    }
659
660    fn as_slice(&self) -> &[Self::Item] {
661        *self
662    }
663}
664
665impl<'a, S: SliceLike> SliceLike for &'a S {
666    type Item = S::Item;
667    type IntoIter = S::IntoIter;
668
669    fn iter(self) -> Self::IntoIter {
670        (*self).iter()
671    }
672
673    fn as_slice(&self) -> &[Self::Item] {
674        (*self).as_slice()
675    }
676}