Skip to main content

chumsky/
container.rs

1//! TODO
2
3use super::*;
4use alloc::collections::LinkedList;
5use core::hash::BuildHasher;
6use hashbrown::HashSet;
7
8/// A utility trait for types that hold a specific constant number of output values.
9///
10/// # Safety
11///
12/// This trait requires that [`Uninit`](ContainerExactly::Uninit) be sound to reinterpret as `Self`
13pub unsafe trait ContainerExactly<T> {
14    /// The length of this container
15    const LEN: usize;
16
17    /// An uninitialized value of this container.
18    type Uninit;
19
20    /// Get an uninitialized form of this container.
21    fn uninit() -> Self::Uninit;
22
23    /// Write a value to a position in an uninitialized container.
24    fn write(uninit: &mut Self::Uninit, i: usize, item: T);
25
26    /// Drop all values before a provided index in this container.
27    ///
28    /// # Safety
29    ///
30    /// All values up to the provided index must be initialized.
31    unsafe fn drop_before(uninit: &mut Self::Uninit, i: usize);
32
33    /// Convert this container into its initialized form.
34    ///
35    /// # Safety
36    ///
37    /// All values in the container must be initialized.
38    unsafe fn take(uninit: Self::Uninit) -> Self;
39}
40
41// SAFETY: `[MaybeUninit<T>; N]` has the same layout as `[T; N]`
42unsafe impl<T, const N: usize> ContainerExactly<T> for [T; N] {
43    const LEN: usize = N;
44
45    type Uninit = [MaybeUninit<T>; N];
46    fn uninit() -> Self::Uninit {
47        MaybeUninitExt::uninit_array()
48    }
49    fn write(uninit: &mut Self::Uninit, i: usize, item: T) {
50        uninit[i].write(item);
51    }
52    unsafe fn drop_before(uninit: &mut Self::Uninit, i: usize) {
53        uninit[..i].iter_mut().for_each(|o| o.assume_init_drop());
54    }
55    unsafe fn take(uninit: Self::Uninit) -> Self {
56        MaybeUninitExt::array_assume_init(uninit)
57    }
58}
59
60// Safety: `Box<C::Uninit>` is sound to reinterpret assuming the inner `C` implements this trait soundly
61unsafe impl<T, C> ContainerExactly<T> for Box<C>
62where
63    C: ContainerExactly<T>,
64{
65    const LEN: usize = C::LEN;
66    type Uninit = Box<C::Uninit>;
67    fn uninit() -> Self::Uninit {
68        Box::new(C::uninit())
69    }
70    fn write(uninit: &mut Self::Uninit, i: usize, item: T) {
71        C::write(&mut *uninit, i, item)
72    }
73    unsafe fn drop_before(uninit: &mut Self::Uninit, i: usize) {
74        C::drop_before(&mut *uninit, i)
75    }
76    unsafe fn take(uninit: Self::Uninit) -> Self {
77        Box::from_raw(Box::into_raw(uninit) as *mut C)
78    }
79}
80
81/*
82// TODO: Unsound!
83// Safety: `Rc<UnsafeCell<C::Uninit>>` is sound to reinterpret assuming the inner `C` implements
84//         this trait soundly
85unsafe impl<T, C> ContainerExactly<T> for Rc<C>
86where
87    C: ContainerExactly<T>,
88{
89    const LEN: usize = C::LEN;
90    type Uninit = Rc<UnsafeCell<C::Uninit>>;
91    fn uninit() -> Self::Uninit {
92        Rc::new(UnsafeCell::new(C::uninit()))
93    }
94    fn write(uninit: &mut Self::Uninit, i: usize, item: T) {
95        // SAFETY: We're the only owners of the uninit data at this point
96        C::write(unsafe { &mut *uninit.get() }, i, item)
97    }
98    unsafe fn drop_before(uninit: &mut Self::Uninit, i: usize) {
99        // SAFETY: We're the only owners of the uninit data at this point
100        C::drop_before(unsafe { &mut *uninit.get() }, i)
101    }
102    unsafe fn take(uninit: Self::Uninit) -> Self {
103        Rc::from_raw(Rc::into_raw(uninit) as *mut C)
104    }
105}
106*/
107
108/*
109// TODO: Unsound!
110#[allow(clippy::arc_with_non_send_sync)]
111// SAFETY: `Arc<UnsafeCell<C::Uninit>>` is sound to reinterpret assuming the inner `C` implements
112//         this trait soundly
113unsafe impl<T, C> ContainerExactly<T> for Arc<C>
114where
115    C: ContainerExactly<T>,
116{
117    const LEN: usize = C::LEN;
118    type Uninit = Arc<UnsafeCell<C::Uninit>>;
119    fn uninit() -> Self::Uninit {
120        Arc::new(UnsafeCell::new(C::uninit()))
121    }
122    fn write(uninit: &mut Self::Uninit, i: usize, item: T) {
123        // SAFETY: We're the only owners of the uninit data at this point
124        C::write(unsafe { &mut *uninit.get() }, i, item)
125    }
126    unsafe fn drop_before(uninit: &mut Self::Uninit, i: usize) {
127        // SAFETY: We're the only owners of the uninit data at this point
128        C::drop_before(unsafe { &mut *uninit.get() }, i)
129    }
130    unsafe fn take(uninit: Self::Uninit) -> Self {
131        Arc::from_raw(Arc::into_raw(uninit) as *mut C)
132    }
133}
134*/
135
136/// A utility trait to abstract over container-like things.
137///
138/// This trait is likely to change in future versions of the crate, so avoid implementing it yourself.
139pub trait Seq<'p, T> {
140    /// The item yielded by the iterator.
141    type Item<'a>: Borrow<T>
142    where
143        Self: 'a;
144
145    /// An iterator over the items within this container, by reference.
146    type Iter<'a>: Iterator<Item = Self::Item<'a>>
147    where
148        Self: 'a;
149
150    /// Iterate over the elements of the container.
151    fn seq_iter(&self) -> Self::Iter<'_>;
152
153    /// Check whether an item is contained within this sequence.
154    fn contains(&self, val: &T) -> bool
155    where
156        T: PartialEq;
157
158    /// Convert an item of the sequence into a [`MaybeRef`].
159    fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, T>
160    where
161        'p: 'b;
162
163    #[doc(hidden)]
164    #[cfg(feature = "debug")]
165    fn seq_info(&self, _scope: &mut debug::NodeScope) -> debug::SeqInfo {
166        let ty = core::any::type_name::<Self>();
167        debug::SeqInfo::Unknown(ty.split_once('<').map_or(ty, |(ty, _)| ty).to_string())
168    }
169}
170
171impl<'p, T: Clone> Seq<'p, T> for T {
172    type Item<'a>
173        = &'a T
174    where
175        Self: 'a;
176
177    type Iter<'a>
178        = core::iter::Once<&'a T>
179    where
180        Self: 'a;
181
182    #[inline(always)]
183    fn seq_iter(&self) -> Self::Iter<'_> {
184        core::iter::once(self)
185    }
186
187    #[inline(always)]
188    fn contains(&self, val: &T) -> bool
189    where
190        T: PartialEq,
191    {
192        self == val
193    }
194
195    #[inline]
196    fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, T>
197    where
198        'p: 'b,
199    {
200        MaybeRef::Val(item.clone())
201    }
202
203    #[doc(hidden)]
204    #[cfg(feature = "debug")]
205    default fn seq_info(&self, _scope: &mut debug::NodeScope) -> debug::SeqInfo {
206        let ty = core::any::type_name::<Self>();
207        debug::SeqInfo::Unknown(ty.split_once('<').map_or(ty, |(ty, _)| ty).to_string())
208    }
209}
210
211#[doc(hidden)]
212#[cfg(feature = "debug")]
213impl<'p, T: Clone + core::fmt::Debug> Seq<'p, T> for T {
214    default fn seq_info(&self, _scope: &mut debug::NodeScope) -> debug::SeqInfo {
215        debug::SeqInfo::Opaque(format!("{self:?}"))
216    }
217}
218
219#[doc(hidden)]
220#[cfg(feature = "debug")]
221impl Seq<'_, char> for char {
222    fn seq_info(&self, _scope: &mut debug::NodeScope) -> debug::SeqInfo {
223        debug::SeqInfo::Char(*self)
224    }
225}
226
227impl<'p, T> Seq<'p, T> for &'p T {
228    type Item<'a>
229        = &'p T
230    where
231        Self: 'a;
232
233    type Iter<'a>
234        = core::iter::Once<&'p T>
235    where
236        Self: 'a;
237
238    #[inline(always)]
239    fn seq_iter(&self) -> Self::Iter<'_> {
240        core::iter::once(*self)
241    }
242
243    #[inline(always)]
244    fn contains(&self, val: &T) -> bool
245    where
246        T: PartialEq,
247    {
248        *self == val
249    }
250
251    #[inline]
252    fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, T>
253    where
254        'p: 'b,
255    {
256        MaybeRef::Ref(item)
257    }
258}
259
260impl<'p, T> Seq<'p, T> for &'p [T] {
261    type Item<'a>
262        = &'p T
263    where
264        Self: 'a;
265
266    type Iter<'a>
267        = core::slice::Iter<'p, T>
268    where
269        Self: 'a;
270
271    #[inline(always)]
272    fn seq_iter(&self) -> Self::Iter<'_> {
273        (self as &[T]).iter()
274    }
275
276    #[inline(always)]
277    fn contains(&self, val: &T) -> bool
278    where
279        T: PartialEq,
280    {
281        <[T]>::contains(self, val)
282    }
283
284    #[inline]
285    fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, T>
286    where
287        'p: 'b,
288    {
289        MaybeRef::Ref(item)
290    }
291}
292
293impl<'p, T: Clone, const N: usize> Seq<'p, T> for [T; N] {
294    type Item<'a>
295        = &'a T
296    where
297        Self: 'a;
298
299    type Iter<'a>
300        = core::slice::Iter<'a, T>
301    where
302        Self: 'a;
303
304    #[inline(always)]
305    fn seq_iter(&self) -> Self::Iter<'_> {
306        self.iter()
307    }
308
309    #[inline(always)]
310    fn contains(&self, val: &T) -> bool
311    where
312        T: PartialEq,
313    {
314        <[T]>::contains(self, val)
315    }
316
317    #[inline]
318    fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, T>
319    where
320        'p: 'b,
321    {
322        MaybeRef::Val(item.clone())
323    }
324}
325
326impl<'p, T, const N: usize> Seq<'p, T> for &'p [T; N] {
327    type Item<'a>
328        = &'p T
329    where
330        Self: 'a;
331
332    type Iter<'a>
333        = core::slice::Iter<'p, T>
334    where
335        Self: 'a;
336
337    #[inline(always)]
338    fn seq_iter(&self) -> Self::Iter<'_> {
339        self.iter()
340    }
341
342    #[inline(always)]
343    fn contains(&self, val: &T) -> bool
344    where
345        T: PartialEq,
346    {
347        #[allow(clippy::explicit_auto_deref)] // FIXME: Clippy bug #9841
348        <[T]>::contains(*self, val)
349    }
350
351    #[inline]
352    fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, T>
353    where
354        'p: 'b,
355    {
356        MaybeRef::Ref(item)
357    }
358}
359
360impl<'p, T: Clone> Seq<'p, T> for Vec<T> {
361    type Item<'a>
362        = &'a T
363    where
364        Self: 'a;
365
366    type Iter<'a>
367        = core::slice::Iter<'a, T>
368    where
369        Self: 'a;
370
371    #[inline(always)]
372    fn seq_iter(&self) -> Self::Iter<'_> {
373        self.iter()
374    }
375
376    #[inline(always)]
377    fn contains(&self, val: &T) -> bool
378    where
379        T: PartialEq,
380    {
381        <[T]>::contains(self, val)
382    }
383
384    #[inline]
385    fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, T>
386    where
387        'p: 'b,
388    {
389        MaybeRef::Val(item.clone())
390    }
391}
392
393impl<'p, T: Clone> Seq<'p, T> for LinkedList<T> {
394    type Item<'a>
395        = &'a T
396    where
397        Self: 'a;
398
399    type Iter<'a>
400        = alloc::collections::linked_list::Iter<'a, T>
401    where
402        Self: 'a;
403
404    #[inline(always)]
405    fn seq_iter(&self) -> Self::Iter<'_> {
406        self.iter()
407    }
408
409    #[inline(always)]
410    fn contains(&self, val: &T) -> bool
411    where
412        T: PartialEq,
413    {
414        LinkedList::contains(self, val)
415    }
416
417    #[inline]
418    fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, T>
419    where
420        'p: 'b,
421    {
422        MaybeRef::Val(item.clone())
423    }
424}
425
426impl<'p, T: Clone + Eq + Hash, S: BuildHasher> Seq<'p, T> for HashSet<T, S> {
427    type Item<'a>
428        = &'a T
429    where
430        Self: 'a;
431
432    type Iter<'a>
433        = hashbrown::hash_set::Iter<'a, T>
434    where
435        Self: 'a;
436
437    #[inline(always)]
438    fn seq_iter(&self) -> Self::Iter<'_> {
439        self.iter()
440    }
441
442    #[inline(always)]
443    fn contains(&self, val: &T) -> bool
444    where
445        T: PartialEq,
446    {
447        HashSet::contains(self, val)
448    }
449
450    #[inline]
451    fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, T>
452    where
453        'p: 'b,
454        S: 'b,
455    {
456        MaybeRef::Val(item.clone())
457    }
458}
459
460#[cfg(feature = "std")]
461impl<'p, T: Clone + Eq + Hash, S: BuildHasher> Seq<'p, T> for std::collections::HashSet<T, S> {
462    type Item<'a>
463        = &'a T
464    where
465        Self: 'a;
466
467    type Iter<'a>
468        = std::collections::hash_set::Iter<'a, T>
469    where
470        Self: 'a;
471
472    #[inline(always)]
473    fn seq_iter(&self) -> Self::Iter<'_> {
474        self.iter()
475    }
476
477    #[inline(always)]
478    fn contains(&self, val: &T) -> bool
479    where
480        T: PartialEq,
481    {
482        self.contains(val)
483    }
484
485    #[inline]
486    fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, T>
487    where
488        'p: 'b,
489        S: 'b,
490    {
491        MaybeRef::Val(item.clone())
492    }
493}
494
495impl<'p, T: Clone + Ord> Seq<'p, T> for alloc::collections::BTreeSet<T> {
496    type Item<'a>
497        = &'a T
498    where
499        Self: 'a;
500
501    type Iter<'a>
502        = alloc::collections::btree_set::Iter<'a, T>
503    where
504        Self: 'a;
505
506    #[inline(always)]
507    fn seq_iter(&self) -> Self::Iter<'_> {
508        self.iter()
509    }
510
511    #[inline(always)]
512    fn contains(&self, val: &T) -> bool
513    where
514        T: PartialEq,
515    {
516        self.contains(val)
517    }
518
519    #[inline]
520    fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, T>
521    where
522        'p: 'b,
523    {
524        MaybeRef::Val(item.clone())
525    }
526}
527
528impl<'p, T> Seq<'p, T> for Range<T>
529where
530    T: Clone + PartialOrd, // Explicit declaration of an implied truth - `Step` requires these
531    Self: Iterator<Item = T>,
532{
533    type Item<'a>
534        = T
535    where
536        Self: 'a;
537
538    type Iter<'a>
539        = Range<T>
540    where
541        Self: 'a;
542
543    #[inline(always)]
544    fn seq_iter(&self) -> Self::Iter<'_> {
545        (*self).clone()
546    }
547
548    #[inline(always)]
549    fn contains(&self, val: &T) -> bool {
550        Range::contains(self, val)
551    }
552
553    #[inline]
554    fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, T>
555    where
556        'p: 'b,
557    {
558        MaybeRef::Val(item)
559    }
560}
561
562impl<'p, T> Seq<'p, T> for core::ops::RangeInclusive<T>
563where
564    T: Clone + PartialOrd,
565    Self: Iterator<Item = T>,
566{
567    type Item<'a>
568        = T
569    where
570        Self: 'a;
571
572    type Iter<'a>
573        = core::ops::RangeInclusive<T>
574    where
575        Self: 'a;
576
577    #[inline(always)]
578    fn seq_iter(&self) -> Self::Iter<'_> {
579        self.clone()
580    }
581
582    #[inline(always)]
583    fn contains(&self, val: &T) -> bool {
584        core::ops::RangeInclusive::contains(self, val)
585    }
586
587    #[inline]
588    fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, T>
589    where
590        'p: 'b,
591    {
592        MaybeRef::Val(item)
593    }
594}
595
596impl<'p, T> Seq<'p, T> for RangeFrom<T>
597where
598    T: Clone + PartialOrd,
599    Self: Iterator<Item = T>,
600{
601    type Item<'a>
602        = T
603    where
604        Self: 'a;
605
606    type Iter<'a>
607        = RangeFrom<T>
608    where
609        Self: 'a;
610
611    #[inline(always)]
612    fn seq_iter(&self) -> Self::Iter<'_> {
613        self.clone()
614    }
615
616    #[inline(always)]
617    fn contains(&self, val: &T) -> bool {
618        RangeFrom::contains(self, val)
619    }
620
621    #[inline]
622    fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, T>
623    where
624        'p: 'b,
625    {
626        MaybeRef::Val(item)
627    }
628}
629
630impl<'p> Seq<'p, char> for str {
631    type Item<'a>
632        = char
633    where
634        Self: 'a;
635
636    type Iter<'a>
637        = core::str::Chars<'a>
638    where
639        Self: 'a;
640
641    #[inline(always)]
642    fn seq_iter(&self) -> Self::Iter<'_> {
643        self.chars()
644    }
645
646    #[inline(always)]
647    fn contains(&self, val: &char) -> bool {
648        self.contains(*val)
649    }
650
651    #[inline]
652    fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, char>
653    where
654        'p: 'b,
655    {
656        MaybeRef::Val(item)
657    }
658}
659
660impl<'p> Seq<'p, char> for String {
661    type Item<'a>
662        = char
663    where
664        Self: 'a;
665
666    type Iter<'a>
667        = core::str::Chars<'a>
668    where
669        Self: 'a;
670
671    #[inline(always)]
672    fn seq_iter(&self) -> Self::Iter<'_> {
673        self.chars()
674    }
675
676    #[inline(always)]
677    fn contains(&self, val: &char) -> bool {
678        str::contains(self, *val)
679    }
680
681    #[inline]
682    fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, char>
683    where
684        'p: 'b,
685    {
686        MaybeRef::Val(item)
687    }
688}
689
690impl<'p> Seq<'p, char> for &'p str {
691    type Item<'a>
692        = char
693    where
694        Self: 'a;
695
696    type Iter<'a>
697        = core::str::Chars<'a>
698    where
699        Self: 'a;
700
701    #[inline(always)]
702    fn seq_iter(&self) -> Self::Iter<'_> {
703        self.chars()
704    }
705
706    #[inline(always)]
707    fn contains(&self, val: &char) -> bool {
708        str::contains(self, *val)
709    }
710
711    #[inline]
712    fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, char>
713    where
714        'p: 'b,
715    {
716        MaybeRef::Val(item)
717    }
718
719    #[doc(hidden)]
720    #[cfg(feature = "debug")]
721    fn seq_info(&self, _scope: &mut debug::NodeScope) -> debug::SeqInfo {
722        debug::SeqInfo::String(self.to_string())
723    }
724}
725
726impl<'p> Seq<'p, &'p Grapheme> for &'p str {
727    type Item<'a>
728        = &'p Grapheme
729    where
730        Self: 'a;
731
732    type Iter<'a>
733        = GraphemesIter<'p>
734    where
735        Self: 'a;
736
737    #[inline(always)]
738    fn seq_iter(&self) -> Self::Iter<'_> {
739        Graphemes::new(self).iter()
740    }
741
742    #[inline(always)]
743    fn contains(&self, val: &&'p Grapheme) -> bool {
744        Graphemes::new(self).contains(val)
745    }
746
747    #[inline]
748    fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, &'p Grapheme>
749    where
750        'p: 'b,
751    {
752        MaybeRef::Val(item)
753    }
754
755    #[doc(hidden)]
756    #[cfg(feature = "debug")]
757    fn seq_info(&self, _scope: &mut debug::NodeScope) -> debug::SeqInfo {
758        debug::SeqInfo::String(self.to_string())
759    }
760}
761
762impl<'p> Seq<'p, &'p Grapheme> for &'p Graphemes {
763    type Item<'a>
764        = &'p Grapheme
765    where
766        Self: 'a;
767
768    type Iter<'a>
769        = GraphemesIter<'p>
770    where
771        Self: 'a;
772
773    #[inline(always)]
774    fn seq_iter(&self) -> Self::Iter<'_> {
775        self.iter()
776    }
777
778    #[inline(always)]
779    fn contains(&self, val: &&'p Grapheme) -> bool {
780        self.iter().any(|i| i == *val)
781    }
782
783    #[inline]
784    fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, &'p Grapheme>
785    where
786        'p: 'b,
787    {
788        MaybeRef::Val(item)
789    }
790}
791
792/// A utility trait to abstract over *linear* container-like things.
793///
794/// This trait is likely to change in future versions of the crate, so avoid implementing it yourself.
795pub trait OrderedSeq<'p, T>: Seq<'p, T> {}
796
797impl<T: Clone> OrderedSeq<'_, T> for T {}
798
799impl<'p, T> OrderedSeq<'p, T> for &'p T {}
800impl<'p, T> OrderedSeq<'p, T> for &'p [T] {}
801impl<T: Clone, const N: usize> OrderedSeq<'_, T> for [T; N] {}
802impl<'p, T, const N: usize> OrderedSeq<'p, T> for &'p [T; N] {}
803impl<T: Clone> OrderedSeq<'_, T> for Vec<T> {}
804impl<'p, T> OrderedSeq<'p, T> for Range<T> where Self: Seq<'p, T> {}
805impl<'p, T> OrderedSeq<'p, T> for core::ops::RangeInclusive<T> where Self: Seq<'p, T> {}
806impl<'p, T> OrderedSeq<'p, T> for RangeFrom<T> where Self: Seq<'p, T> {}
807
808impl OrderedSeq<'_, char> for str {}
809impl OrderedSeq<'_, char> for String {}
810impl<'p> OrderedSeq<'p, char> for &'p str {}
811impl<'p> OrderedSeq<'p, &'p Grapheme> for &'p str {}
812impl<'p> OrderedSeq<'p, &'p Grapheme> for &'p Graphemes {}
813
814#[cfg(test)]
815mod test {
816    use super::*;
817
818    fn init_container<C: ContainerExactly<usize>>() -> C {
819        let mut uninit = C::uninit();
820        for idx in 0..C::LEN {
821            C::write(&mut uninit, idx, idx);
822        }
823        // SAFETY: All elements were initialized.
824        unsafe { C::take(uninit) }
825    }
826
827    fn drop_container<C: ContainerExactly<usize>>() {
828        let mut uninit = C::uninit();
829        for idx in 0..(C::LEN / 2) {
830            C::write(&mut uninit, idx, idx);
831        }
832        // SAFETY: All elements up to this point were initialized.
833        unsafe { C::drop_before(&mut uninit, C::LEN / 2) };
834    }
835
836    #[test]
837    fn exact_array() {
838        let c = init_container::<[usize; 4]>();
839        assert_eq!(&c, &[0, 1, 2, 3]);
840        drop_container::<[usize; 4]>();
841    }
842
843    // #[test]
844    // fn exact_rc_array() {
845    //     let c = init_container::<Rc<[usize; 4]>>();
846    //     assert_eq!(&*c, &[0, 1, 2, 3]);
847    //     drop_container::<Rc<[usize; 4]>>();
848    // }
849
850    // #[test]
851    // fn exact_rc_box_array() {
852    //     let c = init_container::<Rc<Box<[usize; 4]>>>();
853    //     assert_eq!(&**c, &[0, 1, 2, 3]);
854    //     drop_container::<Rc<Box<[usize; 4]>>>();
855    // }
856
857    // #[test]
858    // fn exact_box_rc_array() {
859    //     let c = init_container::<Box<Rc<[usize; 4]>>>();
860    //     assert_eq!(&**c, &[0, 1, 2, 3]);
861    //     drop_container::<Box<Rc<[usize; 4]>>>();
862    // }
863}