@@ -148,8 +148,9 @@ impl<T> [T] {
148
148
/// assert_eq!(None, w.first());
149
149
/// ```
150
150
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
151
+ #[ rustc_const_unstable( feature = "const_slice_first_last" , issue = "83570" ) ]
151
152
#[ inline]
152
- pub fn first ( & self ) -> Option < & T > {
153
+ pub const fn first ( & self ) -> Option < & T > {
153
154
if let [ first, ..] = self { Some ( first) } else { None }
154
155
}
155
156
@@ -166,8 +167,9 @@ impl<T> [T] {
166
167
/// assert_eq!(x, &[5, 1, 2]);
167
168
/// ```
168
169
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
170
+ #[ rustc_const_unstable( feature = "const_slice_first_last" , issue = "83570" ) ]
169
171
#[ inline]
170
- pub fn first_mut ( & mut self ) -> Option < & mut T > {
172
+ pub const fn first_mut ( & mut self ) -> Option < & mut T > {
171
173
if let [ first, ..] = self { Some ( first) } else { None }
172
174
}
173
175
@@ -184,8 +186,9 @@ impl<T> [T] {
184
186
/// }
185
187
/// ```
186
188
#[ stable( feature = "slice_splits" , since = "1.5.0" ) ]
189
+ #[ rustc_const_unstable( feature = "const_slice_first_last" , issue = "83570" ) ]
187
190
#[ inline]
188
- pub fn split_first ( & self ) -> Option < ( & T , & [ T ] ) > {
191
+ pub const fn split_first ( & self ) -> Option < ( & T , & [ T ] ) > {
189
192
if let [ first, tail @ ..] = self { Some ( ( first, tail) ) } else { None }
190
193
}
191
194
@@ -204,8 +207,9 @@ impl<T> [T] {
204
207
/// assert_eq!(x, &[3, 4, 5]);
205
208
/// ```
206
209
#[ stable( feature = "slice_splits" , since = "1.5.0" ) ]
210
+ #[ rustc_const_unstable( feature = "const_slice_first_last" , issue = "83570" ) ]
207
211
#[ inline]
208
- pub fn split_first_mut ( & mut self ) -> Option < ( & mut T , & mut [ T ] ) > {
212
+ pub const fn split_first_mut ( & mut self ) -> Option < ( & mut T , & mut [ T ] ) > {
209
213
if let [ first, tail @ ..] = self { Some ( ( first, tail) ) } else { None }
210
214
}
211
215
@@ -222,8 +226,9 @@ impl<T> [T] {
222
226
/// }
223
227
/// ```
224
228
#[ stable( feature = "slice_splits" , since = "1.5.0" ) ]
229
+ #[ rustc_const_unstable( feature = "const_slice_first_last" , issue = "83570" ) ]
225
230
#[ inline]
226
- pub fn split_last ( & self ) -> Option < ( & T , & [ T ] ) > {
231
+ pub const fn split_last ( & self ) -> Option < ( & T , & [ T ] ) > {
227
232
if let [ init @ .., last] = self { Some ( ( last, init) ) } else { None }
228
233
}
229
234
@@ -242,8 +247,9 @@ impl<T> [T] {
242
247
/// assert_eq!(x, &[4, 5, 3]);
243
248
/// ```
244
249
#[ stable( feature = "slice_splits" , since = "1.5.0" ) ]
250
+ #[ rustc_const_unstable( feature = "const_slice_first_last" , issue = "83570" ) ]
245
251
#[ inline]
246
- pub fn split_last_mut ( & mut self ) -> Option < ( & mut T , & mut [ T ] ) > {
252
+ pub const fn split_last_mut ( & mut self ) -> Option < ( & mut T , & mut [ T ] ) > {
247
253
if let [ init @ .., last] = self { Some ( ( last, init) ) } else { None }
248
254
}
249
255
@@ -259,8 +265,9 @@ impl<T> [T] {
259
265
/// assert_eq!(None, w.last());
260
266
/// ```
261
267
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
268
+ #[ rustc_const_unstable( feature = "const_slice_first_last" , issue = "83570" ) ]
262
269
#[ inline]
263
- pub fn last ( & self ) -> Option < & T > {
270
+ pub const fn last ( & self ) -> Option < & T > {
264
271
if let [ .., last] = self { Some ( last) } else { None }
265
272
}
266
273
@@ -277,8 +284,9 @@ impl<T> [T] {
277
284
/// assert_eq!(x, &[0, 1, 10]);
278
285
/// ```
279
286
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
287
+ #[ rustc_const_unstable( feature = "const_slice_first_last" , issue = "83570" ) ]
280
288
#[ inline]
281
- pub fn last_mut ( & mut self ) -> Option < & mut T > {
289
+ pub const fn last_mut ( & mut self ) -> Option < & mut T > {
282
290
if let [ .., last] = self { Some ( last) } else { None }
283
291
}
284
292
0 commit comments