Rollup merge of #130101 - RalfJung:const-cleanup, r=fee1-dead · qinheping/verify-rust-std@ac68273 (original) (raw)
`@@ -739,6 +739,7 @@ impl Option {
`
739
739
`#[stable(feature = "pin", since = "1.33.0")]
`
740
740
`#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
`
741
741
`pub const fn as_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>> {
`
``
742
`` +
// FIXME(const-hack): use map once that is possible
``
742
743
`match Pin::get_ref(self).as_ref() {
`
743
744
`` // SAFETY: x is guaranteed to be pinned because it comes from self
``
744
745
`// which is pinned.
`
`@@ -758,6 +759,7 @@ impl Option {
`
758
759
`` // SAFETY: get_unchecked_mut is never used to move the Option inside self.
``
759
760
`` // x is guaranteed to be pinned because it comes from self which is pinned.
``
760
761
`unsafe {
`
``
762
`` +
// FIXME(const-hack): use map once that is possible
``
761
763
`match Pin::get_unchecked_mut(self).as_mut() {
`
762
764
`Some(x) => Some(Pin::new_unchecked(x)),
`
763
765
`None => None,
`
`@@ -1290,10 +1292,7 @@ impl Option {
`
1290
1292
`where
`
1291
1293
`T: Deref,
`
1292
1294
`{
`
1293
``
`-
match self.as_ref() {
`
1294
``
`-
Some(t) => Some(t.deref()),
`
1295
``
`-
None => None,
`
1296
``
`-
}
`
``
1295
`+
self.as_ref().map(|t| t.deref())
`
1297
1296
`}
`
1298
1297
``
1299
1298
`` /// Converts from Option<T> (or &mut Option<T>) to Option<&mut T::Target>.
``
`@@ -1316,10 +1315,7 @@ impl Option {
`
1316
1315
`where
`
1317
1316
`T: DerefMut,
`
1318
1317
`{
`
1319
``
`-
match self.as_mut() {
`
1320
``
`-
Some(t) => Some(t.deref_mut()),
`
1321
``
`-
None => None,
`
1322
``
`-
}
`
``
1318
`+
self.as_mut().map(|t| t.deref_mut())
`
1323
1319
`}
`
1324
1320
``
1325
1321
`/////////////////////////////////////////////////////////////////////////
`
`@@ -1632,13 +1628,7 @@ impl Option {
`
1632
1628
`#[inline]
`
1633
1629
`#[stable(feature = "option_entry", since = "1.20.0")]
`
1634
1630
`pub fn get_or_insert(&mut self, value: T) -> &mut T {
`
1635
``
`-
if let None = *self {
`
1636
``
`-
*self = Some(value);
`
1637
``
`-
}
`
1638
``
-
1639
``
`` -
// SAFETY: a None variant for self would have been replaced by a Some
``
1640
``
`-
// variant in the code above.
`
1641
``
`-
unsafe { self.as_mut().unwrap_unchecked() }
`
``
1631
`+
self.get_or_insert_with(|| value)
`
1642
1632
`}
`
1643
1633
``
1644
1634
`` /// Inserts the default value into the option if it is [None], then
``
`@@ -1724,7 +1714,7 @@ impl Option {
`
1724
1714
`#[stable(feature = "rust1", since = "1.0.0")]
`
1725
1715
`#[rustc_const_unstable(feature = "const_option", issue = "67441")]
`
1726
1716
`pub const fn take(&mut self) -> Option {
`
1727
``
`` -
// FIXME replace mem::replace by mem::take when the latter is const ready
``
``
1717
`` +
// FIXME(const-hack) replace mem::replace by mem::take when the latter is const ready
``
1728
1718
` mem::replace(self, None)
`
1729
1719
`}
`
1730
1720
``