Skip to content

Commit 467933b

Browse files
committed
Rust: Also add specialized IndexMut implementations
1 parent 40eff65 commit 467933b

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

rust/tools/builtins/impls.rs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
/// }
3131
/// ```
3232
///
33-
/// which the type inference library cannot currently handle (we fail
34-
/// to resolve the `Output` types).
33+
/// (as well as their `IndexMut` counterparts), which the type inference library
34+
/// cannot currently handle (we fail to resolve the `Output` types).
3535
mod index_impls {
3636
use std::alloc::Allocator;
3737
use std::ops::Index;
@@ -44,6 +44,14 @@ mod index_impls {
4444
}
4545
}
4646

47+
impl<T, const N: usize> IndexMut<i32> for [T; N] {
48+
type Output = T;
49+
50+
fn index_mut(&mut self, index: i32) -> &mut Self::Output {
51+
panic!()
52+
}
53+
}
54+
4755
impl<T, const N: usize> Index<usize> for [T; N] {
4856
type Output = T;
4957

@@ -52,6 +60,14 @@ mod index_impls {
5260
}
5361
}
5462

63+
impl<T, const N: usize> IndexMut<usize> for [T; N] {
64+
type Output = T;
65+
66+
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
67+
panic!()
68+
}
69+
}
70+
5571
impl<T> Index<i32> for [T] {
5672
type Output = T;
5773

@@ -60,6 +76,14 @@ mod index_impls {
6076
}
6177
}
6278

79+
impl<T> IndexMut<i32> for [T] {
80+
type Output = T;
81+
82+
fn index_mut(&mut self, index: i32) -> &mut Self::Output {
83+
panic!()
84+
}
85+
}
86+
6387
impl<T> Index<usize> for [T] {
6488
type Output = T;
6589

@@ -68,6 +92,14 @@ mod index_impls {
6892
}
6993
}
7094

95+
impl<T> IndexMut<usize> for [T] {
96+
type Output = T;
97+
98+
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
99+
panic!()
100+
}
101+
}
102+
71103
impl<T, A: Allocator> Index<i32> for Vec<T, A> {
72104
type Output = T;
73105

@@ -76,11 +108,27 @@ mod index_impls {
76108
}
77109
}
78110

111+
impl<T, A: Allocator> IndexMut<i32> for Vec<T, A> {
112+
type Output = T;
113+
114+
fn index_mut(&mut self, index: i32) -> &mut Self::Output {
115+
panic!()
116+
}
117+
}
118+
79119
impl<T, A: Allocator> Index<usize> for Vec<T, A> {
80120
type Output = T;
81121

82122
fn index(&self, index: usize) -> &Self::Output {
83123
panic!()
84124
}
85125
}
126+
127+
impl<T, A: Allocator> IndexMut<usize> for Vec<T, A> {
128+
type Output = T;
129+
130+
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
131+
panic!()
132+
}
133+
}
86134
}

0 commit comments

Comments
 (0)