From d4c50feafdab4e7749c072aa237326b904774fce Mon Sep 17 00:00:00 2001 From: dis-da-moe Date: Wed, 9 Nov 2022 20:58:22 +0300 Subject: [PATCH 1/7] implement drain_filter for BinaryHeap --- library/alloc/src/collections/binary_heap.rs | 54 +++++++++++++++++++ .../src/collections/binary_heap/tests.rs | 11 ++++ 2 files changed, 65 insertions(+) diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs index 4583bc9a158ef..ee5083f7db189 100644 --- a/library/alloc/src/collections/binary_heap.rs +++ b/library/alloc/src/collections/binary_heap.rs @@ -1220,6 +1220,30 @@ impl BinaryHeap { pub fn clear(&mut self) { self.drain(); } + + /// Creates an iterator which uses a closure to determine if an element should be removed from the underlying vec. + /// If the closure returns true, then the element is removed and yielded. If the closure returns false, the element will remain in the binary heap and will not be yielded by the iterator. + /// # Examples + /// Splitting the binary heap into evens and odds, reusing the original allocation: + /// + /// ``` + /// #![feature(binary_heap_drain_filter)] + /// use std::collections::BinaryHeap; + /// let mut a = BinaryHeap::from(vec![1, 2, 3, 4, 5, 6, 8, 9, 11, 13, 14, 15]); + /// let mut evens = a.drain_filter(|x| *x % 2 == 0).collect::>(); + /// evens.sort(); + /// let odds = a.into_sorted_vec(); + /// + /// assert_eq!(evens, vec![2, 4, 6, 8, 14]); + /// assert_eq!(odds, vec![1, 3, 5, 9, 11, 13, 15]); + /// ``` + #[unstable(feature = "binary_heap_drain_filter", reason = "recently added", issue = "42849")] + pub fn drain_filter(&mut self, filter: F) -> DrainFilter<'_, T, F> + where + F: FnMut(&mut T) -> bool, + { + DrainFilter { inner: self.data.drain_filter(filter) } + } } /// Hole represents a hole in a slice i.e., an index without valid value @@ -1570,6 +1594,36 @@ impl FusedIterator for DrainSorted<'_, T> {} #[unstable(feature = "trusted_len", issue = "37572")] unsafe impl TrustedLen for DrainSorted<'_, T> {} +/// An iterator which uses a closure to determine if an element should be removed from the underlying vec. +/// +/// This `struct` is created by [`BinaryHeap::drain_filter()`]. See its +/// documentation for more. +/// +/// [`drain_filter`]: BinaryHeap::drain_filter +#[unstable(feature = "binary_heap_drain_filter", reason = "recently added", issue = "42849")] +#[derive(Debug)] +pub struct DrainFilter<'a, T, F> +where + F: FnMut(&mut T) -> bool, +{ + inner: crate::vec::DrainFilter<'a, T, F>, +} + +#[unstable(feature = "binary_heap_drain_filter", reason = "recently added", issue = "42849")] +impl Iterator for DrainFilter<'_, T, F> +where + F: FnMut(&mut T) -> bool, +{ + type Item = T; + fn next(&mut self) -> Option { + self.inner.next() + } + + fn size_hint(&self) -> (usize, Option) { + self.inner.size_hint() + } +} + #[stable(feature = "binary_heap_extras_15", since = "1.5.0")] impl From> for BinaryHeap { /// Converts a `Vec` into a `BinaryHeap`. diff --git a/library/alloc/src/collections/binary_heap/tests.rs b/library/alloc/src/collections/binary_heap/tests.rs index 5a05215aeeddf..71d7c8307274d 100644 --- a/library/alloc/src/collections/binary_heap/tests.rs +++ b/library/alloc/src/collections/binary_heap/tests.rs @@ -405,6 +405,17 @@ fn test_retain() { assert!(a.is_empty()); } +#[test] +fn test_drain_filter() { + let mut a = BinaryHeap::from(vec![1, 2, 3, 4, 5, 6, 8, 9, 11, 13, 14, 15]); + let mut evens = a.drain_filter(|x| *x % 2 == 0).collect::>(); + evens.sort(); + let odds = a.into_sorted_vec(); + + assert_eq!(evens, vec![2, 4, 6, 8, 14]); + assert_eq!(odds, vec![1, 3, 5, 9, 11, 13, 15]); +} + // old binaryheap failed this test // // Integrity means that all elements are present after a comparison panics, From 997252c0f46b8360d06f86337e633edf4b5d0874 Mon Sep 17 00:00:00 2001 From: dis-da-moe Date: Wed, 23 Nov 2022 01:31:12 +0300 Subject: [PATCH 2/7] make `rebuild` public, update tests and docs --- compiler/rustc_parse/src/lexer/mod.rs | 3 +- .../src/traits/select/candidate_assembly.rs | 6 +- library/alloc/src/collections/binary_heap.rs | 74 +++++++++++++++++-- .../src/collections/binary_heap/tests.rs | 27 ++++++- library/alloc/src/collections/btree/map.rs | 3 +- library/std/src/path/tests.rs | 3 +- .../std/src/sys/sgx/waitqueue/spin_mutex.rs | 6 +- 7 files changed, 107 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs index de8f1c00c1295..9356cd648f30d 100644 --- a/compiler/rustc_parse/src/lexer/mod.rs +++ b/compiler/rustc_parse/src/lexer/mod.rs @@ -409,7 +409,8 @@ impl<'a> StringReader<'a> { rustc_lexer::LiteralKind::RawByteStr { n_hashes } => { if let Some(n_hashes) = n_hashes { let n = u32::from(n_hashes); - (token::ByteStrRaw(n_hashes), Mode::RawByteStr, 3 + n, 1 + n) // br##" "## + (token::ByteStrRaw(n_hashes), Mode::RawByteStr, 3 + n, 1 + n) + // br##" "## } else { self.report_raw_str_error(start, 2); } diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 3671a0d87df57..b720217a0bff1 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -818,10 +818,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { DEREF_INTO_DYN_SUPERTRAIT, obligation.cause.body_id, obligation.cause.span, - DelayDm(|| format!( + DelayDm(|| { + format!( "`{}` implements `Deref` with supertrait `{}` as output", source, deref_output_ty - )), + ) + }), |lint| lint, ); return; diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs index ee5083f7db189..1b36b66e56cb5 100644 --- a/library/alloc/src/collections/binary_heap.rs +++ b/library/alloc/src/collections/binary_heap.rs @@ -398,6 +398,9 @@ impl BinaryHeap { /// Returns a mutable reference to the greatest item in the binary heap, or /// `None` if it is empty. /// + /// # Logic + /// This method assumes that [`BinaryHeap`]'s heap invariant is upheld. + /// /// Note: If the `PeekMut` value is leaked, the heap may be in an /// inconsistent state. /// @@ -426,12 +429,18 @@ impl BinaryHeap { /// otherwise it's *O*(1). #[stable(feature = "binary_heap_peek_mut", since = "1.12.0")] pub fn peek_mut(&mut self) -> Option> { - if self.is_empty() { None } else { Some(PeekMut { heap: self, sift: false }) } + if self.is_empty() { + None + } else { + Some(PeekMut { heap: self, sift: false }) + } } /// Removes the greatest item from the binary heap and returns it, or `None` if it /// is empty. /// + /// # Logic + /// This method assumes that [`BinaryHeap`]'s heap invariant is upheld. /// # Examples /// /// Basic usage: @@ -462,6 +471,8 @@ impl BinaryHeap { /// Pushes an item onto the binary heap. /// + /// # Logic + /// This method assumes that [`BinaryHeap`]'s heap invariant is upheld. /// # Examples /// /// Basic usage: @@ -504,6 +515,8 @@ impl BinaryHeap { /// Consumes the `BinaryHeap` and returns a vector in sorted /// (ascending) order. /// + /// # Logic + /// This method assumes that `BinaryHeap`'s heap invariant is upheld. /// # Examples /// /// Basic usage: @@ -710,7 +723,42 @@ impl BinaryHeap { } } - fn rebuild(&mut self) { + /// Rebuilds the [`BinaryHeap`] into a valid state. + /// This conversion happens in-place, and has *O*(*n*) time complexity. + /// Commonly used after operations such as [`BinaryHeap::drain_filter`] that violate [`BinaryHeap`]'s heap invariant, + /// or methods that allow interior mutability such as [`Cell`][core::cell::Cell]. + /// + /// # Examples + /// Mutates the heap interiorly using [`Cell`][core::cell::Cell] and restores it afterwards with `rebuild`. + /// + /// ``` + /// #![feature(binary_heap_rebuild)] + /// #![feature(binary_heap_into_iter_sorted)] + /// use std::{ + /// collections::BinaryHeap, + /// cell::Cell + /// }; + /// + /// let mut a = BinaryHeap::from(vec![Cell::new(0), Cell::new(1), Cell::new(2), Cell::new(3)]); + /// + /// let sorted_values = |heap: &BinaryHeap>| { + /// heap.clone() + /// // this method assumes the heap is in a valid state. + /// .into_iter_sorted() + /// .map(|x| x.get()) + /// .collect::>() + /// }; + /// + /// // internal mutation invalidates the heap order and so the sort fails + /// a.peek().unwrap().set(0); + /// assert_eq!(sorted_values(&a), [0, 2, 1, 0]); + /// + /// // the heap is rebuilt to a valid state and so the sort works + /// a.rebuild(); + /// assert_eq!(sorted_values(&a), [2, 1, 0, 0]); + /// ``` + #[unstable(feature = "binary_heap_rebuild", reason = "recently added", issue = "none")] + pub fn rebuild(&mut self) { let mut n = self.len() / 2; while n > 0 { n -= 1; @@ -723,6 +771,8 @@ impl BinaryHeap { /// Moves all the elements of `other` into `self`, leaving `other` empty. /// + /// # Logic + /// This method assumes that [`BinaryHeap`]'s heap invariant is upheld. /// # Examples /// /// Basic usage: @@ -762,6 +812,8 @@ impl BinaryHeap { /// * `.drain_sorted()` is *O*(*n* \* log(*n*)); much slower than `.drain()`. /// You should use the latter for most cases. /// + /// # Logic + /// This method assumes that [`BinaryHeap`]’s heap invariant is upheld. /// # Examples /// /// Basic usage: @@ -787,6 +839,8 @@ impl BinaryHeap { /// In other words, remove all elements `e` for which `f(&e)` returns /// `false`. The elements are visited in unsorted (and unspecified) order. /// + /// # Logic + /// This method assumes that [`BinaryHeap`]'s heap invariant is upheld. /// # Examples /// /// Basic usage: @@ -846,6 +900,8 @@ impl BinaryHeap { /// Returns an iterator which retrieves elements in heap order. /// This method consumes the original heap. /// + /// # Logic + /// This method assumes that [`BinaryHeap`]’s heap invariant is upheld. /// # Examples /// /// Basic usage: @@ -864,6 +920,8 @@ impl BinaryHeap { /// Returns the greatest item in the binary heap, or `None` if it is empty. /// + /// # Logic + /// This method assumes that [`BinaryHeap`]’s heap invariant is upheld. /// # Examples /// /// Basic usage: @@ -1223,19 +1281,23 @@ impl BinaryHeap { /// Creates an iterator which uses a closure to determine if an element should be removed from the underlying vec. /// If the closure returns true, then the element is removed and yielded. If the closure returns false, the element will remain in the binary heap and will not be yielded by the iterator. + /// # Logic + /// This operation violates [`BinaryHeap`]'s heap invariant. + /// It is necessary to call [`BinaryHeap::rebuild`] afterwards if you plan to use methods that assume a heap invariant. /// # Examples /// Splitting the binary heap into evens and odds, reusing the original allocation: /// /// ``` /// #![feature(binary_heap_drain_filter)] + /// #![feature(binary_heap_rebuild)] /// use std::collections::BinaryHeap; - /// let mut a = BinaryHeap::from(vec![1, 2, 3, 4, 5, 6, 8, 9, 11, 13, 14, 15]); + /// let mut a = BinaryHeap::from(vec![1, 2, 3, 4, 5]); /// let mut evens = a.drain_filter(|x| *x % 2 == 0).collect::>(); /// evens.sort(); + /// a.rebuild(); //restores heap /// let odds = a.into_sorted_vec(); - /// - /// assert_eq!(evens, vec![2, 4, 6, 8, 14]); - /// assert_eq!(odds, vec![1, 3, 5, 9, 11, 13, 15]); + /// assert_eq!(evens, vec![2, 4]); + /// assert_eq!(odds, vec![1, 3, 5]); /// ``` #[unstable(feature = "binary_heap_drain_filter", reason = "recently added", issue = "42849")] pub fn drain_filter(&mut self, filter: F) -> DrainFilter<'_, T, F> diff --git a/library/alloc/src/collections/binary_heap/tests.rs b/library/alloc/src/collections/binary_heap/tests.rs index 71d7c8307274d..b487dbbb22be6 100644 --- a/library/alloc/src/collections/binary_heap/tests.rs +++ b/library/alloc/src/collections/binary_heap/tests.rs @@ -1,5 +1,6 @@ use super::*; use crate::boxed::Box; +use core::cell::Cell; use std::iter::TrustedLen; use std::panic::{catch_unwind, AssertUnwindSafe}; use std::sync::atomic::{AtomicU32, Ordering}; @@ -407,13 +408,33 @@ fn test_retain() { #[test] fn test_drain_filter() { - let mut a = BinaryHeap::from(vec![1, 2, 3, 4, 5, 6, 8, 9, 11, 13, 14, 15]); + let mut a = BinaryHeap::from(vec![1, 2, 3, 4, 5]); let mut evens = a.drain_filter(|x| *x % 2 == 0).collect::>(); evens.sort(); + a.rebuild(); let odds = a.into_sorted_vec(); + assert_eq!(evens, vec![2, 4]); + assert_eq!(odds, vec![1, 3, 5]); +} - assert_eq!(evens, vec![2, 4, 6, 8, 14]); - assert_eq!(odds, vec![1, 3, 5, 9, 11, 13, 15]); +#[test] +fn test_rebuild() { + let mut a = BinaryHeap::from(vec![Cell::new(0), Cell::new(1), Cell::new(2), Cell::new(3)]); + + let sorted_values = |heap: &BinaryHeap>| { + heap.clone() + // this method assumes the heap is in a valid state. + .into_iter_sorted() + .map(|x| x.get()) + .collect::>() + }; + // internal mutation invalidates the heap order and so the sort fails + a.peek().unwrap().set(0); + assert_eq!(sorted_values(&a), [0, 2, 1, 0]); + + // the heap is rebuilt to a valid state and so the sort works + a.rebuild(); + assert_eq!(sorted_values(&a), [2, 1, 0, 0]); } // old binaryheap failed this test diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index c4c75e46a2a3b..d798a3e8a21c9 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -283,7 +283,8 @@ impl Clone for BTreeMap { if self.is_empty() { BTreeMap::new_in((*self.alloc).clone()) } else { - clone_subtree(self.root.as_ref().unwrap().reborrow(), (*self.alloc).clone()) // unwrap succeeds because not empty + clone_subtree(self.root.as_ref().unwrap().reborrow(), (*self.alloc).clone()) + // unwrap succeeds because not empty } } } diff --git a/library/std/src/path/tests.rs b/library/std/src/path/tests.rs index dd307022c6d05..04e8e681a69a2 100644 --- a/library/std/src/path/tests.rs +++ b/library/std/src/path/tests.rs @@ -1727,7 +1727,8 @@ fn test_unix_absolute() { // Test leading `.` and `..` components let curdir = crate::env::current_dir().unwrap(); assert_eq!(absolute("./a").unwrap().as_os_str(), curdir.join("a").as_os_str()); - assert_eq!(absolute("../a").unwrap().as_os_str(), curdir.join("../a").as_os_str()); // return /pwd/../a + assert_eq!(absolute("../a").unwrap().as_os_str(), curdir.join("../a").as_os_str()); + // return /pwd/../a } #[test] diff --git a/library/std/src/sys/sgx/waitqueue/spin_mutex.rs b/library/std/src/sys/sgx/waitqueue/spin_mutex.rs index f6e851ccaddfa..cf17a4a593802 100644 --- a/library/std/src/sys/sgx/waitqueue/spin_mutex.rs +++ b/library/std/src/sys/sgx/waitqueue/spin_mutex.rs @@ -56,7 +56,11 @@ impl SpinMutex { /// Lock the Mutex or return false. pub macro try_lock_or_false($e:expr) { - if let Some(v) = $e.try_lock() { v } else { return false } + if let Some(v) = $e.try_lock() { + v + } else { + return false; + } } impl<'a, T> Deref for SpinMutexGuard<'a, T> { From e1586de93ecc9d0030ef03c67e344ab4663db18c Mon Sep 17 00:00:00 2001 From: dis-da-moe Date: Wed, 23 Nov 2022 01:32:17 +0300 Subject: [PATCH 3/7] fmt --- library/alloc/src/collections/binary_heap.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs index 1b36b66e56cb5..b7bd562ef2c46 100644 --- a/library/alloc/src/collections/binary_heap.rs +++ b/library/alloc/src/collections/binary_heap.rs @@ -429,11 +429,7 @@ impl BinaryHeap { /// otherwise it's *O*(1). #[stable(feature = "binary_heap_peek_mut", since = "1.12.0")] pub fn peek_mut(&mut self) -> Option> { - if self.is_empty() { - None - } else { - Some(PeekMut { heap: self, sift: false }) - } + if self.is_empty() { None } else { Some(PeekMut { heap: self, sift: false }) } } /// Removes the greatest item from the binary heap and returns it, or `None` if it From f055c35e690334e943d215b1234bd43c2a01ba72 Mon Sep 17 00:00:00 2001 From: dis-da-moe Date: Wed, 23 Nov 2022 01:38:04 +0300 Subject: [PATCH 4/7] fmt --- library/alloc/src/collections/binary_heap.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs index b7bd562ef2c46..83a7aed382379 100644 --- a/library/alloc/src/collections/binary_heap.rs +++ b/library/alloc/src/collections/binary_heap.rs @@ -429,7 +429,11 @@ impl BinaryHeap { /// otherwise it's *O*(1). #[stable(feature = "binary_heap_peek_mut", since = "1.12.0")] pub fn peek_mut(&mut self) -> Option> { - if self.is_empty() { None } else { Some(PeekMut { heap: self, sift: false }) } + if self.is_empty() { + None + } else { + Some(PeekMut { heap: self, sift: false }) + } } /// Removes the greatest item from the binary heap and returns it, or `None` if it @@ -732,7 +736,7 @@ impl BinaryHeap { /// #![feature(binary_heap_into_iter_sorted)] /// use std::{ /// collections::BinaryHeap, - /// cell::Cell + /// cell::Cell, /// }; /// /// let mut a = BinaryHeap::from(vec![Cell::new(0), Cell::new(1), Cell::new(2), Cell::new(3)]); From 36e49382adf60ad795d4b902052205f82a3d8078 Mon Sep 17 00:00:00 2001 From: dis-da-moe Date: Wed, 23 Nov 2022 01:38:34 +0300 Subject: [PATCH 5/7] fmt --- library/alloc/src/collections/binary_heap.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs index 83a7aed382379..7bd50e7bdd481 100644 --- a/library/alloc/src/collections/binary_heap.rs +++ b/library/alloc/src/collections/binary_heap.rs @@ -740,7 +740,7 @@ impl BinaryHeap { /// }; /// /// let mut a = BinaryHeap::from(vec![Cell::new(0), Cell::new(1), Cell::new(2), Cell::new(3)]); - /// + /// /// let sorted_values = |heap: &BinaryHeap>| { /// heap.clone() /// // this method assumes the heap is in a valid state. From 0b89033e0f9348433a5bddda6dfa7a1c58b1b52e Mon Sep 17 00:00:00 2001 From: dis-da-moe Date: Wed, 23 Nov 2022 01:39:04 +0300 Subject: [PATCH 6/7] fmt --- library/alloc/src/collections/binary_heap.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs index 7bd50e7bdd481..a420d9b4af9aa 100644 --- a/library/alloc/src/collections/binary_heap.rs +++ b/library/alloc/src/collections/binary_heap.rs @@ -429,11 +429,7 @@ impl BinaryHeap { /// otherwise it's *O*(1). #[stable(feature = "binary_heap_peek_mut", since = "1.12.0")] pub fn peek_mut(&mut self) -> Option> { - if self.is_empty() { - None - } else { - Some(PeekMut { heap: self, sift: false }) - } + if self.is_empty() { None } else { Some(PeekMut { heap: self, sift: false }) } } /// Removes the greatest item from the binary heap and returns it, or `None` if it From c5c2068bfaaf002823a6353474e60c441f5d6d74 Mon Sep 17 00:00:00 2001 From: dis-da-moe Date: Wed, 23 Nov 2022 01:42:08 +0300 Subject: [PATCH 7/7] revert accidental formatting changes --- compiler/rustc_parse/src/lexer/mod.rs | 3 +-- .../src/traits/select/candidate_assembly.rs | 6 ++---- library/alloc/src/collections/btree/map.rs | 3 +-- library/std/src/path/tests.rs | 3 +-- library/std/src/sys/sgx/waitqueue/spin_mutex.rs | 6 +----- 5 files changed, 6 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs index 9356cd648f30d..de8f1c00c1295 100644 --- a/compiler/rustc_parse/src/lexer/mod.rs +++ b/compiler/rustc_parse/src/lexer/mod.rs @@ -409,8 +409,7 @@ impl<'a> StringReader<'a> { rustc_lexer::LiteralKind::RawByteStr { n_hashes } => { if let Some(n_hashes) = n_hashes { let n = u32::from(n_hashes); - (token::ByteStrRaw(n_hashes), Mode::RawByteStr, 3 + n, 1 + n) - // br##" "## + (token::ByteStrRaw(n_hashes), Mode::RawByteStr, 3 + n, 1 + n) // br##" "## } else { self.report_raw_str_error(start, 2); } diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index b720217a0bff1..3671a0d87df57 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -818,12 +818,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { DEREF_INTO_DYN_SUPERTRAIT, obligation.cause.body_id, obligation.cause.span, - DelayDm(|| { - format!( + DelayDm(|| format!( "`{}` implements `Deref` with supertrait `{}` as output", source, deref_output_ty - ) - }), + )), |lint| lint, ); return; diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index d798a3e8a21c9..c4c75e46a2a3b 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -283,8 +283,7 @@ impl Clone for BTreeMap { if self.is_empty() { BTreeMap::new_in((*self.alloc).clone()) } else { - clone_subtree(self.root.as_ref().unwrap().reborrow(), (*self.alloc).clone()) - // unwrap succeeds because not empty + clone_subtree(self.root.as_ref().unwrap().reborrow(), (*self.alloc).clone()) // unwrap succeeds because not empty } } } diff --git a/library/std/src/path/tests.rs b/library/std/src/path/tests.rs index 04e8e681a69a2..dd307022c6d05 100644 --- a/library/std/src/path/tests.rs +++ b/library/std/src/path/tests.rs @@ -1727,8 +1727,7 @@ fn test_unix_absolute() { // Test leading `.` and `..` components let curdir = crate::env::current_dir().unwrap(); assert_eq!(absolute("./a").unwrap().as_os_str(), curdir.join("a").as_os_str()); - assert_eq!(absolute("../a").unwrap().as_os_str(), curdir.join("../a").as_os_str()); - // return /pwd/../a + assert_eq!(absolute("../a").unwrap().as_os_str(), curdir.join("../a").as_os_str()); // return /pwd/../a } #[test] diff --git a/library/std/src/sys/sgx/waitqueue/spin_mutex.rs b/library/std/src/sys/sgx/waitqueue/spin_mutex.rs index cf17a4a593802..f6e851ccaddfa 100644 --- a/library/std/src/sys/sgx/waitqueue/spin_mutex.rs +++ b/library/std/src/sys/sgx/waitqueue/spin_mutex.rs @@ -56,11 +56,7 @@ impl SpinMutex { /// Lock the Mutex or return false. pub macro try_lock_or_false($e:expr) { - if let Some(v) = $e.try_lock() { - v - } else { - return false; - } + if let Some(v) = $e.try_lock() { v } else { return false } } impl<'a, T> Deref for SpinMutexGuard<'a, T> {