]> git.lizzy.rs Git - rust.git/blob - src/librustc_data_structures/indexed_vec.rs
Rollup merge of #56476 - GuillaumeGomez:invalid-line-number-match, r=QuietMisdreavus
[rust.git] / src / librustc_data_structures / indexed_vec.rs
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use std::fmt::Debug;
12 use std::iter::{self, FromIterator};
13 use std::slice;
14 use std::marker::PhantomData;
15 use std::ops::{Index, IndexMut, Range, RangeBounds};
16 use std::fmt;
17 use std::hash::Hash;
18 use std::vec;
19 use std::u32;
20
21 use rustc_serialize as serialize;
22
23 /// Represents some newtyped `usize` wrapper.
24 ///
25 /// (purpose: avoid mixing indexes for different bitvector domains.)
26 pub trait Idx: Copy + 'static + Ord + Debug + Hash {
27     fn new(idx: usize) -> Self;
28
29     fn index(self) -> usize;
30
31     fn increment_by(&mut self, amount: usize) {
32         let v = self.index() + amount;
33         *self = Self::new(v);
34     }
35 }
36
37 impl Idx for usize {
38     #[inline]
39     fn new(idx: usize) -> Self { idx }
40     #[inline]
41     fn index(self) -> usize { self }
42 }
43
44 impl Idx for u32 {
45     #[inline]
46     fn new(idx: usize) -> Self { assert!(idx <= u32::MAX as usize); idx as u32 }
47     #[inline]
48     fn index(self) -> usize { self as usize }
49 }
50
51 /// Creates a struct type `S` that can be used as an index with
52 /// `IndexVec` and so on.
53 ///
54 /// There are two ways of interacting with these indices:
55 ///
56 /// - The `From` impls are the preferred way. So you can do
57 ///   `S::from(v)` with a `usize` or `u32`. And you can convert back
58 ///   to an integer with `u32::from(s)`.
59 ///
60 /// - Alternatively, you can use the methods `S::new(v)` and `s.index()`
61 ///   to create/return a value.
62 ///
63 /// Internally, the index uses a u32, so the index must not exceed
64 /// `u32::MAX`. You can also customize things like the `Debug` impl,
65 /// what traits are derived, and so forth via the macro.
66 #[macro_export]
67 macro_rules! newtype_index {
68     // ---- public rules ----
69
70     // Use default constants
71     ($v:vis struct $name:ident { .. }) => (
72         newtype_index!(
73             // Leave out derives marker so we can use its absence to ensure it comes first
74             @type         [$name]
75             // shave off 256 indices at the end to allow space for packing these indices into enums
76             @max          [0xFFFF_FF00]
77             @vis          [$v]
78             @debug_format ["{}"]);
79     );
80
81     // Define any constants
82     ($v:vis struct $name:ident { $($tokens:tt)+ }) => (
83         newtype_index!(
84             // Leave out derives marker so we can use its absence to ensure it comes first
85             @type         [$name]
86             // shave off 256 indices at the end to allow space for packing these indices into enums
87             @max          [0xFFFF_FF00]
88             @vis          [$v]
89             @debug_format ["{}"]
90                           $($tokens)+);
91     );
92
93     // ---- private rules ----
94
95     // Base case, user-defined constants (if any) have already been defined
96     (@derives      [$($derives:ident,)*]
97      @type         [$type:ident]
98      @max          [$max:expr]
99      @vis          [$v:vis]
100      @debug_format [$debug_format:tt]) => (
101         #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, $($derives),*)]
102         #[rustc_layout_scalar_valid_range_end($max)]
103         $v struct $type {
104             private: u32
105         }
106
107         impl $type {
108             $v const MAX_AS_U32: u32 = $max;
109
110             $v const MAX: $type = $type::from_u32_const($max);
111
112             #[inline]
113             $v fn from_usize(value: usize) -> Self {
114                 assert!(value <= ($max as usize));
115                 unsafe {
116                     $type::from_u32_unchecked(value as u32)
117                 }
118             }
119
120             #[inline]
121             $v fn from_u32(value: u32) -> Self {
122                 assert!(value <= $max);
123                 unsafe {
124                     $type::from_u32_unchecked(value)
125                 }
126             }
127
128             /// Hacky variant of `from_u32` for use in constants.
129             /// This version checks the "max" constraint by using an
130             /// invalid array dereference.
131             #[inline]
132             $v const fn from_u32_const(value: u32) -> Self {
133                 // This will fail at const eval time unless `value <=
134                 // max` is true (in which case we get the index 0).
135                 // It will also fail at runtime, of course, but in a
136                 // kind of wacky way.
137                 let _ = ["out of range value used"][
138                     !(value <= $max) as usize
139                 ];
140
141                 unsafe {
142                     $type { private: value }
143                 }
144             }
145
146             #[inline]
147             $v const unsafe fn from_u32_unchecked(value: u32) -> Self {
148                 $type { private: value }
149             }
150
151             /// Extract value of this index as an integer.
152             #[inline]
153             $v fn index(self) -> usize {
154                 self.as_usize()
155             }
156
157             /// Extract value of this index as a usize.
158             #[inline]
159             $v fn as_u32(self) -> u32 {
160                 self.private
161             }
162
163             /// Extract value of this index as a u32.
164             #[inline]
165             $v fn as_usize(self) -> usize {
166                 self.as_u32() as usize
167             }
168         }
169
170         impl Idx for $type {
171             #[inline]
172             fn new(value: usize) -> Self {
173                 Self::from(value)
174             }
175
176             #[inline]
177             fn index(self) -> usize {
178                 usize::from(self)
179             }
180         }
181
182         impl ::std::iter::Step for $type {
183             #[inline]
184             fn steps_between(start: &Self, end: &Self) -> Option<usize> {
185                 <usize as ::std::iter::Step>::steps_between(
186                     &Idx::index(*start),
187                     &Idx::index(*end),
188                 )
189             }
190
191             #[inline]
192             fn replace_one(&mut self) -> Self {
193                 ::std::mem::replace(self, Self::new(1))
194             }
195
196             #[inline]
197             fn replace_zero(&mut self) -> Self {
198                 ::std::mem::replace(self, Self::new(0))
199             }
200
201             #[inline]
202             fn add_one(&self) -> Self {
203                 Self::new(Idx::index(*self) + 1)
204             }
205
206             #[inline]
207             fn sub_one(&self) -> Self {
208                 Self::new(Idx::index(*self) - 1)
209             }
210
211             #[inline]
212             fn add_usize(&self, u: usize) -> Option<Self> {
213                 Idx::index(*self).checked_add(u).map(Self::new)
214             }
215         }
216
217         impl From<$type> for u32 {
218             #[inline]
219             fn from(v: $type) -> u32 {
220                 v.as_u32()
221             }
222         }
223
224         impl From<$type> for usize {
225             #[inline]
226             fn from(v: $type) -> usize {
227                 v.as_usize()
228             }
229         }
230
231         impl From<usize> for $type {
232             #[inline]
233             fn from(value: usize) -> Self {
234                 $type::from_usize(value)
235             }
236         }
237
238         impl From<u32> for $type {
239             #[inline]
240             fn from(value: u32) -> Self {
241                 $type::from_u32(value)
242             }
243         }
244
245         newtype_index!(
246             @handle_debug
247             @derives      [$($derives,)*]
248             @type         [$type]
249             @debug_format [$debug_format]);
250     );
251
252     // base case for handle_debug where format is custom. No Debug implementation is emitted.
253     (@handle_debug
254      @derives      [$($_derives:ident,)*]
255      @type         [$type:ident]
256      @debug_format [custom]) => ();
257
258     // base case for handle_debug, no debug overrides found, so use default
259     (@handle_debug
260      @derives      []
261      @type         [$type:ident]
262      @debug_format [$debug_format:tt]) => (
263         impl ::std::fmt::Debug for $type {
264             fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
265                 write!(fmt, $debug_format, self.as_u32())
266             }
267         }
268     );
269
270     // Debug is requested for derive, don't generate any Debug implementation.
271     (@handle_debug
272      @derives      [Debug, $($derives:ident,)*]
273      @type         [$type:ident]
274      @debug_format [$debug_format:tt]) => ();
275
276     // It's not Debug, so just pop it off the front of the derives stack and check the rest.
277     (@handle_debug
278      @derives      [$_derive:ident, $($derives:ident,)*]
279      @type         [$type:ident]
280      @debug_format [$debug_format:tt]) => (
281         newtype_index!(
282             @handle_debug
283             @derives      [$($derives,)*]
284             @type         [$type]
285             @debug_format [$debug_format]);
286     );
287
288     // Append comma to end of derives list if it's missing
289     (@type         [$type:ident]
290      @max          [$max:expr]
291      @vis          [$v:vis]
292      @debug_format [$debug_format:tt]
293                    derive [$($derives:ident),*]
294                    $($tokens:tt)*) => (
295         newtype_index!(
296             @type         [$type]
297             @max          [$max]
298             @vis          [$v]
299             @debug_format [$debug_format]
300                           derive [$($derives,)*]
301                           $($tokens)*);
302     );
303
304     // By not including the @derives marker in this list nor in the default args, we can force it
305     // to come first if it exists. When encodable is custom, just use the derives list as-is.
306     (@type         [$type:ident]
307      @max          [$max:expr]
308      @vis          [$v:vis]
309      @debug_format [$debug_format:tt]
310                    derive [$($derives:ident,)+]
311                    ENCODABLE = custom
312                    $($tokens:tt)*) => (
313         newtype_index!(
314             @derives      [$($derives,)+]
315             @type         [$type]
316             @max          [$max]
317             @vis          [$v]
318             @debug_format [$debug_format]
319                           $($tokens)*);
320     );
321
322     // By not including the @derives marker in this list nor in the default args, we can force it
323     // to come first if it exists. When encodable isn't custom, add serialization traits by default.
324     (@type         [$type:ident]
325      @max          [$max:expr]
326      @vis          [$v:vis]
327      @debug_format [$debug_format:tt]
328                    derive [$($derives:ident,)+]
329                    $($tokens:tt)*) => (
330         newtype_index!(
331             @derives      [$($derives,)+ RustcDecodable, RustcEncodable,]
332             @type         [$type]
333             @max          [$max]
334             @vis          [$v]
335             @debug_format [$debug_format]
336                           $($tokens)*);
337     );
338
339     // The case where no derives are added, but encodable is overridden. Don't
340     // derive serialization traits
341     (@type         [$type:ident]
342      @max          [$max:expr]
343      @vis          [$v:vis]
344      @debug_format [$debug_format:tt]
345                    ENCODABLE = custom
346                    $($tokens:tt)*) => (
347         newtype_index!(
348             @derives      []
349             @type         [$type]
350             @max          [$max]
351             @vis          [$v]
352             @debug_format [$debug_format]
353                           $($tokens)*);
354     );
355
356     // The case where no derives are added, add serialization derives by default
357     (@type         [$type:ident]
358      @max          [$max:expr]
359      @vis          [$v:vis]
360      @debug_format [$debug_format:tt]
361                    $($tokens:tt)*) => (
362         newtype_index!(
363             @derives      [RustcDecodable, RustcEncodable,]
364             @type         [$type]
365             @max          [$max]
366             @vis          [$v]
367             @debug_format [$debug_format]
368                           $($tokens)*);
369     );
370
371     // Rewrite final without comma to one that includes comma
372     (@derives      [$($derives:ident,)*]
373      @type         [$type:ident]
374      @max          [$max:expr]
375      @vis          [$v:vis]
376      @debug_format [$debug_format:tt]
377                    $name:ident = $constant:expr) => (
378         newtype_index!(
379             @derives      [$($derives,)*]
380             @type         [$type]
381             @max          [$max]
382             @vis          [$v]
383             @debug_format [$debug_format]
384                           $name = $constant,);
385     );
386
387     // Rewrite final const without comma to one that includes comma
388     (@derives      [$($derives:ident,)*]
389      @type         [$type:ident]
390      @max          [$_max:expr]
391      @vis          [$v:vis]
392      @debug_format [$debug_format:tt]
393                    $(#[doc = $doc:expr])*
394                    const $name:ident = $constant:expr) => (
395         newtype_index!(
396             @derives      [$($derives,)*]
397             @type         [$type]
398             @max          [$max]
399             @vis          [$v]
400             @debug_format [$debug_format]
401                           $(#[doc = $doc])* const $name = $constant,);
402     );
403
404     // Replace existing default for max
405     (@derives      [$($derives:ident,)*]
406      @type         [$type:ident]
407      @max          [$_max:expr]
408      @vis          [$v:vis]
409      @debug_format [$debug_format:tt]
410                    MAX = $max:expr,
411                    $($tokens:tt)*) => (
412         newtype_index!(
413             @derives      [$($derives,)*]
414             @type         [$type]
415             @max          [$max]
416             @vis          [$v]
417             @debug_format [$debug_format]
418                           $($tokens)*);
419     );
420
421     // Replace existing default for debug_format
422     (@derives      [$($derives:ident,)*]
423      @type         [$type:ident]
424      @max          [$max:expr]
425      @vis          [$v:vis]
426      @debug_format [$_debug_format:tt]
427                    DEBUG_FORMAT = $debug_format:tt,
428                    $($tokens:tt)*) => (
429         newtype_index!(
430             @derives      [$($derives,)*]
431             @type         [$type]
432             @max          [$max]
433             @vis          [$v]
434             @debug_format [$debug_format]
435                           $($tokens)*);
436     );
437
438     // Assign a user-defined constant
439     (@derives      [$($derives:ident,)*]
440      @type         [$type:ident]
441      @max          [$max:expr]
442      @vis          [$v:vis]
443      @debug_format [$debug_format:tt]
444                    $(#[doc = $doc:expr])*
445                    const $name:ident = $constant:expr,
446                    $($tokens:tt)*) => (
447         $(#[doc = $doc])*
448         pub const $name: $type = $type::from_u32_const($constant);
449         newtype_index!(
450             @derives      [$($derives,)*]
451             @type         [$type]
452             @max          [$max]
453             @vis          [$v]
454             @debug_format [$debug_format]
455                           $($tokens)*);
456     );
457 }
458
459 #[derive(Clone, PartialEq, Eq, Hash)]
460 pub struct IndexVec<I: Idx, T> {
461     pub raw: Vec<T>,
462     _marker: PhantomData<fn(&I)>
463 }
464
465 // Whether `IndexVec` is `Send` depends only on the data,
466 // not the phantom data.
467 unsafe impl<I: Idx, T> Send for IndexVec<I, T> where T: Send {}
468
469 impl<I: Idx, T: serialize::Encodable> serialize::Encodable for IndexVec<I, T> {
470     fn encode<S: serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
471         serialize::Encodable::encode(&self.raw, s)
472     }
473 }
474
475 impl<I: Idx, T: serialize::Decodable> serialize::Decodable for IndexVec<I, T> {
476     fn decode<D: serialize::Decoder>(d: &mut D) -> Result<Self, D::Error> {
477         serialize::Decodable::decode(d).map(|v| {
478             IndexVec { raw: v, _marker: PhantomData }
479         })
480     }
481 }
482
483 impl<I: Idx, T: fmt::Debug> fmt::Debug for IndexVec<I, T> {
484     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
485         fmt::Debug::fmt(&self.raw, fmt)
486     }
487 }
488
489 pub type Enumerated<I, J> = iter::Map<iter::Enumerate<J>, IntoIdx<I>>;
490
491 impl<I: Idx, T> IndexVec<I, T> {
492     #[inline]
493     pub fn new() -> Self {
494         IndexVec { raw: Vec::new(), _marker: PhantomData }
495     }
496
497     #[inline]
498     pub fn from_raw(raw: Vec<T>) -> Self {
499         IndexVec { raw, _marker: PhantomData }
500     }
501
502     #[inline]
503     pub fn with_capacity(capacity: usize) -> Self {
504         IndexVec { raw: Vec::with_capacity(capacity), _marker: PhantomData }
505     }
506
507     #[inline]
508     pub fn from_elem<S>(elem: T, universe: &IndexVec<I, S>) -> Self
509         where T: Clone
510     {
511         IndexVec { raw: vec![elem; universe.len()], _marker: PhantomData }
512     }
513
514     #[inline]
515     pub fn from_elem_n(elem: T, n: usize) -> Self
516         where T: Clone
517     {
518         IndexVec { raw: vec![elem; n], _marker: PhantomData }
519     }
520
521     #[inline]
522     pub fn push(&mut self, d: T) -> I {
523         let idx = I::new(self.len());
524         self.raw.push(d);
525         idx
526     }
527
528     #[inline]
529     pub fn pop(&mut self) -> Option<T> {
530         self.raw.pop()
531     }
532
533     #[inline]
534     pub fn len(&self) -> usize {
535         self.raw.len()
536     }
537
538     /// Gives the next index that will be assigned when `push` is
539     /// called.
540     #[inline]
541     pub fn next_index(&self) -> I {
542         I::new(self.len())
543     }
544
545     #[inline]
546     pub fn is_empty(&self) -> bool {
547         self.raw.is_empty()
548     }
549
550     #[inline]
551     pub fn into_iter(self) -> vec::IntoIter<T> {
552         self.raw.into_iter()
553     }
554
555     #[inline]
556     pub fn into_iter_enumerated(self) -> Enumerated<I, vec::IntoIter<T>>
557     {
558         self.raw.into_iter().enumerate().map(IntoIdx { _marker: PhantomData })
559     }
560
561     #[inline]
562     pub fn iter(&self) -> slice::Iter<T> {
563         self.raw.iter()
564     }
565
566     #[inline]
567     pub fn iter_enumerated(&self) -> Enumerated<I, slice::Iter<'_, T>>
568     {
569         self.raw.iter().enumerate().map(IntoIdx { _marker: PhantomData })
570     }
571
572     #[inline]
573     pub fn indices(&self) -> iter::Map<Range<usize>, IntoIdx<I>> {
574         (0..self.len()).map(IntoIdx { _marker: PhantomData })
575     }
576
577     #[inline]
578     pub fn iter_mut(&mut self) -> slice::IterMut<T> {
579         self.raw.iter_mut()
580     }
581
582     #[inline]
583     pub fn iter_enumerated_mut(&mut self) -> Enumerated<I, slice::IterMut<'_, T>>
584     {
585         self.raw.iter_mut().enumerate().map(IntoIdx { _marker: PhantomData })
586     }
587
588     #[inline]
589     pub fn drain<'a, R: RangeBounds<usize>>(
590         &'a mut self, range: R) -> impl Iterator<Item=T> + 'a {
591         self.raw.drain(range)
592     }
593
594     #[inline]
595     pub fn drain_enumerated<'a, R: RangeBounds<usize>>(
596         &'a mut self, range: R) -> impl Iterator<Item=(I, T)> + 'a {
597         self.raw.drain(range).enumerate().map(IntoIdx { _marker: PhantomData })
598     }
599
600     #[inline]
601     pub fn last(&self) -> Option<I> {
602         self.len().checked_sub(1).map(I::new)
603     }
604
605     #[inline]
606     pub fn shrink_to_fit(&mut self) {
607         self.raw.shrink_to_fit()
608     }
609
610     #[inline]
611     pub fn swap(&mut self, a: I, b: I) {
612         self.raw.swap(a.index(), b.index())
613     }
614
615     #[inline]
616     pub fn truncate(&mut self, a: usize) {
617         self.raw.truncate(a)
618     }
619
620     #[inline]
621     pub fn get(&self, index: I) -> Option<&T> {
622         self.raw.get(index.index())
623     }
624
625     #[inline]
626     pub fn get_mut(&mut self, index: I) -> Option<&mut T> {
627         self.raw.get_mut(index.index())
628     }
629
630     /// Return mutable references to two distinct elements, a and b. Panics if a == b.
631     #[inline]
632     pub fn pick2_mut(&mut self, a: I, b: I) -> (&mut T, &mut T) {
633         let (ai, bi) = (a.index(), b.index());
634         assert!(ai != bi);
635
636         if ai < bi {
637             let (c1, c2) = self.raw.split_at_mut(bi);
638             (&mut c1[ai], &mut c2[0])
639         } else {
640             let (c2, c1) = self.pick2_mut(b, a);
641             (c1, c2)
642         }
643     }
644
645     pub fn convert_index_type<Ix: Idx>(self) -> IndexVec<Ix, T> {
646         IndexVec {
647             raw: self.raw,
648             _marker: PhantomData,
649         }
650     }
651 }
652
653 impl<I: Idx, T: Clone> IndexVec<I, T> {
654     /// Grows the index vector so that it contains an entry for
655     /// `elem`; if that is already true, then has no
656     /// effect. Otherwise, inserts new values as needed by invoking
657     /// `fill_value`.
658     #[inline]
659     pub fn ensure_contains_elem(&mut self, elem: I, fill_value: impl FnMut() -> T) {
660         let min_new_len = elem.index() + 1;
661         if self.len() < min_new_len {
662             self.raw.resize_with(min_new_len, fill_value);
663         }
664     }
665
666     #[inline]
667     pub fn resize(&mut self, new_len: usize, value: T) {
668         self.raw.resize(new_len, value)
669     }
670
671     #[inline]
672     pub fn resize_to_elem(&mut self, elem: I, fill_value: impl FnMut() -> T) {
673         let min_new_len = elem.index() + 1;
674         self.raw.resize_with(min_new_len, fill_value);
675     }
676 }
677
678 impl<I: Idx, T: Ord> IndexVec<I, T> {
679     #[inline]
680     pub fn binary_search(&self, value: &T) -> Result<I, I> {
681         match self.raw.binary_search(value) {
682             Ok(i) => Ok(Idx::new(i)),
683             Err(i) => Err(Idx::new(i)),
684         }
685     }
686 }
687
688 impl<I: Idx, T> Index<I> for IndexVec<I, T> {
689     type Output = T;
690
691     #[inline]
692     fn index(&self, index: I) -> &T {
693         &self.raw[index.index()]
694     }
695 }
696
697 impl<I: Idx, T> IndexMut<I> for IndexVec<I, T> {
698     #[inline]
699     fn index_mut(&mut self, index: I) -> &mut T {
700         &mut self.raw[index.index()]
701     }
702 }
703
704 impl<I: Idx, T> Default for IndexVec<I, T> {
705     #[inline]
706     fn default() -> Self {
707         Self::new()
708     }
709 }
710
711 impl<I: Idx, T> Extend<T> for IndexVec<I, T> {
712     #[inline]
713     fn extend<J: IntoIterator<Item = T>>(&mut self, iter: J) {
714         self.raw.extend(iter);
715     }
716 }
717
718 impl<I: Idx, T> FromIterator<T> for IndexVec<I, T> {
719     #[inline]
720     fn from_iter<J>(iter: J) -> Self where J: IntoIterator<Item=T> {
721         IndexVec { raw: FromIterator::from_iter(iter), _marker: PhantomData }
722     }
723 }
724
725 impl<I: Idx, T> IntoIterator for IndexVec<I, T> {
726     type Item = T;
727     type IntoIter = vec::IntoIter<T>;
728
729     #[inline]
730     fn into_iter(self) -> vec::IntoIter<T> {
731         self.raw.into_iter()
732     }
733
734 }
735
736 impl<'a, I: Idx, T> IntoIterator for &'a IndexVec<I, T> {
737     type Item = &'a T;
738     type IntoIter = slice::Iter<'a, T>;
739
740     #[inline]
741     fn into_iter(self) -> slice::Iter<'a, T> {
742         self.raw.iter()
743     }
744 }
745
746 impl<'a, I: Idx, T> IntoIterator for &'a mut IndexVec<I, T> {
747     type Item = &'a mut T;
748     type IntoIter = slice::IterMut<'a, T>;
749
750     #[inline]
751     fn into_iter(self) -> slice::IterMut<'a, T> {
752         self.raw.iter_mut()
753     }
754 }
755
756 pub struct IntoIdx<I: Idx> { _marker: PhantomData<fn(&I)> }
757 impl<I: Idx, T> FnOnce<((usize, T),)> for IntoIdx<I> {
758     type Output = (I, T);
759
760     extern "rust-call" fn call_once(self, ((n, t),): ((usize, T),)) -> Self::Output {
761         (I::new(n), t)
762     }
763 }
764
765 impl<I: Idx, T> FnMut<((usize, T),)> for IntoIdx<I> {
766     extern "rust-call" fn call_mut(&mut self, ((n, t),): ((usize, T),)) -> Self::Output {
767         (I::new(n), t)
768     }
769 }
770
771 impl<I: Idx> FnOnce<(usize,)> for IntoIdx<I> {
772     type Output = I;
773
774     extern "rust-call" fn call_once(self, (n,): (usize,)) -> Self::Output {
775         I::new(n)
776     }
777 }
778
779 impl<I: Idx> FnMut<(usize,)> for IntoIdx<I> {
780     extern "rust-call" fn call_mut(&mut self, (n,): (usize,)) -> Self::Output {
781         I::new(n)
782     }
783 }