@@ -146,6 +146,9 @@ impl<T> [T] {
146146 /// ```
147147 /// let a = [1, 2, 3];
148148 /// assert!(!a.is_empty());
149+ ///
150+ /// let b: &[i32] = &[];
151+ /// assert!(b.is_empty());
149152 /// ```
150153 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
151154 #[ rustc_const_stable( feature = "const_slice_is_empty" , since = "1.39.0" ) ]
@@ -185,6 +188,9 @@ impl<T> [T] {
185188 /// *first = 5;
186189 /// }
187190 /// assert_eq!(x, &[5, 1, 2]);
191+ ///
192+ /// let y: &mut [i32] = &mut [];
193+ /// assert_eq!(None, y.first_mut());
188194 /// ```
189195 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
190196 #[ rustc_const_unstable( feature = "const_slice_first_last" , issue = "83570" ) ]
@@ -297,7 +303,7 @@ impl<T> [T] {
297303 if let [ .., last] = self { Some ( last) } else { None }
298304 }
299305
300- /// Returns a mutable reference to the last item in the slice.
306+ /// Returns a mutable reference to the last item in the slice, or `None` if it is empty .
301307 ///
302308 /// # Examples
303309 ///
@@ -308,6 +314,9 @@ impl<T> [T] {
308314 /// *last = 10;
309315 /// }
310316 /// assert_eq!(x, &[0, 1, 10]);
317+ ///
318+ /// let y: &mut [i32] = &mut [];
319+ /// assert_eq!(None, y.last_mut());
311320 /// ```
312321 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
313322 #[ rustc_const_unstable( feature = "const_slice_first_last" , issue = "83570" ) ]
0 commit comments