Skip to content

Commit

Permalink
Make sure that signatures aren't accidental refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Apr 28, 2023
1 parent 1c42cb4 commit 33871c9
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 24 deletions.
60 changes: 48 additions & 12 deletions library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1543,11 +1543,17 @@ impl<'a, K: 'a, V: 'a> Iterator for Iter<'a, K, V> {
self.next_back()
}

fn min(mut self) -> Option<(&'a K, &'a V)> {
fn min(mut self) -> Option<(&'a K, &'a V)>
where
(&'a K, &'a V): Ord,
{
self.next()
}

fn max(mut self) -> Option<(&'a K, &'a V)> {
fn max(mut self) -> Option<(&'a K, &'a V)>
where
(&'a K, &'a V): Ord,
{
self.next_back()
}
}
Expand Down Expand Up @@ -1612,11 +1618,17 @@ impl<'a, K, V> Iterator for IterMut<'a, K, V> {
self.next_back()
}

fn min(mut self) -> Option<(&'a K, &'a mut V)> {
fn min(mut self) -> Option<(&'a K, &'a mut V)>
where
(&'a K, &'a mut V): Ord,
{
self.next()
}

fn max(mut self) -> Option<(&'a K, &'a mut V)> {
fn max(mut self) -> Option<(&'a K, &'a mut V)>
where
(&'a K, &'a mut V): Ord,
{
self.next_back()
}
}
Expand Down Expand Up @@ -1779,11 +1791,17 @@ impl<'a, K, V> Iterator for Keys<'a, K, V> {
self.next_back()
}

fn min(mut self) -> Option<&'a K> {
fn min(mut self) -> Option<&'a K>
where
&'a K: Ord,
{
self.next()
}

fn max(mut self) -> Option<&'a K> {
fn max(mut self) -> Option<&'a K>
where
&'a K: Ord,
{
self.next_back()
}
}
Expand Down Expand Up @@ -2008,11 +2026,17 @@ impl<'a, K, V> Iterator for Range<'a, K, V> {
self.next_back()
}

fn min(mut self) -> Option<(&'a K, &'a V)> {
fn min(mut self) -> Option<(&'a K, &'a V)>
where
(&'a K, &'a V): Ord,
{
self.next()
}

fn max(mut self) -> Option<(&'a K, &'a V)> {
fn max(mut self) -> Option<(&'a K, &'a V)>
where
(&'a K, &'a V): Ord,
{
self.next_back()
}
}
Expand Down Expand Up @@ -2081,11 +2105,17 @@ impl<K, V, A: Allocator + Clone> Iterator for IntoKeys<K, V, A> {
self.next_back()
}

fn min(mut self) -> Option<K> {
fn min(mut self) -> Option<K>
where
K: Ord,
{
self.next()
}

fn max(mut self) -> Option<K> {
fn max(mut self) -> Option<K>
where
K: Ord,
{
self.next_back()
}
}
Expand Down Expand Up @@ -2204,11 +2234,17 @@ impl<'a, K, V> Iterator for RangeMut<'a, K, V> {
self.next_back()
}

fn min(mut self) -> Option<(&'a K, &'a mut V)> {
fn min(mut self) -> Option<(&'a K, &'a mut V)>
where
(&'a K, &'a mut V): Ord,
{
self.next()
}

fn max(mut self) -> Option<(&'a K, &'a mut V)> {
fn max(mut self) -> Option<(&'a K, &'a mut V)>
where
(&'a K, &'a mut V): Ord,
{
self.next_back()
}
}
Expand Down
20 changes: 16 additions & 4 deletions library/alloc/src/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1501,11 +1501,17 @@ impl<'a, T> Iterator for Iter<'a, T> {
self.next_back()
}

fn min(mut self) -> Option<&'a T> {
fn min(mut self) -> Option<&'a T>
where
&'a T: Ord,
{
self.next()
}

fn max(mut self) -> Option<&'a T> {
fn max(mut self) -> Option<&'a T>
where
&'a T: Ord,
{
self.next_back()
}
}
Expand Down Expand Up @@ -1604,11 +1610,17 @@ impl<'a, T> Iterator for Range<'a, T> {
self.next_back()
}

fn min(mut self) -> Option<&'a T> {
fn min(mut self) -> Option<&'a T>
where
&'a T: Ord,
{
self.next()
}

fn max(mut self) -> Option<&'a T> {
fn max(mut self) -> Option<&'a T>
where
&'a T: Ord,
{
self.next_back()
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2815,7 +2815,7 @@ impl<'a, T: 'a + Copy, A: Allocator> Extend<&'a T> for VecDeque<T, A> {
}

#[inline]
fn extend_one(&mut self, &elem: &T) {
fn extend_one(&mut self, &elem: &'a T) {
self.push_back(elem);
}

Expand Down
4 changes: 2 additions & 2 deletions library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ where
impl<'a, T, const N: usize> TryFrom<&'a [T]> for &'a [T; N] {
type Error = TryFromSliceError;

fn try_from(slice: &[T]) -> Result<&[T; N], TryFromSliceError> {
fn try_from(slice: &'a [T]) -> Result<&'a [T; N], TryFromSliceError> {
if slice.len() == N {
let ptr = slice.as_ptr() as *const [T; N];
// SAFETY: ok because we just checked that the length fits
Expand All @@ -275,7 +275,7 @@ impl<'a, T, const N: usize> TryFrom<&'a [T]> for &'a [T; N] {
impl<'a, T, const N: usize> TryFrom<&'a mut [T]> for &'a mut [T; N] {
type Error = TryFromSliceError;

fn try_from(slice: &mut [T]) -> Result<&mut [T; N], TryFromSliceError> {
fn try_from(slice: &'a mut [T]) -> Result<&'a mut [T; N], TryFromSliceError> {
if slice.len() == N {
let ptr = slice.as_mut_ptr() as *mut [T; N];
// SAFETY: ok because we just checked that the length fits
Expand Down
20 changes: 16 additions & 4 deletions library/core/src/iter/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,12 +732,18 @@ impl<A: Step> Iterator for ops::Range<A> {
}

#[inline]
fn min(mut self) -> Option<A> {
fn min(mut self) -> Option<A>
where
A: Ord,
{
self.next()
}

#[inline]
fn max(mut self) -> Option<A> {
fn max(mut self) -> Option<A>
where
A: Ord,
{
self.next_back()
}

Expand Down Expand Up @@ -1158,12 +1164,18 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
}

#[inline]
fn min(mut self) -> Option<A> {
fn min(mut self) -> Option<A>
where
A: Ord,
{
self.next()
}

#[inline]
fn max(mut self) -> Option<A> {
fn max(mut self) -> Option<A>
where
A: Ord,
{
self.next_back()
}

Expand Down
2 changes: 1 addition & 1 deletion library/portable-simd/crates/core_simd/src/ops/deref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ macro_rules! deref_ops {

#[inline]
#[must_use = "operator returns a new vector without mutating the inputs"]
fn $call(self, rhs: &$simd) -> Self::Output {
fn $call(self, rhs: &'rhs $simd) -> Self::Output {
(*self).$call(*rhs)
}
}
Expand Down

0 comments on commit 33871c9

Please sign in to comment.