Skip to content

Commit eb14da9

Browse files
authored
Use allows ref struct in a few more places (#103604)
1 parent a582842 commit eb14da9

File tree

9 files changed

+24
-22
lines changed

9 files changed

+24
-22
lines changed

src/libraries/System.Memory/ref/System.Memory.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,10 @@ public static partial class MemoryExtensions
223223
public static System.Span<T> AsSpan<T>(this T[]? array, System.Range range) { throw null; }
224224
public static int BinarySearch<T>(this System.ReadOnlySpan<T> span, System.IComparable<T> comparable) { throw null; }
225225
public static int BinarySearch<T>(this System.Span<T> span, System.IComparable<T> comparable) { throw null; }
226-
public static int BinarySearch<T, TComparer>(this System.ReadOnlySpan<T> span, T value, TComparer comparer) where TComparer : System.Collections.Generic.IComparer<T> { throw null; }
227-
public static int BinarySearch<T, TComparable>(this System.ReadOnlySpan<T> span, TComparable comparable) where TComparable : System.IComparable<T> { throw null; }
228-
public static int BinarySearch<T, TComparer>(this System.Span<T> span, T value, TComparer comparer) where TComparer : System.Collections.Generic.IComparer<T> { throw null; }
229-
public static int BinarySearch<T, TComparable>(this System.Span<T> span, TComparable comparable) where TComparable : System.IComparable<T> { throw null; }
226+
public static int BinarySearch<T, TComparer>(this System.ReadOnlySpan<T> span, T value, TComparer comparer) where TComparer : System.Collections.Generic.IComparer<T>, allows ref struct { throw null; }
227+
public static int BinarySearch<T, TComparable>(this System.ReadOnlySpan<T> span, TComparable comparable) where TComparable : System.IComparable<T>, allows ref struct { throw null; }
228+
public static int BinarySearch<T, TComparer>(this System.Span<T> span, T value, TComparer comparer) where TComparer : System.Collections.Generic.IComparer<T>, allows ref struct { throw null; }
229+
public static int BinarySearch<T, TComparable>(this System.Span<T> span, TComparable comparable) where TComparable : System.IComparable<T>, allows ref struct { throw null; }
230230
public static int CommonPrefixLength<T>(this System.Span<T> span, System.ReadOnlySpan<T> other) { throw null; }
231231
public static int CommonPrefixLength<T>(this System.Span<T> span, System.ReadOnlySpan<T> other, System.Collections.Generic.IEqualityComparer<T>? comparer) { throw null; }
232232
public static int CommonPrefixLength<T>(this System.ReadOnlySpan<T> span, System.ReadOnlySpan<T> other) { throw null; }

src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IAlternateEqualityComparer.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ namespace System.Collections.Generic
99
/// </summary>
1010
/// <typeparam name="TAlternate">The alternate type to compare.</typeparam>
1111
/// <typeparam name="T">The type to compare.</typeparam>
12-
public interface IAlternateEqualityComparer<in TAlternate, T> where TAlternate : allows ref struct
12+
public interface IAlternateEqualityComparer<in TAlternate, T>
13+
where TAlternate : allows ref struct
14+
where T : allows ref struct
1315
{
1416
/// <summary>Determines whether the specified <paramref name="alternate"/> equals the specified <paramref name="other"/>.</summary>
1517
/// <param name="alternate">The instance of type <typeparamref name="TAlternate"/> to compare.</param>

src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IComparer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace System.Collections.Generic
88
// The generic IComparer interface implements a method that compares
99
// two objects. It is used in conjunction with the Sort and
1010
// BinarySearch methods on the Array, List, and SortedList classes.
11-
public interface IComparer<in T>
11+
public interface IComparer<in T> where T : allows ref struct
1212
{
1313
// Compares two objects. An implementation of this method must return a
1414
// value less than zero if x is less than y, zero if x is equal to y, or a

src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IEqualityComparer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace System.Collections.Generic
88
// The generic IEqualityComparer interface implements methods to check if two objects are equal
99
// and generate Hashcode for an object.
1010
// It is used in Dictionary class.
11-
public interface IEqualityComparer<in T>
11+
public interface IEqualityComparer<in T> where T : allows ref struct
1212
{
1313
bool Equals(T? x, T? y);
1414
int GetHashCode([DisallowNull] T obj);

src/libraries/System.Private.CoreLib/src/System/IComparable.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public interface IComparable
4141

4242
// Generic version of IComparable.
4343

44-
public interface IComparable<in T>
44+
public interface IComparable<in T> where T : allows ref struct
4545
{
4646
// Interface does not need to be marked with the serializable attribute
4747

src/libraries/System.Private.CoreLib/src/System/IEquatable.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace System
55
{
6-
public interface IEquatable<T> // invariant due to questionable semantics around equality and inheritance
6+
public interface IEquatable<T> where T : allows ref struct // invariant due to questionable semantics around equality and inheritance
77
{
88
/// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
99
/// <param name="other">An object to compare with this object.</param>

src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3138,7 +3138,7 @@ public static int BinarySearch<T>(
31383138
[MethodImpl(MethodImplOptions.AggressiveInlining)]
31393139
public static int BinarySearch<T, TComparable>(
31403140
this Span<T> span, TComparable comparable)
3141-
where TComparable : IComparable<T>
3141+
where TComparable : IComparable<T>, allows ref struct
31423142
{
31433143
return BinarySearch((ReadOnlySpan<T>)span, comparable);
31443144
}
@@ -3164,7 +3164,7 @@ public static int BinarySearch<T, TComparable>(
31643164
[MethodImpl(MethodImplOptions.AggressiveInlining)]
31653165
public static int BinarySearch<T, TComparer>(
31663166
this Span<T> span, T value, TComparer comparer)
3167-
where TComparer : IComparer<T>
3167+
where TComparer : IComparer<T>, allows ref struct
31683168
{
31693169
return BinarySearch((ReadOnlySpan<T>)span, value, comparer);
31703170
}
@@ -3212,7 +3212,7 @@ public static int BinarySearch<T>(
32123212
[MethodImpl(MethodImplOptions.AggressiveInlining)]
32133213
public static int BinarySearch<T, TComparable>(
32143214
this ReadOnlySpan<T> span, TComparable comparable)
3215-
where TComparable : IComparable<T>
3215+
where TComparable : IComparable<T>, allows ref struct
32163216
{
32173217
return SpanHelpers.BinarySearch(span, comparable);
32183218
}
@@ -3238,7 +3238,7 @@ public static int BinarySearch<T, TComparable>(
32383238
[MethodImpl(MethodImplOptions.AggressiveInlining)]
32393239
public static int BinarySearch<T, TComparer>(
32403240
this ReadOnlySpan<T> span, T value, TComparer comparer)
3241-
where TComparer : IComparer<T>
3241+
where TComparer : IComparer<T>, allows ref struct
32423242
{
32433243
if (comparer == null)
32443244
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparer);

src/libraries/System.Private.CoreLib/src/System/SpanHelpers.BinarySearch.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal static partial class SpanHelpers
1212
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1313
public static int BinarySearch<T, TComparable>(
1414
this ReadOnlySpan<T> span, TComparable comparable)
15-
where TComparable : IComparable<T>
15+
where TComparable : IComparable<T>, allows ref struct
1616
{
1717
if (comparable == null)
1818
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparable);
@@ -22,7 +22,7 @@ public static int BinarySearch<T, TComparable>(
2222

2323
public static int BinarySearch<T, TComparable>(
2424
ref T spanStart, int length, TComparable comparable)
25-
where TComparable : IComparable<T>
25+
where TComparable : IComparable<T>, allows ref struct
2626
{
2727
int lo = 0;
2828
int hi = length - 1;
@@ -59,8 +59,8 @@ public static int BinarySearch<T, TComparable>(
5959
}
6060

6161
// Helper to allow sharing all code via IComparable<T> inlineable
62-
internal readonly struct ComparerComparable<T, TComparer> : IComparable<T>
63-
where TComparer : IComparer<T>
62+
internal readonly ref struct ComparerComparable<T, TComparer> : IComparable<T>
63+
where TComparer : IComparer<T>, allows ref struct
6464
{
6565
private readonly T _value;
6666
private readonly TComparer _comparer;

src/libraries/System.Runtime/ref/System.Runtime.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3451,7 +3451,7 @@ public partial interface IComparable
34513451
{
34523452
int CompareTo(object? obj);
34533453
}
3454-
public partial interface IComparable<in T>
3454+
public partial interface IComparable<in T> where T : allows ref struct
34553455
{
34563456
int CompareTo(T? other);
34573457
}
@@ -3484,7 +3484,7 @@ public partial interface IDisposable
34843484
{
34853485
void Dispose();
34863486
}
3487-
public partial interface IEquatable<T>
3487+
public partial interface IEquatable<T> where T : allows ref struct
34883488
{
34893489
bool Equals(T? other);
34903490
}
@@ -8170,7 +8170,7 @@ public partial interface IStructuralEquatable
81708170
}
81718171
namespace System.Collections.Generic
81728172
{
8173-
public interface IAlternateEqualityComparer<in TAlternate, T> where TAlternate : allows ref struct
8173+
public interface IAlternateEqualityComparer<in TAlternate, T> where TAlternate : allows ref struct where T : allows ref struct
81748174
{
81758175
bool Equals(TAlternate alternate, T other);
81768176
int GetHashCode(TAlternate alternate);
@@ -8195,7 +8195,7 @@ public partial interface ICollection<T> : System.Collections.Generic.IEnumerable
81958195
void CopyTo(T[] array, int arrayIndex);
81968196
bool Remove(T item);
81978197
}
8198-
public partial interface IComparer<in T>
8198+
public partial interface IComparer<in T> where T : allows ref struct
81998199
{
82008200
int Compare(T? x, T? y);
82018201
}
@@ -8217,7 +8217,7 @@ public partial interface IEnumerator<out T> : System.Collections.IEnumerator, Sy
82178217
{
82188218
new T Current { get; }
82198219
}
8220-
public partial interface IEqualityComparer<in T>
8220+
public partial interface IEqualityComparer<in T> where T : allows ref struct
82218221
{
82228222
bool Equals(T? x, T? y);
82238223
int GetHashCode([System.Diagnostics.CodeAnalysis.DisallowNullAttribute] T obj);

0 commit comments

Comments
 (0)