@@ -574,17 +574,22 @@ impl<T> Option<T> {
574
574
/// ```
575
575
/// #![feature(option_insert)]
576
576
///
577
- /// let mut o = None;
578
- /// let v = o.insert(3);
579
- /// assert_eq!(*v, 3);
577
+ /// let mut opt = None;
578
+ /// let val = opt.insert(1);
579
+ /// assert_eq!(*val, 1);
580
+ /// assert_eq!(opt.unwrap(), 1);
581
+ /// let val = opt.insert(2);
582
+ /// assert_eq!(*val, 2);
583
+ /// *val = 3;
584
+ /// assert_eq!(opt.unwrap(), 3);
580
585
/// ```
581
586
#[ inline]
582
- #[ unstable( feature = "option_insert" , reason = "new API " , issue = "none" ) ]
583
- pub fn insert ( & mut self , v : T ) -> & mut T {
584
- * self = Some ( v ) ;
587
+ #[ unstable( feature = "option_insert" , reason = "newly added " , issue = "none" ) ]
588
+ pub fn insert ( & mut self , val : T ) -> & mut T {
589
+ * self = Some ( val ) ;
585
590
586
- match * self {
587
- Some ( ref mut v) => v,
591
+ match self {
592
+ Some ( v) => v,
588
593
// SAFETY: the code above just filled the option
589
594
None => unsafe { hint:: unreachable_unchecked ( ) } ,
590
595
}
@@ -839,8 +844,8 @@ impl<T> Option<T> {
839
844
/// ```
840
845
#[ inline]
841
846
#[ stable( feature = "option_entry" , since = "1.20.0" ) ]
842
- pub fn get_or_insert ( & mut self , v : T ) -> & mut T {
843
- self . get_or_insert_with ( || v )
847
+ pub fn get_or_insert ( & mut self , val : T ) -> & mut T {
848
+ self . get_or_insert_with ( || val )
844
849
}
845
850
846
851
/// Inserts a value computed from `f` into the option if it is [`None`], then
@@ -867,8 +872,8 @@ impl<T> Option<T> {
867
872
* self = Some ( f ( ) ) ;
868
873
}
869
874
870
- match * self {
871
- Some ( ref mut v) => v,
875
+ match self {
876
+ Some ( v) => v,
872
877
// SAFETY: a `None` variant for `self` would have been replaced by a `Some`
873
878
// variant in the code above.
874
879
None => unsafe { hint:: unreachable_unchecked ( ) } ,
0 commit comments