@@ -145,8 +145,9 @@ impl<T> [T] {
145
145
/// assert_eq!(None, w.first());
146
146
/// ```
147
147
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
148
+ #[ rustc_const_unstable( feature = "const_slice_first_last" , issue = "83570" ) ]
148
149
#[ inline]
149
- pub fn first ( & self ) -> Option < & T > {
150
+ pub const fn first ( & self ) -> Option < & T > {
150
151
if let [ first, ..] = self { Some ( first) } else { None }
151
152
}
152
153
@@ -163,8 +164,9 @@ impl<T> [T] {
163
164
/// assert_eq!(x, &[5, 1, 2]);
164
165
/// ```
165
166
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
167
+ #[ rustc_const_unstable( feature = "const_slice_first_last" , issue = "83570" ) ]
166
168
#[ inline]
167
- pub fn first_mut ( & mut self ) -> Option < & mut T > {
169
+ pub const fn first_mut ( & mut self ) -> Option < & mut T > {
168
170
if let [ first, ..] = self { Some ( first) } else { None }
169
171
}
170
172
@@ -181,8 +183,9 @@ impl<T> [T] {
181
183
/// }
182
184
/// ```
183
185
#[ stable( feature = "slice_splits" , since = "1.5.0" ) ]
186
+ #[ rustc_const_unstable( feature = "const_slice_first_last" , issue = "83570" ) ]
184
187
#[ inline]
185
- pub fn split_first ( & self ) -> Option < ( & T , & [ T ] ) > {
188
+ pub const fn split_first ( & self ) -> Option < ( & T , & [ T ] ) > {
186
189
if let [ first, tail @ ..] = self { Some ( ( first, tail) ) } else { None }
187
190
}
188
191
@@ -201,8 +204,9 @@ impl<T> [T] {
201
204
/// assert_eq!(x, &[3, 4, 5]);
202
205
/// ```
203
206
#[ stable( feature = "slice_splits" , since = "1.5.0" ) ]
207
+ #[ rustc_const_unstable( feature = "const_slice_first_last" , issue = "83570" ) ]
204
208
#[ inline]
205
- pub fn split_first_mut ( & mut self ) -> Option < ( & mut T , & mut [ T ] ) > {
209
+ pub const fn split_first_mut ( & mut self ) -> Option < ( & mut T , & mut [ T ] ) > {
206
210
if let [ first, tail @ ..] = self { Some ( ( first, tail) ) } else { None }
207
211
}
208
212
@@ -219,8 +223,9 @@ impl<T> [T] {
219
223
/// }
220
224
/// ```
221
225
#[ stable( feature = "slice_splits" , since = "1.5.0" ) ]
226
+ #[ rustc_const_unstable( feature = "const_slice_first_last" , issue = "83570" ) ]
222
227
#[ inline]
223
- pub fn split_last ( & self ) -> Option < ( & T , & [ T ] ) > {
228
+ pub const fn split_last ( & self ) -> Option < ( & T , & [ T ] ) > {
224
229
if let [ init @ .., last] = self { Some ( ( last, init) ) } else { None }
225
230
}
226
231
@@ -239,8 +244,9 @@ impl<T> [T] {
239
244
/// assert_eq!(x, &[4, 5, 3]);
240
245
/// ```
241
246
#[ stable( feature = "slice_splits" , since = "1.5.0" ) ]
247
+ #[ rustc_const_unstable( feature = "const_slice_first_last" , issue = "83570" ) ]
242
248
#[ inline]
243
- pub fn split_last_mut ( & mut self ) -> Option < ( & mut T , & mut [ T ] ) > {
249
+ pub const fn split_last_mut ( & mut self ) -> Option < ( & mut T , & mut [ T ] ) > {
244
250
if let [ init @ .., last] = self { Some ( ( last, init) ) } else { None }
245
251
}
246
252
@@ -256,8 +262,9 @@ impl<T> [T] {
256
262
/// assert_eq!(None, w.last());
257
263
/// ```
258
264
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
265
+ #[ rustc_const_unstable( feature = "const_slice_first_last" , issue = "83570" ) ]
259
266
#[ inline]
260
- pub fn last ( & self ) -> Option < & T > {
267
+ pub const fn last ( & self ) -> Option < & T > {
261
268
if let [ .., last] = self { Some ( last) } else { None }
262
269
}
263
270
@@ -274,8 +281,9 @@ impl<T> [T] {
274
281
/// assert_eq!(x, &[0, 1, 10]);
275
282
/// ```
276
283
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
284
+ #[ rustc_const_unstable( feature = "const_slice_first_last" , issue = "83570" ) ]
277
285
#[ inline]
278
- pub fn last_mut ( & mut self ) -> Option < & mut T > {
286
+ pub const fn last_mut ( & mut self ) -> Option < & mut T > {
279
287
if let [ .., last] = self { Some ( last) } else { None }
280
288
}
281
289
0 commit comments