From de16951dad317a0ce07cf73f7b2202e20f331aa5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 19 Apr 2021 17:48:51 +0300 Subject: [PATCH 1/5] Clarify the difference between insert and get_or_insert --- library/core/src/option.rs | 64 +++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 1e1e9613696..1c68abaf79d 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -594,34 +594,6 @@ impl Option { } } - /// Inserts `value` into the option then returns a mutable reference to it. - /// - /// If the option already contains a value, the old value is dropped. - /// - /// # Example - /// - /// ``` - /// let mut opt = None; - /// let val = opt.insert(1); - /// assert_eq!(*val, 1); - /// assert_eq!(opt.unwrap(), 1); - /// let val = opt.insert(2); - /// assert_eq!(*val, 2); - /// *val = 3; - /// assert_eq!(opt.unwrap(), 3); - /// ``` - #[inline] - #[stable(feature = "option_insert", since = "1.53.0")] - pub fn insert(&mut self, value: T) -> &mut T { - *self = Some(value); - - match self { - Some(v) => v, - // SAFETY: the code above just filled the option - None => unsafe { hint::unreachable_unchecked() }, - } - } - ///////////////////////////////////////////////////////////////////////// // Iterator constructors ///////////////////////////////////////////////////////////////////////// @@ -849,12 +821,46 @@ impl Option { } ///////////////////////////////////////////////////////////////////////// - // Entry-like operations to insert if None and return a reference + // Entry-like operations to insert a value and return a reference ///////////////////////////////////////////////////////////////////////// + /// Inserts `value` into the option then returns a mutable reference to it. + /// + /// If the option already contains a value, the old value is dropped. + /// + /// See also [`Option::get_or_insert`], which doesn't update the value if + /// the option already contains [`Some`]. + /// + /// # Example + /// + /// ``` + /// let mut opt = None; + /// let val = opt.insert(1); + /// assert_eq!(*val, 1); + /// assert_eq!(opt.unwrap(), 1); + /// let val = opt.insert(2); + /// assert_eq!(*val, 2); + /// *val = 3; + /// assert_eq!(opt.unwrap(), 3); + /// ``` + #[inline] + #[stable(feature = "option_insert", since = "1.53.0")] + pub fn insert(&mut self, value: T) -> &mut T { + *self = Some(value); + + match self { + Some(v) => v, + // SAFETY: the code above just filled the option + None => unsafe { hint::unreachable_unchecked() }, + } + } + /// Inserts `value` into the option if it is [`None`], then /// returns a mutable reference to the contained value. /// + /// See also [`Option::insert`], which updates the value even if + /// the option already contains [`Some`]. + /// /// # Examples /// /// ``` From 9b624071d3b174c59774ebbcd4a06588224d0fdd Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 19 Apr 2021 11:40:25 -0700 Subject: [PATCH 2/5] rustdoc: Show nag box on IE10 Rustdoc doesn't work on IE11. It's been broken for months, it isn't supported by the [tiered browser support list], it's even more severely broken on other Rust websites, and IE11 doesn't support the `
` tag that we want to use. In the interest of honesty, let's give an actual error message for anyone on IE11. [tiered browser support list]: https://github.com/rust-lang/rfcs/blob/master/text/1985-tiered-browser-support.md --- src/librustdoc/html/layout.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index dc67a63d333..fbd8f21b76a 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -68,7 +68,7 @@ crate fn render( \ \ \ -