From: Stephen Toub Date: Fri, 7 Aug 2020 15:25:42 +0000 (-0400) Subject: Use T? for unconstrained nullable types (#40197) X-Git-Tag: submit/tizen/20210909.063632~6155 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e7204f5d6fcaca5e097ec854b3be6055229fc442;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Use T? for unconstrained nullable types (#40197) * Temporarily upgrade compiler version for T? support * Use T? for unconstrained nullable types --- diff --git a/docs/coding-guidelines/api-guidelines/nullability.md b/docs/coding-guidelines/api-guidelines/nullability.md index 8c029d0..62e0fe3 100644 --- a/docs/coding-guidelines/api-guidelines/nullability.md +++ b/docs/coding-guidelines/api-guidelines/nullability.md @@ -99,6 +99,7 @@ The C# compiler respects a set of attributes that impact its flow analysis. We - **DO** add `[NotNullIfNotNull(string)]` if nullable ref argument will be non-`null` upon exit, when an other argument passed evaluated to non-`null`, pass that argument name as string. Example: `public void Exchange([NotNullIfNotNull("value")] ref object? location, object? value);`. - **DO** add `[return: NotNullIfNotNull(string)]` if a method would not return `null` in case an argument passed evaluated to non-`null`, pass that argument name as string. Example: `[return: NotNullIfNotNull("name")] public string? FormatName(string? name);` - **DO** add `[MemberNotNull(string fieldName)]` to a helper method which initializes member field(s), passing in the field name. Example: `[MemberNotNull("_buffer")] private void InitializeBuffer()`. This will help to avoid spurious warnings at call sites that call the initialization method and then proceed to use the specified field. Note that there are two constructors to `MemberNotNull`; one that takes a single `string`, and one that takes a `params string[]`. When the number of fields initialized is small (e.g. <= 3), it's preferable to use multiple `[MemberNotNull(string)]` attributes on the method rather than one `[MemberNotNull(string, string, string, ...)]` attribute, as the latter is not CLS compliant and will likely require `#pragma warning disable` and `#pragma warning restore` around the line to suppress warnings. +- **AVOID** using `[MaybeNull]`, not because it's problematic, but because there's almost always a better option, such as `T?` (as of this writing, in all of the dotnet/runtime there are only 7 occurrences of `[MaybeNull]`). One example of where it's applicable is `AsyncLocal.Value`; `[DisallowNull]` can't be used here, because `null` is valid if `T` is nullable, and `T?` shouldn't be used because `Value` shouldn't be set to `null` if `T` isn't nullable. Another is in the relatively rare case where a public or protected field is exposed, may begin life as null, but shouldn't be explicitly set to null. ## Code Review Guidance diff --git a/eng/Versions.props b/eng/Versions.props index 45e7544..02bd975 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -16,6 +16,8 @@ release true + + 3.8.0-2.20379.3 true false true diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/GC.cs b/src/coreclr/src/System.Private.CoreLib/src/System/GC.cs index 1809ea6..cb011de 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/GC.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/GC.cs @@ -659,7 +659,7 @@ namespace System /// If pinned is set to true, must not be a reference type or a type that contains object references. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] // forced to ensure no perf drop for small memory buffers (hot path) - public static T[] AllocateUninitializedArray(int length, bool pinned = false) + public static T[] AllocateUninitializedArray(int length, bool pinned = false) // T[] rather than T?[] to match `new T[length]` behavior { if (!pinned) { @@ -705,7 +705,7 @@ namespace System /// /// If pinned is set to true, must not be a reference type or a type that contains object references. /// - public static T[] AllocateArray(int length, bool pinned = false) + public static T[] AllocateArray(int length, bool pinned = false) // T[] rather than T?[] to match `new T[length]` behavior { GC_ALLOC_FLAGS flags = GC_ALLOC_FLAGS.GC_ALLOC_NO_FLAGS; diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs index 994244c..016d950 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs @@ -706,7 +706,7 @@ namespace System.Runtime.InteropServices } [SupportedOSPlatform("windows")] - public static TWrapper CreateWrapperOfType([AllowNull] T o) + public static TWrapper CreateWrapperOfType(T? o) { return (TWrapper)CreateWrapperOfType(o, typeof(TWrapper))!; } @@ -756,7 +756,7 @@ namespace System.Runtime.InteropServices public static extern void GetNativeVariantForObject(object? obj, /* VARIANT * */ IntPtr pDstNativeVariant); [SupportedOSPlatform("windows")] - public static void GetNativeVariantForObject([AllowNull] T obj, IntPtr pDstNativeVariant) + public static void GetNativeVariantForObject(T? obj, IntPtr pDstNativeVariant) { GetNativeVariantForObject((object?)obj, pDstNativeVariant); } @@ -766,10 +766,9 @@ namespace System.Runtime.InteropServices public static extern object? GetObjectForNativeVariant(/* VARIANT * */ IntPtr pSrcNativeVariant); [SupportedOSPlatform("windows")] - [return: MaybeNull] - public static T GetObjectForNativeVariant(IntPtr pSrcNativeVariant) + public static T? GetObjectForNativeVariant(IntPtr pSrcNativeVariant) { - return (T)GetObjectForNativeVariant(pSrcNativeVariant)!; + return (T?)GetObjectForNativeVariant(pSrcNativeVariant); } [SupportedOSPlatform("windows")] diff --git a/src/libraries/Common/src/System/Data/ProviderBase/DbReferenceCollection.cs b/src/libraries/Common/src/System/Data/ProviderBase/DbReferenceCollection.cs index 1ccde66..8d7aa93 100644 --- a/src/libraries/Common/src/System/Data/ProviderBase/DbReferenceCollection.cs +++ b/src/libraries/Common/src/System/Data/ProviderBase/DbReferenceCollection.cs @@ -137,8 +137,7 @@ namespace System.Data.ProviderBase } } - [return: MaybeNull] - internal T FindItem(int tag, Func filterMethod) where T : class + internal T? FindItem(int tag, Func filterMethod) where T : class { bool lockObtained = false; try diff --git a/src/libraries/Common/src/System/Net/Http/aspnetcore/Quic/Implementations/MsQuic/MsQuicStream.cs b/src/libraries/Common/src/System/Net/Http/aspnetcore/Quic/Implementations/MsQuic/MsQuicStream.cs index fc451a7..be0e4a8 100644 --- a/src/libraries/Common/src/System/Net/Http/aspnetcore/Quic/Implementations/MsQuic/MsQuicStream.cs +++ b/src/libraries/Common/src/System/Net/Http/aspnetcore/Quic/Implementations/MsQuic/MsQuicStream.cs @@ -398,7 +398,7 @@ namespace System.Net.Quic.Implementations.MsQuic { ThrowIfDisposed(); - return default!; + return Task.CompletedTask; } public override ValueTask DisposeAsync() diff --git a/src/libraries/Common/src/System/Threading/Tasks/RendezvousAwaitable.cs b/src/libraries/Common/src/System/Threading/Tasks/RendezvousAwaitable.cs index 3b4fd9a..b6d1b46 100644 --- a/src/libraries/Common/src/System/Threading/Tasks/RendezvousAwaitable.cs +++ b/src/libraries/Common/src/System/Threading/Tasks/RendezvousAwaitable.cs @@ -24,7 +24,7 @@ namespace System.Threading.Tasks /// The exception representing the failed async operation, if it failed. private ExceptionDispatchInfo? _error; /// The result of the async operation, if it succeeded. - [AllowNull] private TResult _result = default; + private TResult? _result; #if DEBUG private bool _resultSet; #endif @@ -64,7 +64,7 @@ namespace System.Threading.Tasks } // The operation completed successfully. Clear and return the result. - TResult result = _result; + TResult result = _result!; _result = default(TResult); #if DEBUG _resultSet = false; diff --git a/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/ref/Microsoft.Extensions.DependencyInjection.Abstractions.cs b/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/ref/Microsoft.Extensions.DependencyInjection.Abstractions.cs index 5f91373..dffd433 100644 --- a/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/ref/Microsoft.Extensions.DependencyInjection.Abstractions.cs +++ b/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/ref/Microsoft.Extensions.DependencyInjection.Abstractions.cs @@ -111,8 +111,7 @@ namespace Microsoft.Extensions.DependencyInjection public static T GetRequiredService(this System.IServiceProvider provider) where T : notnull { throw null; } public static System.Collections.Generic.IEnumerable GetServices(this System.IServiceProvider provider, System.Type serviceType) { throw null; } public static System.Collections.Generic.IEnumerable GetServices(this System.IServiceProvider provider) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T GetService(this System.IServiceProvider provider) { throw null; } + public static T? GetService(this System.IServiceProvider provider) { throw null; } } } namespace Microsoft.Extensions.DependencyInjection.Extensions diff --git a/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ServiceProviderServiceExtensions.cs b/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ServiceProviderServiceExtensions.cs index e35fc65..29fcd6c 100644 --- a/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ServiceProviderServiceExtensions.cs +++ b/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ServiceProviderServiceExtensions.cs @@ -18,15 +18,14 @@ namespace Microsoft.Extensions.DependencyInjection /// The type of service object to get. /// The to retrieve the service object from. /// A service object of type or null if there is no such service. - [return: MaybeNull] - public static T GetService(this IServiceProvider provider) + public static T? GetService(this IServiceProvider provider) { if (provider == null) { throw new ArgumentNullException(nameof(provider)); } - return (T)provider.GetService(typeof(T)); + return (T?)provider.GetService(typeof(T)); } /// diff --git a/src/libraries/Microsoft.VisualBasic.Core/ref/Microsoft.VisualBasic.Core.cs b/src/libraries/Microsoft.VisualBasic.Core/ref/Microsoft.VisualBasic.Core.cs index 7b0bfbc..db97852 100644 --- a/src/libraries/Microsoft.VisualBasic.Core/ref/Microsoft.VisualBasic.Core.cs +++ b/src/libraries/Microsoft.VisualBasic.Core/ref/Microsoft.VisualBasic.Core.cs @@ -771,9 +771,8 @@ namespace Microsoft.VisualBasic.CompilerServices public static decimal ToDecimal(string? Value) { throw null; } public static double ToDouble(object? Value) { throw null; } public static double ToDouble(string? Value) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("Value")] - public static T ToGenericParameter(object? Value) { throw null; } + public static T? ToGenericParameter(object? Value) { throw null; } public static int ToInteger(object? Value) { throw null; } public static int ToInteger(string? Value) { throw null; } public static long ToLong(object? Value) { throw null; } diff --git a/src/libraries/System.Collections.Concurrent/ref/System.Collections.Concurrent.cs b/src/libraries/System.Collections.Concurrent/ref/System.Collections.Concurrent.cs index cef519b..c1a477b 100644 --- a/src/libraries/System.Collections.Concurrent/ref/System.Collections.Concurrent.cs +++ b/src/libraries/System.Collections.Concurrent/ref/System.Collections.Concurrent.cs @@ -33,8 +33,8 @@ namespace System.Collections.Concurrent System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } public T Take() { throw null; } public T Take(System.Threading.CancellationToken cancellationToken) { throw null; } - public static int TakeFromAny(System.Collections.Concurrent.BlockingCollection[] collections, [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] out T item) { throw null; } - public static int TakeFromAny(System.Collections.Concurrent.BlockingCollection[] collections, [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] out T item, System.Threading.CancellationToken cancellationToken) { throw null; } + public static int TakeFromAny(System.Collections.Concurrent.BlockingCollection[] collections, out T? item) { throw null; } + public static int TakeFromAny(System.Collections.Concurrent.BlockingCollection[] collections, out T? item, System.Threading.CancellationToken cancellationToken) { throw null; } public T[] ToArray() { throw null; } public bool TryAdd(T item) { throw null; } public bool TryAdd(T item, int millisecondsTimeout) { throw null; } @@ -48,10 +48,10 @@ namespace System.Collections.Concurrent public bool TryTake([System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out T item, int millisecondsTimeout) { throw null; } public bool TryTake([System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out T item, int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) { throw null; } public bool TryTake([System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out T item, System.TimeSpan timeout) { throw null; } - public static int TryTakeFromAny(System.Collections.Concurrent.BlockingCollection[] collections, [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] out T item) { throw null; } - public static int TryTakeFromAny(System.Collections.Concurrent.BlockingCollection[] collections, [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] out T item, int millisecondsTimeout) { throw null; } - public static int TryTakeFromAny(System.Collections.Concurrent.BlockingCollection[] collections, [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] out T item, int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) { throw null; } - public static int TryTakeFromAny(System.Collections.Concurrent.BlockingCollection[] collections, [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] out T item, System.TimeSpan timeout) { throw null; } + public static int TryTakeFromAny(System.Collections.Concurrent.BlockingCollection[] collections, out T? item) { throw null; } + public static int TryTakeFromAny(System.Collections.Concurrent.BlockingCollection[] collections, out T? item, int millisecondsTimeout) { throw null; } + public static int TryTakeFromAny(System.Collections.Concurrent.BlockingCollection[] collections, out T? item, int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) { throw null; } + public static int TryTakeFromAny(System.Collections.Concurrent.BlockingCollection[] collections, out T? item, System.TimeSpan timeout) { throw null; } } public partial class ConcurrentBag : System.Collections.Concurrent.IProducerConsumerCollection, System.Collections.Generic.IEnumerable, System.Collections.Generic.IReadOnlyCollection, System.Collections.ICollection, System.Collections.IEnumerable { diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs index ec80b76..a7a74c6 100644 --- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs +++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs @@ -1169,7 +1169,7 @@ namespace System.Collections.Concurrent /// The count of is greater than the maximum size of /// 62 for STA and 63 for MTA. /// A call to TakeFromAny may block until an item is available to be removed. - public static int TakeFromAny(BlockingCollection[] collections, [MaybeNull] out T item) + public static int TakeFromAny(BlockingCollection[] collections, out T? item) { return TakeFromAny(collections, out item, CancellationToken.None); } @@ -1198,7 +1198,7 @@ namespace System.Collections.Concurrent /// The count of is greater than the maximum size of /// 62 for STA and 63 for MTA. /// A call to TakeFromAny may block until an item is available to be removed. - public static int TakeFromAny(BlockingCollection[] collections, [MaybeNull] out T item, CancellationToken cancellationToken) + public static int TakeFromAny(BlockingCollection[] collections, out T? item, CancellationToken cancellationToken) { int returnValue = TryTakeFromAnyCore(collections, out item, Timeout.Infinite, true, cancellationToken); Debug.Assert(returnValue >= 0 && returnValue < collections.Length, @@ -1226,7 +1226,7 @@ namespace System.Collections.Concurrent /// The count of is greater than the maximum size of /// 62 for STA and 63 for MTA. /// A call to TryTakeFromAny may block until an item is available to be removed. - public static int TryTakeFromAny(BlockingCollection[] collections, [MaybeNull] out T item) + public static int TryTakeFromAny(BlockingCollection[] collections, out T? item) { return TryTakeFromAny(collections, out item, 0); } @@ -1257,7 +1257,7 @@ namespace System.Collections.Concurrent /// The count of is greater than the maximum size of /// 62 for STA and 63 for MTA. /// A call to TryTakeFromAny may block until an item is available to be removed. - public static int TryTakeFromAny(BlockingCollection[] collections, [MaybeNull] out T item, TimeSpan timeout) + public static int TryTakeFromAny(BlockingCollection[] collections, out T? item, TimeSpan timeout) { ValidateTimeout(timeout); return TryTakeFromAnyCore(collections, out item, (int)timeout.TotalMilliseconds, false, CancellationToken.None); @@ -1287,7 +1287,7 @@ namespace System.Collections.Concurrent /// The count of is greater than the maximum size of /// 62 for STA and 63 for MTA. /// A call to TryTakeFromAny may block until an item is available to be removed. - public static int TryTakeFromAny(BlockingCollection[] collections, [MaybeNull] out T item, int millisecondsTimeout) + public static int TryTakeFromAny(BlockingCollection[] collections, out T? item, int millisecondsTimeout) { ValidateMillisecondsTimeout(millisecondsTimeout); return TryTakeFromAnyCore(collections, out item, millisecondsTimeout, false, CancellationToken.None); @@ -1321,7 +1321,7 @@ namespace System.Collections.Concurrent /// The count of is greater than the maximum size of /// 62 for STA and 63 for MTA. /// A call to TryTakeFromAny may block until an item is available to be removed. - public static int TryTakeFromAny(BlockingCollection[] collections, [MaybeNull] out T item, int millisecondsTimeout, CancellationToken cancellationToken) + public static int TryTakeFromAny(BlockingCollection[] collections, out T? item, int millisecondsTimeout, CancellationToken cancellationToken) { ValidateMillisecondsTimeout(millisecondsTimeout); return TryTakeFromAnyCore(collections, out item, millisecondsTimeout, false, cancellationToken); @@ -1344,7 +1344,7 @@ namespace System.Collections.Concurrent /// If the collections argument is a 0-length array or contains a /// null element. Also, if at least one of the collections has been marked complete for adds. /// If at least one of the collections has been disposed. - private static int TryTakeFromAnyCore(BlockingCollection[] collections, [MaybeNull] out T item, int millisecondsTimeout, bool isTakeOperation, CancellationToken externalCancellationToken) + private static int TryTakeFromAnyCore(BlockingCollection[] collections, out T? item, int millisecondsTimeout, bool isTakeOperation, CancellationToken externalCancellationToken) { ValidateCollectionsArray(collections, false); @@ -1378,7 +1378,7 @@ namespace System.Collections.Concurrent /// If the collections argument is a 0-length array or contains a /// null element. Also, if at least one of the collections has been marked complete for adds. /// If at least one of the collections has been disposed. - private static int TryTakeFromAnyCoreSlow(BlockingCollection[] collections, [MaybeNull] out T item, int millisecondsTimeout, bool isTakeOperation, CancellationToken externalCancellationToken) + private static int TryTakeFromAnyCoreSlow(BlockingCollection[] collections, out T? item, int millisecondsTimeout, bool isTakeOperation, CancellationToken externalCancellationToken) { const int OPERATION_FAILED = -1; diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentBag.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentBag.cs index e225354..2ac047d 100644 --- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentBag.cs +++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentBag.cs @@ -1089,7 +1089,7 @@ namespace System.Collections.Concurrent private sealed class Enumerator : IEnumerator { private readonly T[] _array; - [AllowNull] private T _current = default; + private T? _current; private int _index; public Enumerator(T[] array) @@ -1110,7 +1110,7 @@ namespace System.Collections.Concurrent return false; } - public T Current => _current; + public T Current => _current!; object? IEnumerator.Current { diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentDictionary.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentDictionary.cs index 6b06c59..affa3bf 100644 --- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentDictionary.cs +++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentDictionary.cs @@ -344,7 +344,7 @@ namespace System.Collections.Concurrent /// The variable into which the removed value, if found, is stored. /// Whether removal of the key is conditional on its value. /// The conditional value to compare against if is true - private bool TryRemoveInternal(TKey key, [MaybeNullWhen(false)] out TValue value, bool matchValue, [AllowNull] TValue oldValue) + private bool TryRemoveInternal(TKey key, [MaybeNullWhen(false)] out TValue value, bool matchValue, TValue? oldValue) { IEqualityComparer? comparer = _comparer; int hashcode = comparer is null ? key.GetHashCode() : comparer.GetHashCode(key); @@ -375,7 +375,7 @@ namespace System.Collections.Concurrent bool valuesMatch = EqualityComparer.Default.Equals(oldValue, curr._value); if (!valuesMatch) { - value = default!; + value = default; return false; } } diff --git a/src/libraries/System.Collections.Immutable/ref/System.Collections.Immutable.cs b/src/libraries/System.Collections.Immutable/ref/System.Collections.Immutable.cs index 5c77291..b24217c 100644 --- a/src/libraries/System.Collections.Immutable/ref/System.Collections.Immutable.cs +++ b/src/libraries/System.Collections.Immutable/ref/System.Collections.Immutable.cs @@ -268,8 +268,7 @@ namespace System.Collections.Immutable public static System.Collections.Immutable.ImmutableDictionary Create() where TKey : notnull { throw null; } public static System.Collections.Immutable.ImmutableDictionary Create(System.Collections.Generic.IEqualityComparer? keyComparer) where TKey : notnull { throw null; } public static System.Collections.Immutable.ImmutableDictionary Create(System.Collections.Generic.IEqualityComparer? keyComparer, System.Collections.Generic.IEqualityComparer? valueComparer) where TKey : notnull { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TValue GetValueOrDefault(this System.Collections.Immutable.IImmutableDictionary dictionary, TKey key) where TKey : notnull { throw null; } + public static TValue? GetValueOrDefault(this System.Collections.Immutable.IImmutableDictionary dictionary, TKey key) where TKey : notnull { throw null; } public static TValue GetValueOrDefault(this System.Collections.Immutable.IImmutableDictionary dictionary, TKey key, TValue defaultValue) where TKey : notnull { throw null; } public static System.Collections.Immutable.ImmutableDictionary ToImmutableDictionary(this System.Collections.Generic.IEnumerable> source) where TKey : notnull { throw null; } public static System.Collections.Immutable.ImmutableDictionary ToImmutableDictionary(this System.Collections.Generic.IEnumerable> source, System.Collections.Generic.IEqualityComparer? keyComparer) where TKey : notnull { throw null; } @@ -367,8 +366,7 @@ namespace System.Collections.Immutable public bool ContainsKey(TKey key) { throw null; } public bool ContainsValue(TValue value) { throw null; } public System.Collections.Immutable.ImmutableDictionary.Enumerator GetEnumerator() { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public TValue GetValueOrDefault(TKey key) { throw null; } + public TValue? GetValueOrDefault(TKey key) { throw null; } public TValue GetValueOrDefault(TKey key, TValue defaultValue) { throw null; } public bool Remove(System.Collections.Generic.KeyValuePair item) { throw null; } public bool Remove(TKey key) { throw null; } @@ -572,14 +570,12 @@ namespace System.Collections.Immutable public void CopyTo(T[] array) { } public void CopyTo(T[] array, int arrayIndex) { } public bool Exists(System.Predicate match) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public T Find(System.Predicate match) { throw null; } + public T? Find(System.Predicate match) { throw null; } public System.Collections.Immutable.ImmutableList FindAll(System.Predicate match) { throw null; } public int FindIndex(int startIndex, int count, System.Predicate match) { throw null; } public int FindIndex(int startIndex, System.Predicate match) { throw null; } public int FindIndex(System.Predicate match) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public T FindLast(System.Predicate match) { throw null; } + public T? FindLast(System.Predicate match) { throw null; } public int FindLastIndex(int startIndex, int count, System.Predicate match) { throw null; } public int FindLastIndex(int startIndex, System.Predicate match) { throw null; } public int FindLastIndex(System.Predicate match) { throw null; } @@ -662,14 +658,12 @@ namespace System.Collections.Immutable public void CopyTo(T[] array) { } public void CopyTo(T[] array, int arrayIndex) { } public bool Exists(System.Predicate match) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public T Find(System.Predicate match) { throw null; } + public T? Find(System.Predicate match) { throw null; } public System.Collections.Immutable.ImmutableList FindAll(System.Predicate match) { throw null; } public int FindIndex(int startIndex, int count, System.Predicate match) { throw null; } public int FindIndex(int startIndex, System.Predicate match) { throw null; } public int FindIndex(System.Predicate match) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public T FindLast(System.Predicate match) { throw null; } + public T? FindLast(System.Predicate match) { throw null; } public int FindLastIndex(int startIndex, int count, System.Predicate match) { throw null; } public int FindLastIndex(int startIndex, System.Predicate match) { throw null; } public int FindLastIndex(System.Predicate match) { throw null; } @@ -866,8 +860,7 @@ namespace System.Collections.Immutable public bool ContainsKey(TKey key) { throw null; } public bool ContainsValue(TValue value) { throw null; } public System.Collections.Immutable.ImmutableSortedDictionary.Enumerator GetEnumerator() { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public TValue GetValueOrDefault(TKey key) { throw null; } + public TValue? GetValueOrDefault(TKey key) { throw null; } public TValue GetValueOrDefault(TKey key, TValue defaultValue) { throw null; } public bool Remove(System.Collections.Generic.KeyValuePair item) { throw null; } public bool Remove(TKey key) { throw null; } @@ -928,10 +921,8 @@ namespace System.Collections.Immutable public bool IsEmpty { get { throw null; } } public T this[int index] { get { throw null; } } public System.Collections.Generic.IComparer KeyComparer { get { throw null; } } - [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public T Max { get { throw null; } } - [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public T Min { get { throw null; } } + public T? Max { get { throw null; } } + public T? Min { get { throw null; } } bool System.Collections.Generic.ICollection.IsReadOnly { get { throw null; } } T System.Collections.Generic.IList.this[int index] { get { throw null; } set { } } bool System.Collections.ICollection.IsSynchronized { get { throw null; } } @@ -996,10 +987,8 @@ namespace System.Collections.Immutable public int Count { get { throw null; } } public T this[int index] { get { throw null; } } public System.Collections.Generic.IComparer KeyComparer { get { throw null; } set { } } - [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public T Max { get { throw null; } } - [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public T Min { get { throw null; } } + public T? Max { get { throw null; } } + public T? Min { get { throw null; } } bool System.Collections.Generic.ICollection.IsReadOnly { get { throw null; } } bool System.Collections.ICollection.IsSynchronized { get { throw null; } } object System.Collections.ICollection.SyncRoot { get { throw null; } } @@ -1083,32 +1072,24 @@ namespace System.Linq { public static partial class ImmutableArrayExtensions { - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T Aggregate(this System.Collections.Immutable.ImmutableArray immutableArray, System.Func func) { throw null; } + public static T? Aggregate(this System.Collections.Immutable.ImmutableArray immutableArray, System.Func func) { throw null; } public static TAccumulate Aggregate(this System.Collections.Immutable.ImmutableArray immutableArray, TAccumulate seed, System.Func func) { throw null; } public static TResult Aggregate(this System.Collections.Immutable.ImmutableArray immutableArray, TAccumulate seed, System.Func func, System.Func resultSelector) { throw null; } public static bool All(this System.Collections.Immutable.ImmutableArray immutableArray, System.Func predicate) { throw null; } public static bool Any(this System.Collections.Immutable.ImmutableArray immutableArray) { throw null; } public static bool Any(this System.Collections.Immutable.ImmutableArray immutableArray, System.Func predicate) { throw null; } public static bool Any(this System.Collections.Immutable.ImmutableArray.Builder builder) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T ElementAtOrDefault(this System.Collections.Immutable.ImmutableArray immutableArray, int index) { throw null; } + public static T? ElementAtOrDefault(this System.Collections.Immutable.ImmutableArray immutableArray, int index) { throw null; } public static T ElementAt(this System.Collections.Immutable.ImmutableArray immutableArray, int index) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T FirstOrDefault(this System.Collections.Immutable.ImmutableArray immutableArray) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T FirstOrDefault(this System.Collections.Immutable.ImmutableArray immutableArray, System.Func predicate) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T FirstOrDefault(this System.Collections.Immutable.ImmutableArray.Builder builder) { throw null; } + public static T? FirstOrDefault(this System.Collections.Immutable.ImmutableArray immutableArray) { throw null; } + public static T? FirstOrDefault(this System.Collections.Immutable.ImmutableArray immutableArray, System.Func predicate) { throw null; } + public static T? FirstOrDefault(this System.Collections.Immutable.ImmutableArray.Builder builder) { throw null; } public static T First(this System.Collections.Immutable.ImmutableArray immutableArray) { throw null; } public static T First(this System.Collections.Immutable.ImmutableArray immutableArray, System.Func predicate) { throw null; } public static T First(this System.Collections.Immutable.ImmutableArray.Builder builder) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T LastOrDefault(this System.Collections.Immutable.ImmutableArray immutableArray) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T LastOrDefault(this System.Collections.Immutable.ImmutableArray immutableArray, System.Func predicate) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T LastOrDefault(this System.Collections.Immutable.ImmutableArray.Builder builder) { throw null; } + public static T? LastOrDefault(this System.Collections.Immutable.ImmutableArray immutableArray) { throw null; } + public static T? LastOrDefault(this System.Collections.Immutable.ImmutableArray immutableArray, System.Func predicate) { throw null; } + public static T? LastOrDefault(this System.Collections.Immutable.ImmutableArray.Builder builder) { throw null; } public static T Last(this System.Collections.Immutable.ImmutableArray immutableArray) { throw null; } public static T Last(this System.Collections.Immutable.ImmutableArray immutableArray, System.Func predicate) { throw null; } public static T Last(this System.Collections.Immutable.ImmutableArray.Builder builder) { throw null; } @@ -1117,10 +1098,8 @@ namespace System.Linq public static bool SequenceEqual(this System.Collections.Immutable.ImmutableArray immutableArray, System.Collections.Generic.IEnumerable items, System.Collections.Generic.IEqualityComparer? comparer = null) where TDerived : TBase { throw null; } public static bool SequenceEqual(this System.Collections.Immutable.ImmutableArray immutableArray, System.Collections.Immutable.ImmutableArray items, System.Collections.Generic.IEqualityComparer? comparer = null) where TDerived : TBase { throw null; } public static bool SequenceEqual(this System.Collections.Immutable.ImmutableArray immutableArray, System.Collections.Immutable.ImmutableArray items, System.Func predicate) where TDerived : TBase { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T SingleOrDefault(this System.Collections.Immutable.ImmutableArray immutableArray) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T SingleOrDefault(this System.Collections.Immutable.ImmutableArray immutableArray, System.Func predicate) { throw null; } + public static T? SingleOrDefault(this System.Collections.Immutable.ImmutableArray immutableArray) { throw null; } + public static T? SingleOrDefault(this System.Collections.Immutable.ImmutableArray immutableArray, System.Func predicate) { throw null; } public static T Single(this System.Collections.Immutable.ImmutableArray immutableArray) { throw null; } public static T Single(this System.Collections.Immutable.ImmutableArray immutableArray, System.Func predicate) { throw null; } public static T[] ToArray(this System.Collections.Immutable.ImmutableArray immutableArray) { throw null; } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/AllocFreeConcurrentStack.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/AllocFreeConcurrentStack.cs index 3188fce..e441355 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/AllocFreeConcurrentStack.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/AllocFreeConcurrentStack.cs @@ -31,7 +31,7 @@ namespace System.Collections.Immutable return true; } - item = default(T)!; + item = default; return false; } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/IImmutableListQueries.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/IImmutableListQueries.cs index d5decd8..cb19d18 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/IImmutableListQueries.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/IImmutableListQueries.cs @@ -120,8 +120,7 @@ namespace System.Collections.Immutable /// The first element that matches the conditions defined by the specified predicate, /// if found; otherwise, the default value for type . /// - [return: MaybeNull] - T Find(Predicate match); + T? Find(Predicate match); /// /// Retrieves all the elements that match the conditions defined by the specified @@ -194,8 +193,7 @@ namespace System.Collections.Immutable /// The last element that matches the conditions defined by the specified predicate, /// if found; otherwise, the default value for type . /// - [return: MaybeNull] - T FindLast(Predicate match); + T? FindLast(Predicate match); /// /// Searches for an element that matches the conditions defined by the specified diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary.cs index 80d99d4..53e6a03 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary.cs @@ -290,8 +290,7 @@ namespace System.Collections.Immutable /// The dictionary to retrieve the value from. /// The key to search for. /// The value for the key, or the default value of type if no matching key was found. - [return: MaybeNull] - public static TValue GetValueOrDefault(this IImmutableDictionary dictionary, TKey key) where TKey : notnull + public static TValue? GetValueOrDefault(this IImmutableDictionary dictionary, TKey key) where TKey : notnull { return GetValueOrDefault(dictionary, key, default(TValue)!); } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.Builder.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.Builder.cs index a3c7662..eb94a5b 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.Builder.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.Builder.cs @@ -466,8 +466,7 @@ namespace System.Collections.Immutable /// /// The key to search for. /// The value for the key, or the default value of type if no matching key was found. - [return: MaybeNull] - public TValue GetValueOrDefault(TKey key) + public TValue? GetValueOrDefault(TKey key) { return this.GetValueOrDefault(key, default(TValue)!); } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.HashBucket.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.HashBucket.cs index 0f8e7ce..77e65ec 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.HashBucket.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.HashBucket.cs @@ -263,7 +263,7 @@ namespace System.Collections.Immutable { if (this.IsEmpty) { - value = default(TValue)!; + value = default; return false; } @@ -277,7 +277,7 @@ namespace System.Collections.Immutable var index = _additionalElements.IndexOf(kv, comparers.KeyOnlyComparer); if (index < 0) { - value = default(TValue)!; + value = default; return false; } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.cs index 504d120..346fdc1 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.cs @@ -912,7 +912,7 @@ namespace System.Collections.Immutable return bucket.TryGetValue(key, origin.Comparers, out value!); } - value = default(TValue)!; + value = default; return false; } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableInterlocked.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableInterlocked.cs index f907de4..5f99c06 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableInterlocked.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableInterlocked.cs @@ -525,7 +525,7 @@ namespace System.Collections.Immutable if (priorCollection.IsEmpty) { - value = default(T)!; + value = default; return false; } @@ -580,7 +580,7 @@ namespace System.Collections.Immutable if (priorCollection.IsEmpty) { - value = default(T)!; + value = default; return false; } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.Builder.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.Builder.cs index 7d5577d..ee6b888 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.Builder.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.Builder.cs @@ -395,8 +395,7 @@ namespace System.Collections.Immutable /// The first element that matches the conditions defined by the specified predicate, /// if found; otherwise, the default value for type T. /// - [return: MaybeNull] - public T Find(Predicate match) => _root.Find(match); + public T? Find(Predicate match) => _root.Find(match); /// /// Retrieves all the elements that match the conditions defined by the specified @@ -469,8 +468,7 @@ namespace System.Collections.Immutable /// The last element that matches the conditions defined by the specified predicate, /// if found; otherwise, the default value for type T. /// - [return: MaybeNull] - public T FindLast(Predicate match) => _root.FindLast(match); + public T? FindLast(Predicate match) => _root.FindLast(match); /// /// Searches for an element that matches the conditions defined by the specified diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.Node.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.Node.cs index 9c30a67..ef03813 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.Node.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.Node.cs @@ -998,8 +998,7 @@ namespace System.Collections.Immutable /// The first element that matches the conditions defined by the specified predicate, /// if found; otherwise, the default value for type . /// - [return: MaybeNull] - internal T Find(Predicate match) + internal T? Find(Predicate match) { Requires.NotNull(match, nameof(match)); @@ -1011,7 +1010,7 @@ namespace System.Collections.Immutable } } - return default(T)!; + return default; } /// @@ -1144,8 +1143,7 @@ namespace System.Collections.Immutable /// The last element that matches the conditions defined by the specified predicate, /// if found; otherwise, the default value for type . /// - [return: MaybeNull] - internal T FindLast(Predicate match) + internal T? FindLast(Predicate match) { Requires.NotNull(match, nameof(match)); @@ -1160,7 +1158,7 @@ namespace System.Collections.Immutable } } - return default(T)!; + return default; } /// diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.cs index e252d3c..9597b0a 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.cs @@ -593,8 +593,7 @@ namespace System.Collections.Immutable /// The first element that matches the conditions defined by the specified predicate, /// if found; otherwise, the default value for type . /// - [return: MaybeNull] - public T Find(Predicate match) => _root.Find(match); + public T? Find(Predicate match) => _root.Find(match); /// /// Retrieves all the elements that match the conditions defined by the specified @@ -667,8 +666,7 @@ namespace System.Collections.Immutable /// The last element that matches the conditions defined by the specified predicate, /// if found; otherwise, the default value for type . /// - [return: MaybeNull] - public T FindLast(Predicate match) => _root.FindLast(match); + public T? FindLast(Predicate match) => _root.FindLast(match); /// /// Searches for an element that matches the conditions defined by the specified diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary_2.Builder.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary_2.Builder.cs index 47da5f0..2f8fafe 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary_2.Builder.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary_2.Builder.cs @@ -603,8 +603,7 @@ namespace System.Collections.Immutable /// /// The key to search for. /// The value for the key, or the default value for type if no matching key was found. - [return: MaybeNull] - public TValue GetValueOrDefault(TKey key) + public TValue? GetValueOrDefault(TKey key) { return this.GetValueOrDefault(key, default(TValue)!); } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary_2.Node.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary_2.Node.cs index 353fb92..99173a5 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary_2.Node.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary_2.Node.cs @@ -362,7 +362,7 @@ namespace System.Collections.Immutable var match = this.Search(key, keyComparer); if (match.IsEmpty) { - value = default(TValue)!; + value = default; return false; } else diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.Builder.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.Builder.cs index 3516981..2a1c606 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.Builder.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.Builder.cs @@ -123,8 +123,7 @@ namespace System.Collections.Immutable /// Gets the maximum value in the collection, as defined by the comparer. /// /// The maximum value in the set. - [MaybeNull] - public T Max + public T? Max { get { return _root.Max; } } @@ -133,8 +132,7 @@ namespace System.Collections.Immutable /// Gets the minimum value in the collection, as defined by the comparer. /// /// The minimum value in the set. - [MaybeNull] - public T Min + public T? Min { get { return _root.Min; } } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.Node.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.Node.cs index 9ff2099..89b044c 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.Node.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.Node.cs @@ -184,14 +184,13 @@ namespace System.Collections.Immutable /// Gets the maximum value in the collection, as defined by the comparer. /// /// The maximum value in the set. - [MaybeNull] - internal T Max + internal T? Max { get { if (this.IsEmpty) { - return default(T)!; + return default; } Node n = this; @@ -208,14 +207,13 @@ namespace System.Collections.Immutable /// Gets the minimum value in the collection, as defined by the comparer. /// /// The minimum value in the set. - [MaybeNull] - internal T Min + internal T? Min { get { if (this.IsEmpty) { - return default(T)!; + return default; } Node n = this; diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.cs index c6b8a28..b74674d 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.cs @@ -84,8 +84,7 @@ namespace System.Collections.Immutable /// Gets the maximum value in the collection, as defined by the comparer. /// /// The maximum value in the set. - [MaybeNull] - public T Max + public T? Max { get { return _root.Max; } } @@ -94,8 +93,7 @@ namespace System.Collections.Immutable /// Gets the minimum value in the collection, as defined by the comparer. /// /// The minimum value in the set. - [MaybeNull] - public T Min + public T? Min { get { return _root.Min; } } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableStack_1.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableStack_1.cs index 15b5fbd..f8b70a0a 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableStack_1.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableStack_1.cs @@ -27,8 +27,7 @@ namespace System.Collections.Immutable /// /// The element on the top of the stack. /// - [MaybeNull] - private readonly T _head = default!; + private readonly T? _head; /// /// A stack that contains the rest of the elements (under the top element). diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/SecureObjectPool.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/SecureObjectPool.cs index 8d3664f..6d194da 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/SecureObjectPool.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/SecureObjectPool.cs @@ -124,7 +124,7 @@ namespace System.Collections.Immutable } else { - value = default(T)!; + value = default; return false; } } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/SortedInt32KeyNode.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/SortedInt32KeyNode.cs index 96ba562..25cc063 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/SortedInt32KeyNode.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/SortedInt32KeyNode.cs @@ -34,8 +34,7 @@ namespace System.Collections.Immutable /// /// The value associated with this node. /// - [MaybeNull] - private readonly TValue _value = default!; + private readonly TValue? _value; /// /// A value indicating whether this node has been frozen (made immutable). @@ -197,15 +196,14 @@ namespace System.Collections.Immutable /// /// The key. /// The value. - [return: MaybeNull] - internal TValue GetValueOrDefault(int key) + internal TValue? GetValueOrDefault(int key) { SortedInt32KeyNode node = this; while (true) { if (node.IsEmpty) { - return default(TValue)!; + return default; } if (key == node._key) @@ -237,7 +235,7 @@ namespace System.Collections.Immutable { if (node.IsEmpty) { - value = default(TValue)!; + value = default; return false; } diff --git a/src/libraries/System.Collections.Immutable/src/System/Linq/ImmutableArrayExtensions.cs b/src/libraries/System.Collections.Immutable/src/System/Linq/ImmutableArrayExtensions.cs index 13109d4..2850cc5 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Linq/ImmutableArrayExtensions.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Linq/ImmutableArrayExtensions.cs @@ -253,14 +253,13 @@ namespace System.Linq /// Applies an accumulator function over a sequence. /// /// The type of element contained by the collection. - [return: MaybeNull] - public static T Aggregate(this ImmutableArray immutableArray, Func func) + public static T? Aggregate(this ImmutableArray immutableArray, Func func) { Requires.NotNull(func, nameof(func)); if (immutableArray.Length == 0) { - return default(T)!; + return default; } var result = immutableArray[0]; @@ -316,12 +315,11 @@ namespace System.Linq /// Returns the element at a specified index in a sequence or a default value if the index is out of range. /// /// The type of element contained by the collection. - [return: MaybeNull] - public static T ElementAtOrDefault(this ImmutableArray immutableArray, int index) + public static T? ElementAtOrDefault(this ImmutableArray immutableArray, int index) { if (index < 0 || index >= immutableArray.Length) { - return default(T)!; + return default; } return immutableArray[index]; @@ -367,18 +365,16 @@ namespace System.Linq /// /// The type of element contained by the collection. /// - [return: MaybeNull] - public static T FirstOrDefault(this ImmutableArray immutableArray) + public static T? FirstOrDefault(this ImmutableArray immutableArray) { - return immutableArray.array!.Length > 0 ? immutableArray.array[0] : default(T)!; + return immutableArray.array!.Length > 0 ? immutableArray.array[0] : default; } /// /// Returns the first element of the sequence that satisfies a condition or a default value if no such element is found. /// /// The type of element contained by the collection. - [return: MaybeNull] - public static T FirstOrDefault(this ImmutableArray immutableArray, Func predicate) + public static T? FirstOrDefault(this ImmutableArray immutableArray, Func predicate) { Requires.NotNull(predicate, nameof(predicate)); @@ -390,7 +386,7 @@ namespace System.Linq } } - return default(T)!; + return default; } /// @@ -432,8 +428,7 @@ namespace System.Linq /// /// The type of element contained by the collection. /// - [return: MaybeNull] - public static T LastOrDefault(this ImmutableArray immutableArray) + public static T? LastOrDefault(this ImmutableArray immutableArray) { immutableArray.ThrowNullRefIfNotInitialized(); return immutableArray.array!.LastOrDefault()!; @@ -443,8 +438,7 @@ namespace System.Linq /// Returns the last element of a sequence that satisfies a condition or a default value if no such element is found. /// /// The type of element contained by the collection. - [return: MaybeNull] - public static T LastOrDefault(this ImmutableArray immutableArray, Func predicate) + public static T? LastOrDefault(this ImmutableArray immutableArray, Func predicate) { Requires.NotNull(predicate, nameof(predicate)); @@ -456,7 +450,7 @@ namespace System.Linq } } - return default(T)!; + return default; } /// @@ -478,8 +472,8 @@ namespace System.Linq { Requires.NotNull(predicate, nameof(predicate)); - var first = true; - var result = default(T)!; + bool first = true; + T? result = default; foreach (var v in immutableArray.array!) { if (predicate(v)) @@ -499,7 +493,7 @@ namespace System.Linq Enumerable.Empty().Single(); // throw the same exception as LINQ would } - return result; + return result!; } /// @@ -507,8 +501,7 @@ namespace System.Linq /// /// The type of element contained by the collection. /// - [return: MaybeNull] - public static T SingleOrDefault(this ImmutableArray immutableArray) + public static T? SingleOrDefault(this ImmutableArray immutableArray) { immutableArray.ThrowNullRefIfNotInitialized(); return immutableArray.array!.SingleOrDefault()!; @@ -518,13 +511,12 @@ namespace System.Linq /// Returns the only element of a sequence that satisfies a specified condition or a default value if no such element exists; this method throws an exception if more than one element satisfies the condition. /// /// The type of element contained by the collection. - [return: MaybeNull] - public static T SingleOrDefault(this ImmutableArray immutableArray, Func predicate) + public static T? SingleOrDefault(this ImmutableArray immutableArray, Func predicate) { Requires.NotNull(predicate, nameof(predicate)); - var first = true; - var result = default(T)!; + bool first = true; + T? result = default; foreach (var v in immutableArray.array!) { if (predicate(v)) @@ -657,12 +649,11 @@ namespace System.Linq /// /// Returns the first element in the collection, or the default value if the collection is empty. /// - [return: MaybeNull] - public static T FirstOrDefault(this ImmutableArray.Builder builder) + public static T? FirstOrDefault(this ImmutableArray.Builder builder) { Requires.NotNull(builder, nameof(builder)); - return builder.Any() ? builder[0] : default(T)!; + return builder.Any() ? builder[0] : default; } /// @@ -684,12 +675,11 @@ namespace System.Linq /// /// Returns the last element in the collection, or the default value if the collection is empty. /// - [return: MaybeNull] - public static T LastOrDefault(this ImmutableArray.Builder builder) + public static T? LastOrDefault(this ImmutableArray.Builder builder) { Requires.NotNull(builder, nameof(builder)); - return builder.Any() ? builder[builder.Count - 1] : default(T)!; + return builder.Any() ? builder[builder.Count - 1] : default; } /// diff --git a/src/libraries/System.Collections/ref/System.Collections.cs b/src/libraries/System.Collections/ref/System.Collections.cs index b0505e8..334a67a 100644 --- a/src/libraries/System.Collections/ref/System.Collections.cs +++ b/src/libraries/System.Collections/ref/System.Collections.cs @@ -43,8 +43,7 @@ namespace System.Collections.Generic { public static partial class CollectionExtensions { - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TValue GetValueOrDefault(this System.Collections.Generic.IReadOnlyDictionary dictionary, TKey key) { throw null; } + public static TValue? GetValueOrDefault(this System.Collections.Generic.IReadOnlyDictionary dictionary, TKey key) { throw null; } public static TValue GetValueOrDefault(this System.Collections.Generic.IReadOnlyDictionary dictionary, TKey key, TValue defaultValue) { throw null; } public static bool Remove(this System.Collections.Generic.IDictionary dictionary, TKey key, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TValue value) { throw null; } public static bool TryAdd(this System.Collections.Generic.IDictionary dictionary, TKey key, TValue value) { throw null; } @@ -53,7 +52,7 @@ namespace System.Collections.Generic { protected Comparer() { } public static System.Collections.Generic.Comparer Default { get { throw null; } } - public abstract int Compare([System.Diagnostics.CodeAnalysis.AllowNullAttribute] T x, [System.Diagnostics.CodeAnalysis.AllowNullAttribute] T y); + public abstract int Compare(T? x, T? y); public static System.Collections.Generic.Comparer Create(System.Comparison comparison) { throw null; } int System.Collections.IComparer.Compare(object? x, object? y) { throw null; } } @@ -184,7 +183,7 @@ namespace System.Collections.Generic { protected EqualityComparer() { } public static System.Collections.Generic.EqualityComparer Default { get { throw null; } } - public abstract bool Equals([System.Diagnostics.CodeAnalysis.AllowNullAttribute] T x, [System.Diagnostics.CodeAnalysis.AllowNullAttribute] T y); + public abstract bool Equals(T? x, T? y); public abstract int GetHashCode([System.Diagnostics.CodeAnalysis.DisallowNullAttribute] T obj); bool System.Collections.IEqualityComparer.Equals(object? x, object? y) { throw null; } int System.Collections.IEqualityComparer.GetHashCode(object obj) { throw null; } @@ -326,14 +325,12 @@ namespace System.Collections.Generic public void CopyTo(T[] array) { } public void CopyTo(T[] array, int arrayIndex) { } public bool Exists(System.Predicate match) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public T Find(System.Predicate match) { throw null; } + public T? Find(System.Predicate match) { throw null; } public System.Collections.Generic.List FindAll(System.Predicate match) { throw null; } public int FindIndex(int startIndex, int count, System.Predicate match) { throw null; } public int FindIndex(int startIndex, System.Predicate match) { throw null; } public int FindIndex(System.Predicate match) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public T FindLast(System.Predicate match) { throw null; } + public T? FindLast(System.Predicate match) { throw null; } public int FindLastIndex(int startIndex, int count, System.Predicate match) { throw null; } public int FindLastIndex(int startIndex, System.Predicate match) { throw null; } public int FindLastIndex(System.Predicate match) { throw null; } @@ -589,10 +586,8 @@ namespace System.Collections.Generic protected SortedSet(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } public System.Collections.Generic.IComparer Comparer { get { throw null; } } public int Count { get { throw null; } } - [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public T Max { get { throw null; } } - [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public T Min { get { throw null; } } + public T? Max { get { throw null; } } + public T? Min { get { throw null; } } bool System.Collections.Generic.ICollection.IsReadOnly { get { throw null; } } bool System.Collections.ICollection.IsSynchronized { get { throw null; } } object System.Collections.ICollection.SyncRoot { get { throw null; } } @@ -607,7 +602,7 @@ namespace System.Collections.Generic public void ExceptWith(System.Collections.Generic.IEnumerable other) { } public System.Collections.Generic.SortedSet.Enumerator GetEnumerator() { throw null; } protected virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } - public virtual System.Collections.Generic.SortedSet GetViewBetween(T lowerValue, T upperValue) { throw null; } + public virtual System.Collections.Generic.SortedSet GetViewBetween(T? lowerValue, T? upperValue) { throw null; } public virtual void IntersectWith(System.Collections.Generic.IEnumerable other) { } public bool IsProperSubsetOf(System.Collections.Generic.IEnumerable other) { throw null; } public bool IsProperSupersetOf(System.Collections.Generic.IEnumerable other) { throw null; } diff --git a/src/libraries/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs b/src/libraries/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs index 47de3ec..39158f2 100644 --- a/src/libraries/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs +++ b/src/libraries/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs @@ -7,8 +7,7 @@ namespace System.Collections.Generic { public static class CollectionExtensions { - [return: MaybeNull] - public static TValue GetValueOrDefault(this IReadOnlyDictionary dictionary, TKey key) + public static TValue? GetValueOrDefault(this IReadOnlyDictionary dictionary, TKey key) { return dictionary.GetValueOrDefault(key, default!); } @@ -53,7 +52,7 @@ namespace System.Collections.Generic return true; } - value = default(TValue)!; + value = default; return false; } } diff --git a/src/libraries/System.Collections/src/System/Collections/Generic/LinkedList.cs b/src/libraries/System.Collections/src/System/Collections/Generic/LinkedList.cs index 1694a7c..cd27186 100644 --- a/src/libraries/System.Collections/src/System/Collections/Generic/LinkedList.cs +++ b/src/libraries/System.Collections/src/System/Collections/Generic/LinkedList.cs @@ -530,7 +530,7 @@ namespace System.Collections.Generic private readonly LinkedList _list; private LinkedListNode? _node; private readonly int _version; - [AllowNull] private T _current; + private T? _current; private int _index; internal Enumerator(LinkedList list) @@ -542,10 +542,7 @@ namespace System.Collections.Generic _index = 0; } - public T Current - { - get { return _current; } - } + public T Current => _current!; object? IEnumerator.Current { diff --git a/src/libraries/System.Collections/src/System/Collections/Generic/Queue.cs b/src/libraries/System.Collections/src/System/Collections/Generic/Queue.cs index efd2b1e..c468d16 100644 --- a/src/libraries/System.Collections/src/System/Collections/Generic/Queue.cs +++ b/src/libraries/System.Collections/src/System/Collections/Generic/Queue.cs @@ -395,7 +395,7 @@ namespace System.Collections.Generic private readonly Queue _q; private readonly int _version; private int _index; // -1 = not started, -2 = ended/disposed - [AllowNull] private T _currentElement; + private T? _currentElement; internal Enumerator(Queue q) { @@ -457,7 +457,7 @@ namespace System.Collections.Generic { if (_index < 0) ThrowEnumerationNotStartedOrEnded(); - return _currentElement; + return _currentElement!; } } diff --git a/src/libraries/System.Collections/src/System/Collections/Generic/SortedDictionary.cs b/src/libraries/System.Collections/src/System/Collections/Generic/SortedDictionary.cs index 8bca75b..fd649d5 100644 --- a/src/libraries/System.Collections/src/System/Collections/Generic/SortedDictionary.cs +++ b/src/libraries/System.Collections/src/System/Collections/Generic/SortedDictionary.cs @@ -288,7 +288,7 @@ namespace System.Collections.Generic TreeSet>.Node? node = _set.FindNode(new KeyValuePair(key, default(TValue)!)); if (node == null) { - value = default(TValue)!; + value = default; return false; } value = node.Item.Value; diff --git a/src/libraries/System.Collections/src/System/Collections/Generic/SortedList.cs b/src/libraries/System.Collections/src/System/Collections/Generic/SortedList.cs index 1ce3cd9..220de76 100644 --- a/src/libraries/System.Collections/src/System/Collections/Generic/SortedList.cs +++ b/src/libraries/System.Collections/src/System/Collections/Generic/SortedList.cs @@ -685,7 +685,7 @@ namespace System.Collections.Generic return true; } - value = default(TValue)!; + value = default; return false; } @@ -761,8 +761,8 @@ namespace System.Collections.Generic private struct Enumerator : IEnumerator>, IDictionaryEnumerator { private readonly SortedList _sortedList; - [AllowNull] private TKey _key; - [AllowNull] private TValue _value; + private TKey? _key; + private TValue? _value; private int _index; private readonly int _version; private readonly int _getEnumeratorRetType; // What should Enumerator.Current return? @@ -796,7 +796,7 @@ namespace System.Collections.Generic throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen); } - return _key; + return _key!; } } @@ -827,17 +827,11 @@ namespace System.Collections.Generic throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen); } - return new DictionaryEntry(_key, _value); + return new DictionaryEntry(_key!, _value); } } - public KeyValuePair Current - { - get - { - return new KeyValuePair(_key, _value); - } - } + public KeyValuePair Current => new KeyValuePair(_key!, _value!); object? IEnumerator.Current { @@ -850,11 +844,11 @@ namespace System.Collections.Generic if (_getEnumeratorRetType == DictEntry) { - return new DictionaryEntry(_key, _value); + return new DictionaryEntry(_key!, _value); } else { - return new KeyValuePair(_key, _value); + return new KeyValuePair(_key!, _value!); } } } @@ -890,7 +884,7 @@ namespace System.Collections.Generic private readonly SortedList _sortedList; private int _index; private readonly int _version; - [AllowNull] private TKey _currentKey = default!; + private TKey? _currentKey; internal SortedListKeyEnumerator(SortedList sortedList) { @@ -923,13 +917,7 @@ namespace System.Collections.Generic return false; } - public TKey Current - { - get - { - return _currentKey; - } - } + public TKey Current => _currentKey!; object? IEnumerator.Current { @@ -960,7 +948,7 @@ namespace System.Collections.Generic private readonly SortedList _sortedList; private int _index; private readonly int _version; - [AllowNull] private TValue _currentValue = default!; + private TValue? _currentValue; internal SortedListValueEnumerator(SortedList sortedList) { @@ -993,13 +981,7 @@ namespace System.Collections.Generic return false; } - public TValue Current - { - get - { - return _currentValue; - } - } + public TValue Current => _currentValue!; object? IEnumerator.Current { diff --git a/src/libraries/System.Collections/src/System/Collections/Generic/SortedSet.TreeSubSet.cs b/src/libraries/System.Collections/src/System/Collections/Generic/SortedSet.TreeSubSet.cs index eb116ac..91745e2 100644 --- a/src/libraries/System.Collections/src/System/Collections/Generic/SortedSet.TreeSubSet.cs +++ b/src/libraries/System.Collections/src/System/Collections/Generic/SortedSet.TreeSubSet.cs @@ -16,10 +16,8 @@ namespace System.Collections.Generic internal sealed class TreeSubSet : SortedSet, ISerializable, IDeserializationCallback { private readonly SortedSet _underlying; - [MaybeNull, AllowNull] - private readonly T _min; - [MaybeNull, AllowNull] - private readonly T _max; + private readonly T? _min; + private readonly T? _max; // keeps track of whether the count variable is up to date // up to date -> _countVersion = _underlying.version // not up to date -> _countVersion < _underlying.version @@ -38,7 +36,7 @@ namespace System.Collections.Generic } #endif - public TreeSubSet(SortedSet Underlying, [AllowNull] T Min, [AllowNull] T Max, bool lowerBoundActive, bool upperBoundActive) + public TreeSubSet(SortedSet Underlying, T? Min, T? Max, bool lowerBoundActive, bool upperBoundActive) : base(Underlying.Comparer) { _underlying = Underlying; @@ -129,7 +127,7 @@ namespace System.Collections.Generic get { Node? current = root; - T result = default(T)!; + T? result = default; while (current != null) { @@ -150,7 +148,7 @@ namespace System.Collections.Generic } } - return result; + return result!; } } @@ -159,7 +157,7 @@ namespace System.Collections.Generic get { Node? current = root; - T result = default(T)!; + T? result = default; while (current != null) { @@ -179,7 +177,7 @@ namespace System.Collections.Generic } } - return result; + return result!; } } @@ -340,7 +338,7 @@ namespace System.Collections.Generic // This passes functionality down to the underlying tree, clipping edges if necessary // There's nothing gained by having a nested subset. May as well draw it from the base // Cannot increase the bounds of the subset, can only decrease it - public override SortedSet GetViewBetween([AllowNull] T lowerValue, [AllowNull] T upperValue) + public override SortedSet GetViewBetween(T? lowerValue, T? upperValue) { if (_lBoundActive && Comparer.Compare(_min, lowerValue) > 0) { diff --git a/src/libraries/System.Collections/src/System/Collections/Generic/SortedSet.cs b/src/libraries/System.Collections/src/System/Collections/Generic/SortedSet.cs index 3cc375c..3d2989a 100644 --- a/src/libraries/System.Collections/src/System/Collections/Generic/SortedSet.cs +++ b/src/libraries/System.Collections/src/System/Collections/Generic/SortedSet.cs @@ -755,9 +755,9 @@ namespace System.Collections.Generic return -1; } - internal Node? FindRange([AllowNull] T from, [AllowNull] T to) => FindRange(from, to, lowerBoundActive: true, upperBoundActive: true); + internal Node? FindRange(T? from, T? to) => FindRange(from, to, lowerBoundActive: true, upperBoundActive: true); - internal Node? FindRange([AllowNull] T from, [AllowNull] T to, bool lowerBoundActive, bool upperBoundActive) + internal Node? FindRange(T? from, T? to, bool lowerBoundActive, bool upperBoundActive) { Node? current = root; while (current != null) @@ -1504,17 +1504,15 @@ namespace System.Collections.Generic #region ISorted members - [MaybeNull] - public T Min => MinInternal; + public T? Min => MinInternal; - [MaybeNull] - internal virtual T MinInternal + internal virtual T? MinInternal { get { if (root == null) { - return default(T)!; + return default; } Node current = root; @@ -1527,17 +1525,15 @@ namespace System.Collections.Generic } } - [MaybeNull] - public T Max => MaxInternal; + public T? Max => MaxInternal; - [MaybeNull] - internal virtual T MaxInternal + internal virtual T? MaxInternal { get { if (root == null) { - return default(T)!; + return default; } Node current = root; @@ -1559,7 +1555,7 @@ namespace System.Collections.Generic } } - public virtual SortedSet GetViewBetween([AllowNull] T lowerValue, [AllowNull] T upperValue) + public virtual SortedSet GetViewBetween(T? lowerValue, T? upperValue) { if (Comparer.Compare(lowerValue, upperValue) > 0) { @@ -2074,7 +2070,7 @@ namespace System.Collections.Generic actualValue = node.Item; return true; } - actualValue = default(T)!; + actualValue = default; return false; } diff --git a/src/libraries/System.Collections/src/System/Collections/Generic/Stack.cs b/src/libraries/System.Collections/src/System/Collections/Generic/Stack.cs index dbb4157..8f191ee 100644 --- a/src/libraries/System.Collections/src/System/Collections/Generic/Stack.cs +++ b/src/libraries/System.Collections/src/System/Collections/Generic/Stack.cs @@ -315,7 +315,7 @@ namespace System.Collections.Generic private readonly Stack _stack; private readonly int _version; private int _index; - [AllowNull] private T _currentElement; + private T? _currentElement; internal Enumerator(Stack stack) { @@ -361,7 +361,7 @@ namespace System.Collections.Generic { if (_index < 0) ThrowEnumerationNotStartedOrEnded(); - return _currentElement; + return _currentElement!; } } diff --git a/src/libraries/System.ComponentModel.Composition/ref/System.ComponentModel.Composition.cs b/src/libraries/System.ComponentModel.Composition/ref/System.ComponentModel.Composition.cs index 2b30949..f55f6b2 100644 --- a/src/libraries/System.ComponentModel.Composition/ref/System.ComponentModel.Composition.cs +++ b/src/libraries/System.ComponentModel.Composition/ref/System.ComponentModel.Composition.cs @@ -415,16 +415,12 @@ namespace System.ComponentModel.Composition.Hosting protected ExportProvider() { } public event System.EventHandler? ExportsChanged { add { } remove { } } public event System.EventHandler? ExportsChanging { add { } remove { } } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public T GetExportedValueOrDefault() { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public T GetExportedValueOrDefault(string? contractName) { throw null; } + public T? GetExportedValueOrDefault() { throw null; } + public T? GetExportedValueOrDefault(string? contractName) { throw null; } public System.Collections.Generic.IEnumerable GetExportedValues() { throw null; } public System.Collections.Generic.IEnumerable GetExportedValues(string? contractName) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public T GetExportedValue() { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public T GetExportedValue(string? contractName) { throw null; } + public T? GetExportedValue() { throw null; } + public T? GetExportedValue(string? contractName) { throw null; } public System.Collections.Generic.IEnumerable GetExports(System.ComponentModel.Composition.Primitives.ImportDefinition definition) { throw null; } public System.Collections.Generic.IEnumerable GetExports(System.ComponentModel.Composition.Primitives.ImportDefinition definition, System.ComponentModel.Composition.Hosting.AtomicComposition? atomicComposition) { throw null; } public System.Collections.Generic.IEnumerable> GetExports(System.Type type, System.Type? metadataViewType, string? contractName) { throw null; } diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/CompositionResultOfT.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/CompositionResultOfT.cs index 380d202..9c66e18 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/CompositionResultOfT.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/CompositionResultOfT.cs @@ -11,7 +11,7 @@ namespace System.ComponentModel.Composition internal struct CompositionResult { private readonly IEnumerable? _errors; - [AllowNull] private readonly T _value; + private readonly T? _value; public CompositionResult(T value) : this(value, null) @@ -28,7 +28,7 @@ namespace System.ComponentModel.Composition { } - internal CompositionResult([AllowNull] T value, IEnumerable? errors) + internal CompositionResult(T? value, IEnumerable? errors) { _errors = errors; _value = value; @@ -53,7 +53,7 @@ namespace System.ComponentModel.Composition { ThrowOnErrors(); - return _value; + return _value!; } } diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AtomicComposition.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AtomicComposition.cs index d20dac1..752d817 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AtomicComposition.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AtomicComposition.cs @@ -295,7 +295,7 @@ namespace System.ComponentModel.Composition.Hosting return _outerAtomicComposition.TryGetValueInternal(key, localAtomicCompositionOnly, out value); } - value = default(T)!; + value = default; return false; } diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/ExportProvider.GetExportOverrides.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/ExportProvider.GetExportOverrides.cs index 12f0a6a..8ddbd6c 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/ExportProvider.GetExportOverrides.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/ExportProvider.GetExportOverrides.cs @@ -473,8 +473,7 @@ namespace System.ComponentModel.Composition.Hosting /// An error occurred during composition. will /// contain a collection of errors that occurred. /// - [return: MaybeNull] - public T GetExportedValue() + public T? GetExportedValue() { return GetExportedValue((string?)null); } @@ -524,8 +523,7 @@ namespace System.ComponentModel.Composition.Hosting /// An error occurred during composition. will /// contain a collection of errors that occurred. /// - [return: MaybeNull] - public T GetExportedValue(string? contractName) + public T? GetExportedValue(string? contractName) { return GetExportedValueCore(contractName, ImportCardinality.ExactlyOne); } @@ -575,8 +573,7 @@ namespace System.ComponentModel.Composition.Hosting /// An error occurred during composition. will /// contain a collection of errors that occurred. /// - [return: MaybeNull] - public T GetExportedValueOrDefault() + public T? GetExportedValueOrDefault() { return GetExportedValueOrDefault((string?)null); } @@ -626,8 +623,7 @@ namespace System.ComponentModel.Composition.Hosting /// An error occurred during composition. will /// contain a collection of errors that occurred. /// - [return: MaybeNull] - public T GetExportedValueOrDefault(string? contractName) + public T? GetExportedValueOrDefault(string? contractName) { return GetExportedValueCore(contractName, ImportCardinality.ZeroOrOne); } @@ -724,8 +720,7 @@ namespace System.ComponentModel.Composition.Hosting return result; } - [return: MaybeNull] - private T GetExportedValueCore(string? contractName, ImportCardinality cardinality) + private T? GetExportedValueCore(string? contractName, ImportCardinality cardinality) { if (!cardinality.IsAtMostOne()) { @@ -734,7 +729,7 @@ namespace System.ComponentModel.Composition.Hosting Export? export = GetExportsCore(typeof(T), (Type?)null, contractName, cardinality).SingleOrDefault(); - return (export != null) ? ExportServices.GetCastedExportedValue(export) : default(T)!; + return (export != null) ? ExportServices.GetCastedExportedValue(export) : default; } private IEnumerable> GetExportsCore(string? contractName) diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/MetadataServices.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/MetadataServices.cs index b64f990..25d362e 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/MetadataServices.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/MetadataServices.cs @@ -26,27 +26,19 @@ namespace System.ComponentModel.Composition return new ReadOnlyDictionary(metadata); } - [return: MaybeNull] - public static T GetValue(this IDictionary metadata, string key) + public static T? GetValue(this IDictionary metadata, string key) { if (metadata == null) { throw new ArgumentNullException(nameof(metadata)); } - if (!metadata.TryGetValue(key, out object? untypedValue)) + if (metadata.TryGetValue(key, out object? untypedValue) && untypedValue is T t) { - return default(T)!; + return t; } - if (untypedValue is T) - { - return (T)untypedValue; - } - else - { - return default(T)!; - } + return default; } } } diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/LazyMemberInfo.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/LazyMemberInfo.cs index 983f25d..14124ff 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/LazyMemberInfo.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/LazyMemberInfo.cs @@ -103,7 +103,7 @@ namespace System.ComponentModel.Composition.ReflectionModel { throw new Exception(SR.Diagnostic_InternalExceptionMessage); } - return MemberType.GetHashCode() ^ _accessors[0]!.GetHashCode(); // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/34644 + return MemberType.GetHashCode() ^ _accessors[0]!.GetHashCode(); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644) } } diff --git a/src/libraries/System.Data.Common/ref/System.Data.Common.cs b/src/libraries/System.Data.Common/ref/System.Data.Common.cs index 24cdb3d..d9df3c0 100644 --- a/src/libraries/System.Data.Common/ref/System.Data.Common.cs +++ b/src/libraries/System.Data.Common/ref/System.Data.Common.cs @@ -403,21 +403,15 @@ namespace System.Data } public static partial class DataRowExtensions { - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T Field(this System.Data.DataRow row, System.Data.DataColumn column) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T Field(this System.Data.DataRow row, System.Data.DataColumn column, System.Data.DataRowVersion version) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T Field(this System.Data.DataRow row, int columnIndex) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T Field(this System.Data.DataRow row, int columnIndex, System.Data.DataRowVersion version) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T Field(this System.Data.DataRow row, string columnName) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T Field(this System.Data.DataRow row, string columnName, System.Data.DataRowVersion version) { throw null; } - public static void SetField(this System.Data.DataRow row, System.Data.DataColumn column, [System.Diagnostics.CodeAnalysis.AllowNullAttribute] T value) { } - public static void SetField(this System.Data.DataRow row, int columnIndex, [System.Diagnostics.CodeAnalysis.AllowNullAttribute] T value) { } - public static void SetField(this System.Data.DataRow row, string columnName, [System.Diagnostics.CodeAnalysis.AllowNullAttribute] T value) { } + public static T? Field(this System.Data.DataRow row, System.Data.DataColumn column) { throw null; } + public static T? Field(this System.Data.DataRow row, System.Data.DataColumn column, System.Data.DataRowVersion version) { throw null; } + public static T? Field(this System.Data.DataRow row, int columnIndex) { throw null; } + public static T? Field(this System.Data.DataRow row, int columnIndex, System.Data.DataRowVersion version) { throw null; } + public static T? Field(this System.Data.DataRow row, string columnName) { throw null; } + public static T? Field(this System.Data.DataRow row, string columnName, System.Data.DataRowVersion version) { throw null; } + public static void SetField(this System.Data.DataRow row, System.Data.DataColumn column, T? value) { } + public static void SetField(this System.Data.DataRow row, int columnIndex, T? value) { } + public static void SetField(this System.Data.DataRow row, string columnName, T? value) { } } [System.FlagsAttribute] public enum DataRowState @@ -1057,8 +1051,8 @@ namespace System.Data [System.ComponentModel.BrowsableAttribute(false)] public bool IsSynchronized { get { throw null; } } public virtual System.Data.DataViewSetting this[System.Data.DataTable table] { get { throw null; } set { } } - [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public virtual System.Data.DataViewSetting this[int index] { get { throw null; } set { } } + [System.Diagnostics.CodeAnalysis.DisallowNullAttribute] + public virtual System.Data.DataViewSetting? this[int index] { get { throw null; } set { } } public virtual System.Data.DataViewSetting? this[string tableName] { get { throw null; } } [System.ComponentModel.BrowsableAttribute(false)] public object SyncRoot { get { throw null; } } @@ -1563,8 +1557,7 @@ namespace System.Data public static partial class TypedTableBaseExtensions { public static System.Data.EnumerableRowCollection AsEnumerable(this System.Data.TypedTableBase source) where TRow : System.Data.DataRow { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TRow ElementAtOrDefault(this System.Data.TypedTableBase source, int index) where TRow : System.Data.DataRow { throw null; } + public static TRow? ElementAtOrDefault(this System.Data.TypedTableBase source, int index) where TRow : System.Data.DataRow { throw null; } public static System.Data.OrderedEnumerableRowCollection OrderByDescending(this System.Data.TypedTableBase source, System.Func keySelector) where TRow : System.Data.DataRow { throw null; } public static System.Data.OrderedEnumerableRowCollection OrderByDescending(this System.Data.TypedTableBase source, System.Func keySelector, System.Collections.Generic.IComparer comparer) where TRow : System.Data.DataRow { throw null; } public static System.Data.OrderedEnumerableRowCollection OrderBy(this System.Data.TypedTableBase source, System.Func keySelector) where TRow : System.Data.DataRow { throw null; } diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbDataReaderExtensions.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbDataReaderExtensions.cs index 97e0faf..8b85144 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbDataReaderExtensions.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbDataReaderExtensions.cs @@ -30,7 +30,7 @@ namespace System.Data.Common BaseSchemaName = GetDbColumnValue(SchemaTableColumn.BaseSchemaName); BaseServerName = GetDbColumnValue(SchemaTableOptionalColumn.BaseServerName); BaseTableName = GetDbColumnValue(SchemaTableColumn.BaseTableName); - ColumnName = GetDbColumnValue(SchemaTableColumn.ColumnName); + ColumnName = GetDbColumnValue(SchemaTableColumn.ColumnName)!; ColumnOrdinal = GetDbColumnValue(SchemaTableColumn.ColumnOrdinal); ColumnSize = GetDbColumnValue(SchemaTableColumn.ColumnSize); IsAliased = GetDbColumnValue(SchemaTableColumn.IsAliased); @@ -49,8 +49,7 @@ namespace System.Data.Common DataTypeName = GetDbColumnValue("DataTypeName"); } - // The following may return null, but local methods can't be annotated for that yet ([MaybeNull]) - private T GetDbColumnValue(string columnName) => _schemaColumns.Contains(columnName) && _schemaRow[columnName] is T value ? value : default!; + private T? GetDbColumnValue(string columnName) => _schemaColumns.Contains(columnName) && _schemaRow[columnName] is T value ? value : default; } public static ReadOnlyCollection GetColumnSchema(this DbDataReader reader) diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLInt64Storage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLInt64Storage.cs index 2c9fa58..e469f32 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLInt64Storage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLInt64Storage.cs @@ -12,7 +12,7 @@ namespace System.Data.Common { internal sealed class SqlInt64Storage : DataStorage { - private SqlInt64[] _values = default!; + private SqlInt64[] _values = default!; // Late-initialized public SqlInt64Storage(DataColumn column) : base(column, typeof(SqlInt64), SqlInt64.Null, SqlInt64.Null, StorageType.SqlInt64) diff --git a/src/libraries/System.Data.Common/src/System/Data/DataRowExtensions.cs b/src/libraries/System.Data.Common/src/System/Data/DataRowExtensions.cs index afa65a3..3ebbdc1 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataRowExtensions.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataRowExtensions.cs @@ -19,8 +19,7 @@ namespace System.Data /// The input DataRow /// The input column name specifying which row value to retrieve. /// The DataRow value for the column specified. - [return: MaybeNull] - public static T Field(this DataRow row, string columnName) + public static T? Field(this DataRow row, string columnName) { DataSetUtil.CheckArgumentNull(row, nameof(row)); return UnboxT.s_unbox(row[columnName]); @@ -35,8 +34,7 @@ namespace System.Data /// The input DataRow /// The input DataColumn specifying which row value to retrieve. /// The DataRow value for the column specified. - [return: MaybeNull] - public static T Field(this DataRow row, DataColumn column) + public static T? Field(this DataRow row, DataColumn column) { DataSetUtil.CheckArgumentNull(row, nameof(row)); return UnboxT.s_unbox(row[column]); @@ -51,8 +49,7 @@ namespace System.Data /// The input DataRow /// The input ordinal specifying which row value to retrieve. /// The DataRow value for the column specified. - [return: MaybeNull] - public static T Field(this DataRow row, int columnIndex) + public static T? Field(this DataRow row, int columnIndex) { DataSetUtil.CheckArgumentNull(row, nameof(row)); return UnboxT.s_unbox(row[columnIndex]); @@ -68,8 +65,7 @@ namespace System.Data /// The input ordinal specifying which row value to retrieve. /// The DataRow version for which row value to retrieve. /// The DataRow value for the column specified. - [return: MaybeNull] - public static T Field(this DataRow row, int columnIndex, DataRowVersion version) + public static T? Field(this DataRow row, int columnIndex, DataRowVersion version) { DataSetUtil.CheckArgumentNull(row, nameof(row)); return UnboxT.s_unbox(row[columnIndex, version]); @@ -85,8 +81,7 @@ namespace System.Data /// The input column name specifying which row value to retrieve. /// The DataRow version for which row value to retrieve. /// The DataRow value for the column specified. - [return: MaybeNull] - public static T Field(this DataRow row, string columnName, DataRowVersion version) + public static T? Field(this DataRow row, string columnName, DataRowVersion version) { DataSetUtil.CheckArgumentNull(row, nameof(row)); return UnboxT.s_unbox(row[columnName, version]); @@ -102,8 +97,7 @@ namespace System.Data /// The input DataColumn specifying which row value to retrieve. /// The DataRow version for which row value to retrieve. /// The DataRow value for the column specified. - [return: MaybeNull] - public static T Field(this DataRow row, DataColumn column, DataRowVersion version) + public static T? Field(this DataRow row, DataColumn column, DataRowVersion version) { DataSetUtil.CheckArgumentNull(row, nameof(row)); return UnboxT.s_unbox(row[column, version]); @@ -115,7 +109,7 @@ namespace System.Data /// The input DataRow. /// The input ordinal specifying which row value to set. /// The new row value for the specified column. - public static void SetField(this DataRow row, int columnIndex, [AllowNull] T value) + public static void SetField(this DataRow row, int columnIndex, T? value) { DataSetUtil.CheckArgumentNull(row, nameof(row)); row[columnIndex] = (object?)value ?? DBNull.Value; @@ -127,7 +121,7 @@ namespace System.Data /// The input DataRow. /// The input column name specifying which row value to retrieve. /// The new row value for the specified column. - public static void SetField(this DataRow row, string columnName, [AllowNull] T value) + public static void SetField(this DataRow row, string columnName, T? value) { DataSetUtil.CheckArgumentNull(row, nameof(row)); row[columnName] = (object?)value ?? DBNull.Value; @@ -139,7 +133,7 @@ namespace System.Data /// The input DataRow. /// The input DataColumn specifying which row value to retrieve. /// The new row value for the specified column. - public static void SetField(this DataRow row, DataColumn column, [AllowNull] T value) + public static void SetField(this DataRow row, DataColumn column, T? value) { DataSetUtil.CheckArgumentNull(row, nameof(row)); row[column] = (object?)value ?? DBNull.Value; @@ -147,9 +141,9 @@ namespace System.Data private static class UnboxT { - internal static readonly Converter s_unbox = Create(); + internal static readonly Converter s_unbox = Create(); - private static Converter Create() + private static Converter Create() { if (typeof(T).IsValueType) { @@ -165,8 +159,7 @@ namespace System.Data return ReferenceField; } - [return: MaybeNull] - private static T ReferenceField(object value) + private static T? ReferenceField(object value) => value == DBNull.Value ? default : (T)value; private static T ValueField(object value) @@ -174,7 +167,6 @@ namespace System.Data ? throw DataSetUtil.InvalidCast(SR.Format(SR.DataSetLinq_NonNullableCast, typeof(T))) : (T)value; - [return: MaybeNull] private static Nullable NullableField(object value) where TElem : struct => value == DBNull.Value ? default : new Nullable((TElem)value); } diff --git a/src/libraries/System.Data.Common/src/System/Data/DataViewSettingCollection.cs b/src/libraries/System.Data.Common/src/System/Data/DataViewSettingCollection.cs index dc059c1..62b9fb6 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataViewSettingCollection.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataViewSettingCollection.cs @@ -84,8 +84,8 @@ namespace System.Data } } - [MaybeNull] - public virtual DataViewSetting this[int index] + [DisallowNull] + public virtual DataViewSetting? this[int index] { get { diff --git a/src/libraries/System.Data.Common/src/System/Data/RbTree.cs b/src/libraries/System.Data.Common/src/System/Data/RbTree.cs index 4c40476..a5f75b0 100644 --- a/src/libraries/System.Data.Common/src/System/Data/RbTree.cs +++ b/src/libraries/System.Data.Common/src/System/Data/RbTree.cs @@ -96,8 +96,8 @@ namespace System.Data internal const int DefaultPageSize = 32; /* 512 = 2^9 32 million nodes*/ internal const int NIL = 0; // 0th page, 0th slot for each tree till CLR static & generics issue is fixed - private TreePage?[] _pageTable = default!; // initial size 4, then doubles (grows) - it never shrinks. Late-initialized to non-null in InitTree. - private int[] _pageTableMap = default!; // Late-initialized to non-null in InitTree + private TreePage?[] _pageTable; // initial size 4, then doubles (grows) - it never shrinks. + private int[] _pageTableMap; private int _inUsePageCount; // contains count of allocated pages per tree, its <= the capacity of pageTable private int _nextFreePageLine; // used for keeping track of position of last used free page in pageTable public int root; @@ -107,8 +107,8 @@ namespace System.Data private int _inUseSatelliteTreeCount; // total number of satellite associated with this tree. private readonly TreeAccessMethod _accessMethod; - protected abstract int CompareNode([AllowNull] K record1, [AllowNull] K record2); - protected abstract int CompareSateliteTreeNode([AllowNull] K record1, [AllowNull] K record2); + protected abstract int CompareNode(K? record1, K? record2); + protected abstract int CompareSateliteTreeNode(K? record1, K? record2); protected RBTree(TreeAccessMethod accessMethod) { @@ -116,6 +116,8 @@ namespace System.Data InitTree(); } + [MemberNotNull(nameof(_pageTable))] + [MemberNotNull(nameof(_pageTableMap))] private void InitTree() { root = NIL; @@ -337,7 +339,7 @@ namespace System.Data * Use bitmap associated with page to allocate a slot. * mark the slot as used and return its index. */ - private int GetNewNode([AllowNull] K key) + private int GetNewNode(K? key) { // find page with free slots, if none, allocate a new page TreePage? page = null; @@ -1205,7 +1207,7 @@ namespace System.Data return root_id; } - private int SearchSubTree(int root_id, [AllowNull] K key) + private int SearchSubTree(int root_id, K? key) { if (root_id != NIL && _accessMethod != TreeAccessMethod.KEY_SEARCH_AND_INDEX) { @@ -1556,7 +1558,7 @@ namespace System.Data // Begin: List of methods for making it easy to work with ArrayList - public int Add([AllowNull] K item) //Insert (int record) + public int Add(K? item) //Insert (int record) { int nodeId = GetNewNode(item); RBInsert(NIL, nodeId, NIL, -1, false); @@ -1875,8 +1877,7 @@ namespace System.Data internal int _parentId; internal int _nextId; // multiple records associated with same key internal int _subTreeSize; // number of nodes in subtree rooted at the current node - [AllowNull, MaybeNull] - internal K _keyOfNode; + internal K? _keyOfNode; internal NodeColor _nodeColor; } @@ -2042,8 +2043,7 @@ namespace System.Data private readonly RBTree _tree; private readonly int _version; private int _index, _mainTreeNodeId; - [AllowNull, MaybeNull] - private K _current; + private K? _current; internal RBTreeEnumerator(RBTree tree) { diff --git a/src/libraries/System.Data.Common/src/System/Data/SortExpressionBuilder.cs b/src/libraries/System.Data.Common/src/System/Data/SortExpressionBuilder.cs index 2889e24..c5304d9 100644 --- a/src/libraries/System.Data.Common/src/System/Data/SortExpressionBuilder.cs +++ b/src/libraries/System.Data.Common/src/System/Data/SortExpressionBuilder.cs @@ -92,7 +92,7 @@ namespace System.Data /// Note: Comparison is done in the order it was Added. /// /// Comparison result of the combined Sort comparer expression - public int Compare([AllowNull] List a, [AllowNull] List b) + public int Compare(List? a, List? b) { Debug.Assert(a != null && b != null && a.Count == Count); diff --git a/src/libraries/System.Data.Common/src/System/Data/TypedTableBaseExtensions.cs b/src/libraries/System.Data.Common/src/System/Data/TypedTableBaseExtensions.cs index 9153511..ccdd593 100644 --- a/src/libraries/System.Data.Common/src/System/Data/TypedTableBaseExtensions.cs +++ b/src/libraries/System.Data.Common/src/System/Data/TypedTableBaseExtensions.cs @@ -92,8 +92,7 @@ namespace System.Data return new EnumerableRowCollection(source as DataTable); } - [return: MaybeNull] - public static TRow ElementAtOrDefault(this TypedTableBase source, int index) where TRow : DataRow + public static TRow? ElementAtOrDefault(this TypedTableBase source, int index) where TRow : DataRow { if ((index >= 0) && (index < source.Rows.Count)) { diff --git a/src/libraries/System.Data.Common/src/System/Data/xmlsaver.cs b/src/libraries/System.Data.Common/src/System/Data/xmlsaver.cs index 959cebb..0d5f495 100644 --- a/src/libraries/System.Data.Common/src/System/Data/xmlsaver.cs +++ b/src/libraries/System.Data.Common/src/System/Data/xmlsaver.cs @@ -6,6 +6,7 @@ using System.ComponentModel; using System.Data.SqlTypes; using System.Data.Common; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Text; @@ -2250,7 +2251,7 @@ namespace System.Data internal XmlWriter _xmlw = default!; // Late-initialized private bool _fBefore; private bool _fErrors; - internal Hashtable _rowsOrder = default!; // Always initialized in DoAssignments + internal Hashtable _rowsOrder; private readonly ArrayList _tables = new ArrayList(); private readonly bool _writeHierarchy; @@ -2297,7 +2298,7 @@ namespace System.Data } } - + [MemberNotNull(nameof(_rowsOrder))] private void DoAssignments(ArrayList tables) { int rows = 0; diff --git a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbReferenceCollection.cs b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbReferenceCollection.cs index 8cf24c8..02e5266 100644 --- a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbReferenceCollection.cs +++ b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbReferenceCollection.cs @@ -133,8 +133,7 @@ namespace System.Data.ProviderBase } } - [return: MaybeNull] - internal T FindItem(int tag, Func filterMethod) where T : class + internal T? FindItem(int tag, Func filterMethod) where T : class { bool lockObtained = false; try diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Unix.cs b/src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Unix.cs index 029f9cd..95bb53f 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Unix.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Unix.cs @@ -25,7 +25,7 @@ namespace System.IO.Enumeration private Queue? _pending; private Interop.Sys.DirectoryEntry _entry; - private TResult _current = default!; + private TResult? _current; // Used for creating full paths private char[]? _pathBuffer; diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Windows.cs b/src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Windows.cs index 69084ac..32fd206 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Windows.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Windows.cs @@ -31,7 +31,7 @@ namespace System.IO.Enumeration private readonly object _lock = new object(); private Interop.NtDll.FILE_FULL_DIR_INFORMATION* _entry; - private TResult _current = default!; + private TResult? _current; private IntPtr _buffer; private int _bufferLength; diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.cs b/src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.cs index c3d4a97..b5168eb 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.cs @@ -69,7 +69,7 @@ namespace System.IO.Enumeration /// The native error code. protected virtual bool ContinueOnError(int error) => false; - public TResult Current => _current; + public TResult Current => _current!; object? IEnumerator.Current => Current; diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/Iterator.cs b/src/libraries/System.IO.FileSystem/src/System/IO/Iterator.cs index 49c4b4c..09bf15d 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/Iterator.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/Iterator.cs @@ -14,18 +14,14 @@ namespace System.IO { private readonly int _threadId; internal int state; - [MaybeNull, AllowNull] - internal TSource current = default; + internal TSource? current; public Iterator() { _threadId = Environment.CurrentManagedThreadId; } - public TSource Current - { - get { return current!; } - } + public TSource Current => current!; protected abstract Iterator Clone(); @@ -37,7 +33,7 @@ namespace System.IO protected virtual void Dispose(bool disposing) { - current = default(TSource)!; + current = default; state = -1; } diff --git a/src/libraries/System.Linq.Expressions/src/System/Dynamic/Utils/CacheDict.cs b/src/libraries/System.Linq.Expressions/src/System/Dynamic/Utils/CacheDict.cs index 50b6cf2e..9c9a3bd 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Dynamic/Utils/CacheDict.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Dynamic/Utils/CacheDict.cs @@ -77,7 +77,7 @@ namespace System.Dynamic.Utils return true; } - value = default(TValue)!; + value = default; return false; } diff --git a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.cs b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.cs index 7365e10..c647214 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.cs @@ -286,7 +286,7 @@ namespace System.Linq.Expressions.Compiler Debug.Assert(_method is DynamicMethod); #endif { - return Expression.Field(Expression.Constant(new StrongBox(default(T)!)), "Value"); + return Expression.Field(Expression.Constant(new StrongBox()), "Value"); } #if FEATURE_COMPILE_TO_METHODBUILDER else diff --git a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/Utilities.cs b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/Utilities.cs index 6185577..7b757e9 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/Utilities.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/Utilities.cs @@ -192,7 +192,7 @@ namespace System.Linq.Expressions.Interpreter } } } - value = default(TValue)!; + value = default; return false; } diff --git a/src/libraries/System.Linq.Parallel/ref/System.Linq.Parallel.cs b/src/libraries/System.Linq.Parallel/ref/System.Linq.Parallel.cs index 837bf53..e8ab5c0 100644 --- a/src/libraries/System.Linq.Parallel/ref/System.Linq.Parallel.cs +++ b/src/libraries/System.Linq.Parallel/ref/System.Linq.Parallel.cs @@ -61,8 +61,7 @@ namespace System.Linq public static System.Linq.ParallelQuery DefaultIfEmpty(this System.Linq.ParallelQuery source, TSource defaultValue) { throw null; } public static System.Linq.ParallelQuery Distinct(this System.Linq.ParallelQuery source) { throw null; } public static System.Linq.ParallelQuery Distinct(this System.Linq.ParallelQuery source, System.Collections.Generic.IEqualityComparer? comparer) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TSource ElementAtOrDefault(this System.Linq.ParallelQuery source, int index) { throw null; } + public static TSource? ElementAtOrDefault(this System.Linq.ParallelQuery source, int index) { throw null; } public static TSource ElementAt(this System.Linq.ParallelQuery source, int index) { throw null; } public static System.Linq.ParallelQuery Empty() { throw null; } [System.ObsoleteAttribute("The second data source of a binary operator must be of type System.Linq.ParallelQuery rather than System.Collections.Generic.IEnumerable. To fix this problem, use the AsParallel() extension method to convert the right data source to System.Linq.ParallelQuery.")] @@ -71,10 +70,8 @@ namespace System.Linq public static System.Linq.ParallelQuery Except(this System.Linq.ParallelQuery first, System.Collections.Generic.IEnumerable second, System.Collections.Generic.IEqualityComparer? comparer) { throw null; } public static System.Linq.ParallelQuery Except(this System.Linq.ParallelQuery first, System.Linq.ParallelQuery second) { throw null; } public static System.Linq.ParallelQuery Except(this System.Linq.ParallelQuery first, System.Linq.ParallelQuery second, System.Collections.Generic.IEqualityComparer? comparer) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TSource FirstOrDefault(this System.Linq.ParallelQuery source) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TSource FirstOrDefault(this System.Linq.ParallelQuery source, System.Func predicate) { throw null; } + public static TSource? FirstOrDefault(this System.Linq.ParallelQuery source) { throw null; } + public static TSource? FirstOrDefault(this System.Linq.ParallelQuery source, System.Func predicate) { throw null; } public static TSource First(this System.Linq.ParallelQuery source) { throw null; } public static TSource First(this System.Linq.ParallelQuery source, System.Func predicate) { throw null; } public static void ForAll(this System.Linq.ParallelQuery source, System.Action action) { } @@ -104,10 +101,8 @@ namespace System.Linq public static System.Linq.ParallelQuery Join(this System.Linq.ParallelQuery outer, System.Collections.Generic.IEnumerable inner, System.Func outerKeySelector, System.Func innerKeySelector, System.Func resultSelector, System.Collections.Generic.IEqualityComparer? comparer) { throw null; } public static System.Linq.ParallelQuery Join(this System.Linq.ParallelQuery outer, System.Linq.ParallelQuery inner, System.Func outerKeySelector, System.Func innerKeySelector, System.Func resultSelector) { throw null; } public static System.Linq.ParallelQuery Join(this System.Linq.ParallelQuery outer, System.Linq.ParallelQuery inner, System.Func outerKeySelector, System.Func innerKeySelector, System.Func resultSelector, System.Collections.Generic.IEqualityComparer? comparer) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TSource LastOrDefault(this System.Linq.ParallelQuery source) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TSource LastOrDefault(this System.Linq.ParallelQuery source, System.Func predicate) { throw null; } + public static TSource? LastOrDefault(this System.Linq.ParallelQuery source) { throw null; } + public static TSource? LastOrDefault(this System.Linq.ParallelQuery source, System.Func predicate) { throw null; } public static TSource Last(this System.Linq.ParallelQuery source) { throw null; } public static TSource Last(this System.Linq.ParallelQuery source, System.Func predicate) { throw null; } public static long LongCount(this System.Linq.ParallelQuery source) { throw null; } @@ -122,8 +117,7 @@ namespace System.Linq public static long? Max(this System.Linq.ParallelQuery source) { throw null; } public static float? Max(this System.Linq.ParallelQuery source) { throw null; } public static float Max(this System.Linq.ParallelQuery source) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TSource Max(this System.Linq.ParallelQuery source) { throw null; } + public static TSource? Max(this System.Linq.ParallelQuery source) { throw null; } public static decimal Max(this System.Linq.ParallelQuery source, System.Func selector) { throw null; } public static double Max(this System.Linq.ParallelQuery source, System.Func selector) { throw null; } public static int Max(this System.Linq.ParallelQuery source, System.Func selector) { throw null; } @@ -134,8 +128,7 @@ namespace System.Linq public static long? Max(this System.Linq.ParallelQuery source, System.Func selector) { throw null; } public static float? Max(this System.Linq.ParallelQuery source, System.Func selector) { throw null; } public static float Max(this System.Linq.ParallelQuery source, System.Func selector) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TResult Max(this System.Linq.ParallelQuery source, System.Func selector) { throw null; } + public static TResult? Max(this System.Linq.ParallelQuery source, System.Func selector) { throw null; } public static decimal Min(this System.Linq.ParallelQuery source) { throw null; } public static double Min(this System.Linq.ParallelQuery source) { throw null; } public static int Min(this System.Linq.ParallelQuery source) { throw null; } @@ -146,8 +139,7 @@ namespace System.Linq public static long? Min(this System.Linq.ParallelQuery source) { throw null; } public static float? Min(this System.Linq.ParallelQuery source) { throw null; } public static float Min(this System.Linq.ParallelQuery source) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TSource Min(this System.Linq.ParallelQuery source) { throw null; } + public static TSource? Min(this System.Linq.ParallelQuery source) { throw null; } public static decimal Min(this System.Linq.ParallelQuery source, System.Func selector) { throw null; } public static double Min(this System.Linq.ParallelQuery source, System.Func selector) { throw null; } public static int Min(this System.Linq.ParallelQuery source, System.Func selector) { throw null; } @@ -158,8 +150,7 @@ namespace System.Linq public static long? Min(this System.Linq.ParallelQuery source, System.Func selector) { throw null; } public static float? Min(this System.Linq.ParallelQuery source, System.Func selector) { throw null; } public static float Min(this System.Linq.ParallelQuery source, System.Func selector) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TResult Min(this System.Linq.ParallelQuery source, System.Func selector) { throw null; } + public static TResult? Min(this System.Linq.ParallelQuery source, System.Func selector) { throw null; } public static System.Linq.ParallelQuery OfType(this System.Linq.ParallelQuery source) { throw null; } public static System.Linq.OrderedParallelQuery OrderByDescending(this System.Linq.ParallelQuery source, System.Func keySelector) { throw null; } public static System.Linq.OrderedParallelQuery OrderByDescending(this System.Linq.ParallelQuery source, System.Func keySelector, System.Collections.Generic.IComparer? comparer) { throw null; } @@ -180,10 +171,8 @@ namespace System.Linq public static bool SequenceEqual(this System.Linq.ParallelQuery first, System.Collections.Generic.IEnumerable second, System.Collections.Generic.IEqualityComparer? comparer) { throw null; } public static bool SequenceEqual(this System.Linq.ParallelQuery first, System.Linq.ParallelQuery second) { throw null; } public static bool SequenceEqual(this System.Linq.ParallelQuery first, System.Linq.ParallelQuery second, System.Collections.Generic.IEqualityComparer? comparer) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TSource SingleOrDefault(this System.Linq.ParallelQuery source) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TSource SingleOrDefault(this System.Linq.ParallelQuery source, System.Func predicate) { throw null; } + public static TSource? SingleOrDefault(this System.Linq.ParallelQuery source) { throw null; } + public static TSource? SingleOrDefault(this System.Linq.ParallelQuery source, System.Func predicate) { throw null; } public static TSource Single(this System.Linq.ParallelQuery source) { throw null; } public static TSource Single(this System.Linq.ParallelQuery source, System.Func predicate) { throw null; } public static System.Linq.ParallelQuery SkipWhile(this System.Linq.ParallelQuery source, System.Func predicate) { throw null; } diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Enumerables/AggregationMinMaxHelpers.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Enumerables/AggregationMinMaxHelpers.cs index 7a5fa88..746c1a5 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Enumerables/AggregationMinMaxHelpers.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Enumerables/AggregationMinMaxHelpers.cs @@ -20,8 +20,7 @@ namespace System.Linq // Helper method to find the minimum or maximum element in the source. // - [return: MaybeNull] - private static T Reduce(IEnumerable source, int sign) + private static T? Reduce(IEnumerable source, int sign) { Debug.Assert(source != null); Debug.Assert(sign == -1 || sign == 1); @@ -41,8 +40,7 @@ namespace System.Linq // Helper method to find the minimum element in the source. // - [return: MaybeNull] - internal static T ReduceMin(IEnumerable source) + internal static T? ReduceMin(IEnumerable source) { return Reduce(source, -1); } @@ -51,8 +49,7 @@ namespace System.Linq // Helper method to find the maximum element in the source. // - [return: MaybeNull] - internal static T ReduceMax(IEnumerable source) + internal static T? ReduceMax(IEnumerable source) { return Reduce(source, 1); } diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Enumerables/EmptyEnumerable.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Enumerables/EmptyEnumerable.cs index 4ad52ac..d4e21e1 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Enumerables/EmptyEnumerable.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Enumerables/EmptyEnumerable.cs @@ -56,7 +56,7 @@ namespace System.Linq.Parallel } } - internal class EmptyEnumerator : QueryOperatorEnumerator, IEnumerator + internal sealed class EmptyEnumerator : QueryOperatorEnumerator, IEnumerator { internal override bool MoveNext([MaybeNullWhen(false), AllowNull] ref T currentElement, ref int currentKey) { diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Helpers.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Helpers.cs index 746887d..5449425 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Helpers.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Helpers.cs @@ -133,7 +133,7 @@ namespace System.Linq.Parallel { internal int hashCode; internal int next; - [MaybeNull, AllowNull] internal TElement value; + internal TElement? value; } } } diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/AsynchronousChannelMergeEnumerator.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/AsynchronousChannelMergeEnumerator.cs index e741ac5..3432a14 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/AsynchronousChannelMergeEnumerator.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/AsynchronousChannelMergeEnumerator.cs @@ -32,7 +32,7 @@ namespace System.Linq.Parallel private IntValueEvent? _consumerEvent; // The consumer event. private readonly bool[] _done; // Tracks which channels are done. private int _channelIndex; // The next channel from which we'll dequeue. - [MaybeNull, AllowNull] private T _currentElement = default; // The remembered element from the previous MoveNext. + private T? _currentElement; // The remembered element from the previous MoveNext. //----------------------------------------------------------------------------------- // Allocates a new enumerator over a set of one-to-one channels. diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/SynchronousChannelMergeEnumerator.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/SynchronousChannelMergeEnumerator.cs index bb0c023..ba10ef6 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/SynchronousChannelMergeEnumerator.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/SynchronousChannelMergeEnumerator.cs @@ -24,7 +24,7 @@ namespace System.Linq.Parallel { private readonly SynchronousChannel[] _channels; // The channel array we will enumerate, from left-to-right. private int _channelIndex; // The current channel index. This moves through the array as we enumerate. - private T _currentElement = default!; // The last element remembered during enumeration. + private T? _currentElement; // The last element remembered during enumeration. //----------------------------------------------------------------------------------- // Instantiates a new enumerator for a set of channels. @@ -61,7 +61,7 @@ namespace System.Linq.Parallel throw new InvalidOperationException(SR.PLINQ_CommonEnumerator_Current_NotStarted); } - return _currentElement; + return _currentElement!; } } diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/QueryOperators/Binary/ConcatQueryOperator.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/QueryOperators/Binary/ConcatQueryOperator.cs index faa7e1a..f6b4b72 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/QueryOperators/Binary/ConcatQueryOperator.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/QueryOperators/Binary/ConcatQueryOperator.cs @@ -296,10 +296,8 @@ namespace System.Linq.Parallel internal struct ConcatKey { - [MaybeNull, AllowNull] - private readonly TLeftKey _leftKey; - [MaybeNull, AllowNull] - private readonly TRightKey _rightKey; + private readonly TLeftKey? _leftKey; + private readonly TRightKey? _rightKey; private readonly bool _isLeft; private ConcatKey([AllowNull] TLeftKey leftKey, [AllowNull] TRightKey rightKey, bool isLeft) diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Utils/ReverseComparer.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Utils/ReverseComparer.cs index f949814..229b524 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Utils/ReverseComparer.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Utils/ReverseComparer.cs @@ -26,7 +26,7 @@ namespace System.Linq.Parallel _comparer = comparer; } - public int Compare([AllowNull] T x, [AllowNull] T y) + public int Compare(T? x, T? y) { return _comparer.Compare(y, x); } diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/ParallelEnumerable.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/ParallelEnumerable.cs index 17a378e..f4f870c 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/ParallelEnumerable.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/ParallelEnumerable.cs @@ -2659,8 +2659,7 @@ namespace System.Linq /// /// The query was canceled. /// - [return: MaybeNull] - public static TSource Min(this ParallelQuery source) + public static TSource? Min(this ParallelQuery source) { if (source == null) throw new ArgumentNullException(nameof(source)); return AggregationMinMaxHelpers.ReduceMin(source); @@ -2922,8 +2921,7 @@ namespace System.Linq /// /// The query was canceled. /// - [return: MaybeNull] - public static TResult Min(this ParallelQuery source, Func selector) + public static TResult? Min(this ParallelQuery source, Func selector) { return source.Select(selector).Min(); } @@ -3164,8 +3162,7 @@ namespace System.Linq /// /// The query was canceled. /// - [return: MaybeNull] - public static TSource Max(this ParallelQuery source) + public static TSource? Max(this ParallelQuery source) { if (source == null) throw new ArgumentNullException(nameof(source)); return AggregationMinMaxHelpers.ReduceMax(source); @@ -3427,8 +3424,7 @@ namespace System.Linq /// /// The query was canceled. /// - [return: MaybeNull] - public static TResult Max(this ParallelQuery source, Func selector) + public static TResult? Max(this ParallelQuery source, Func selector) { return source.Select(selector).Max(); } @@ -5289,8 +5285,7 @@ namespace System.Linq // defaultIfEmpty - whether to return a default value (true) or throw an // exception if the output of the query operator is empty // - [return: MaybeNull] - private static TSource GetOneWithPossibleDefault( + private static TSource? GetOneWithPossibleDefault( QueryOperator queryOp, bool throwIfTwo, bool defaultIfEmpty) { Debug.Assert(queryOp != null, "expected query operator"); @@ -5321,7 +5316,7 @@ namespace System.Linq if (defaultIfEmpty) { - return default(TSource)!; + return default; } else { @@ -5436,8 +5431,7 @@ namespace System.Linq /// /// The query was canceled. /// - [return: MaybeNull] - public static TSource FirstOrDefault(this ParallelQuery source) + public static TSource? FirstOrDefault(this ParallelQuery source) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5483,8 +5477,7 @@ namespace System.Linq /// /// The query was canceled. /// - [return: MaybeNull] - public static TSource FirstOrDefault(this ParallelQuery source, Func predicate) + public static TSource? FirstOrDefault(this ParallelQuery source, Func predicate) { if (source == null) throw new ArgumentNullException(nameof(source)); if (predicate == null) throw new ArgumentNullException(nameof(predicate)); @@ -5616,8 +5609,7 @@ namespace System.Linq /// /// The query was canceled. /// - [return: MaybeNull] - public static TSource LastOrDefault(this ParallelQuery source) + public static TSource? LastOrDefault(this ParallelQuery source) { // @PERF: optimize for seekable data sources. E.g. if an array, we can // seek directly to the last element. @@ -5659,8 +5651,7 @@ namespace System.Linq /// /// The query was canceled. /// - [return: MaybeNull] - public static TSource LastOrDefault(this ParallelQuery source, Func predicate) + public static TSource? LastOrDefault(this ParallelQuery source, Func predicate) { if (source == null) throw new ArgumentNullException(nameof(source)); if (predicate == null) throw new ArgumentNullException(nameof(predicate)); @@ -5764,8 +5755,7 @@ namespace System.Linq /// /// The query was canceled. /// - [return: MaybeNull] - public static TSource SingleOrDefault(this ParallelQuery source) + public static TSource? SingleOrDefault(this ParallelQuery source) { // @PERF: optimize for ICollection-typed data sources, i.e. we can just // check the Count property and avoid costly fork/join/synchronization. @@ -5795,8 +5785,7 @@ namespace System.Linq /// /// The query was canceled. /// - [return: MaybeNull] - public static TSource SingleOrDefault(this ParallelQuery source, Func predicate) + public static TSource? SingleOrDefault(this ParallelQuery source, Func predicate) { if (source == null) throw new ArgumentNullException(nameof(source)); if (predicate == null) throw new ArgumentNullException(nameof(predicate)); @@ -5821,9 +5810,9 @@ namespace System.Linq /// /// is a null reference (Nothing in Visual Basic). /// - public static ParallelQuery DefaultIfEmpty(this ParallelQuery source) + public static ParallelQuery DefaultIfEmpty(this ParallelQuery source) { - return DefaultIfEmpty(source, default!); + return DefaultIfEmpty(source, default!)!; } /// @@ -5909,8 +5898,7 @@ namespace System.Linq /// /// The query was canceled. /// - [return: MaybeNull] - public static TSource ElementAtOrDefault(this ParallelQuery source, int index) + public static TSource? ElementAtOrDefault(this ParallelQuery source, int index) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5928,7 +5916,7 @@ namespace System.Linq } } - return default(TSource)!; + return default; } } } diff --git a/src/libraries/System.Linq.Queryable/ref/System.Linq.Queryable.cs b/src/libraries/System.Linq.Queryable/ref/System.Linq.Queryable.cs index 91d264a..c3253aa 100644 --- a/src/libraries/System.Linq.Queryable/ref/System.Linq.Queryable.cs +++ b/src/libraries/System.Linq.Queryable/ref/System.Linq.Queryable.cs @@ -74,15 +74,12 @@ namespace System.Linq public static System.Linq.IQueryable DefaultIfEmpty(this System.Linq.IQueryable source, TSource defaultValue) { throw null; } public static System.Linq.IQueryable Distinct(this System.Linq.IQueryable source) { throw null; } public static System.Linq.IQueryable Distinct(this System.Linq.IQueryable source, System.Collections.Generic.IEqualityComparer? comparer) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TSource ElementAtOrDefault(this System.Linq.IQueryable source, int index) { throw null; } + public static TSource? ElementAtOrDefault(this System.Linq.IQueryable source, int index) { throw null; } public static TSource ElementAt(this System.Linq.IQueryable source, int index) { throw null; } public static System.Linq.IQueryable Except(this System.Linq.IQueryable source1, System.Collections.Generic.IEnumerable source2) { throw null; } public static System.Linq.IQueryable Except(this System.Linq.IQueryable source1, System.Collections.Generic.IEnumerable source2, System.Collections.Generic.IEqualityComparer? comparer) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TSource FirstOrDefault(this System.Linq.IQueryable source) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TSource FirstOrDefault(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> predicate) { throw null; } + public static TSource? FirstOrDefault(this System.Linq.IQueryable source) { throw null; } + public static TSource? FirstOrDefault(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> predicate) { throw null; } public static TSource First(this System.Linq.IQueryable source) { throw null; } public static TSource First(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> predicate) { throw null; } public static System.Linq.IQueryable> GroupBy(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> keySelector) { throw null; } @@ -99,22 +96,16 @@ namespace System.Linq public static System.Linq.IQueryable Intersect(this System.Linq.IQueryable source1, System.Collections.Generic.IEnumerable source2, System.Collections.Generic.IEqualityComparer? comparer) { throw null; } public static System.Linq.IQueryable Join(this System.Linq.IQueryable outer, System.Collections.Generic.IEnumerable inner, System.Linq.Expressions.Expression> outerKeySelector, System.Linq.Expressions.Expression> innerKeySelector, System.Linq.Expressions.Expression> resultSelector) { throw null; } public static System.Linq.IQueryable Join(this System.Linq.IQueryable outer, System.Collections.Generic.IEnumerable inner, System.Linq.Expressions.Expression> outerKeySelector, System.Linq.Expressions.Expression> innerKeySelector, System.Linq.Expressions.Expression> resultSelector, System.Collections.Generic.IEqualityComparer? comparer) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TSource LastOrDefault(this System.Linq.IQueryable source) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TSource LastOrDefault(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> predicate) { throw null; } + public static TSource? LastOrDefault(this System.Linq.IQueryable source) { throw null; } + public static TSource? LastOrDefault(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> predicate) { throw null; } public static TSource Last(this System.Linq.IQueryable source) { throw null; } public static TSource Last(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> predicate) { throw null; } public static long LongCount(this System.Linq.IQueryable source) { throw null; } public static long LongCount(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> predicate) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TSource Max(this System.Linq.IQueryable source) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TResult Max(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> selector) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TSource Min(this System.Linq.IQueryable source) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TResult Min(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> selector) { throw null; } + public static TSource? Max(this System.Linq.IQueryable source) { throw null; } + public static TResult? Max(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> selector) { throw null; } + public static TSource? Min(this System.Linq.IQueryable source) { throw null; } + public static TResult? Min(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> selector) { throw null; } public static System.Linq.IQueryable OfType(this System.Linq.IQueryable source) { throw null; } public static System.Linq.IOrderedQueryable OrderByDescending(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> keySelector) { throw null; } public static System.Linq.IOrderedQueryable OrderByDescending(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> keySelector, System.Collections.Generic.IComparer? comparer) { throw null; } @@ -130,10 +121,8 @@ namespace System.Linq public static System.Linq.IQueryable Select(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> selector) { throw null; } public static bool SequenceEqual(this System.Linq.IQueryable source1, System.Collections.Generic.IEnumerable source2) { throw null; } public static bool SequenceEqual(this System.Linq.IQueryable source1, System.Collections.Generic.IEnumerable source2, System.Collections.Generic.IEqualityComparer? comparer) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TSource SingleOrDefault(this System.Linq.IQueryable source) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TSource SingleOrDefault(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> predicate) { throw null; } + public static TSource? SingleOrDefault(this System.Linq.IQueryable source) { throw null; } + public static TSource? SingleOrDefault(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> predicate) { throw null; } public static TSource Single(this System.Linq.IQueryable source) { throw null; } public static TSource Single(this System.Linq.IQueryable source, System.Linq.Expressions.Expression> predicate) { throw null; } public static System.Linq.IQueryable SkipLast(this System.Linq.IQueryable source, int count) { throw null; } diff --git a/src/libraries/System.Linq.Queryable/src/System/Linq/CachedReflection.cs b/src/libraries/System.Linq.Queryable/src/System/Linq/CachedReflection.cs index 91e37ff..8f345d0 100644 --- a/src/libraries/System.Linq.Queryable/src/System/Linq/CachedReflection.cs +++ b/src/libraries/System.Linq.Queryable/src/System/Linq/CachedReflection.cs @@ -262,7 +262,7 @@ namespace System.Linq public static MethodInfo ElementAtOrDefault_TSource_2(Type TSource) => (s_ElementAtOrDefault_TSource_2 ?? - (s_ElementAtOrDefault_TSource_2 = new Func, int, object>(Queryable.ElementAtOrDefault).GetMethodInfo().GetGenericMethodDefinition())) + (s_ElementAtOrDefault_TSource_2 = new Func, int, object?>(Queryable.ElementAtOrDefault).GetMethodInfo().GetGenericMethodDefinition())) .MakeGenericMethod(TSource); private static MethodInfo? s_Except_TSource_2; @@ -297,14 +297,14 @@ namespace System.Linq public static MethodInfo FirstOrDefault_TSource_1(Type TSource) => (s_FirstOrDefault_TSource_1 ?? - (s_FirstOrDefault_TSource_1 = new Func, object>(Queryable.FirstOrDefault).GetMethodInfo().GetGenericMethodDefinition())) + (s_FirstOrDefault_TSource_1 = new Func, object?>(Queryable.FirstOrDefault).GetMethodInfo().GetGenericMethodDefinition())) .MakeGenericMethod(TSource); private static MethodInfo? s_FirstOrDefault_TSource_2; public static MethodInfo FirstOrDefault_TSource_2(Type TSource) => (s_FirstOrDefault_TSource_2 ?? - (s_FirstOrDefault_TSource_2 = new Func, Expression>, object>(Queryable.FirstOrDefault).GetMethodInfo().GetGenericMethodDefinition())) + (s_FirstOrDefault_TSource_2 = new Func, Expression>, object?>(Queryable.FirstOrDefault).GetMethodInfo().GetGenericMethodDefinition())) .MakeGenericMethod(TSource); private static MethodInfo? s_GroupBy_TSource_TKey_2; @@ -423,14 +423,14 @@ namespace System.Linq public static MethodInfo LastOrDefault_TSource_1(Type TSource) => (s_LastOrDefault_TSource_1 ?? - (s_LastOrDefault_TSource_1 = new Func, object>(Queryable.LastOrDefault).GetMethodInfo().GetGenericMethodDefinition())) + (s_LastOrDefault_TSource_1 = new Func, object?>(Queryable.LastOrDefault).GetMethodInfo().GetGenericMethodDefinition())) .MakeGenericMethod(TSource); private static MethodInfo? s_LastOrDefault_TSource_2; public static MethodInfo LastOrDefault_TSource_2(Type TSource) => (s_LastOrDefault_TSource_2 ?? - (s_LastOrDefault_TSource_2 = new Func, Expression>, object>(Queryable.LastOrDefault).GetMethodInfo().GetGenericMethodDefinition())) + (s_LastOrDefault_TSource_2 = new Func, Expression>, object?>(Queryable.LastOrDefault).GetMethodInfo().GetGenericMethodDefinition())) .MakeGenericMethod(TSource); private static MethodInfo? s_LongCount_TSource_1; @@ -451,28 +451,28 @@ namespace System.Linq public static MethodInfo Max_TSource_1(Type TSource) => (s_Max_TSource_1 ?? - (s_Max_TSource_1 = new Func, object>(Queryable.Max).GetMethodInfo().GetGenericMethodDefinition())) + (s_Max_TSource_1 = new Func, object?>(Queryable.Max).GetMethodInfo().GetGenericMethodDefinition())) .MakeGenericMethod(TSource); private static MethodInfo? s_Max_TSource_TResult_2; public static MethodInfo Max_TSource_TResult_2(Type TSource, Type TResult) => (s_Max_TSource_TResult_2 ?? - (s_Max_TSource_TResult_2 = new Func, Expression>, object>(Queryable.Max).GetMethodInfo().GetGenericMethodDefinition())) + (s_Max_TSource_TResult_2 = new Func, Expression>, object?>(Queryable.Max).GetMethodInfo().GetGenericMethodDefinition())) .MakeGenericMethod(TSource, TResult); private static MethodInfo? s_Min_TSource_1; public static MethodInfo Min_TSource_1(Type TSource) => (s_Min_TSource_1 ?? - (s_Min_TSource_1 = new Func, object>(Queryable.Min).GetMethodInfo().GetGenericMethodDefinition())) + (s_Min_TSource_1 = new Func, object?>(Queryable.Min).GetMethodInfo().GetGenericMethodDefinition())) .MakeGenericMethod(TSource); private static MethodInfo? s_Min_TSource_TResult_2; public static MethodInfo Min_TSource_TResult_2(Type TSource, Type TResult) => (s_Min_TSource_TResult_2 ?? - (s_Min_TSource_TResult_2 = new Func, Expression>, object>(Queryable.Min).GetMethodInfo().GetGenericMethodDefinition())) + (s_Min_TSource_TResult_2 = new Func, Expression>, object?>(Queryable.Min).GetMethodInfo().GetGenericMethodDefinition())) .MakeGenericMethod(TSource, TResult); private static MethodInfo? s_OfType_TResult_1; @@ -591,14 +591,14 @@ namespace System.Linq public static MethodInfo SingleOrDefault_TSource_1(Type TSource) => (s_SingleOrDefault_TSource_1 ?? - (s_SingleOrDefault_TSource_1 = new Func, object>(Queryable.SingleOrDefault).GetMethodInfo().GetGenericMethodDefinition())) + (s_SingleOrDefault_TSource_1 = new Func, object?>(Queryable.SingleOrDefault).GetMethodInfo().GetGenericMethodDefinition())) .MakeGenericMethod(TSource); private static MethodInfo? s_SingleOrDefault_TSource_2; public static MethodInfo SingleOrDefault_TSource_2(Type TSource) => (s_SingleOrDefault_TSource_2 ?? - (s_SingleOrDefault_TSource_2 = new Func, Expression>, object>(Queryable.SingleOrDefault).GetMethodInfo().GetGenericMethodDefinition())) + (s_SingleOrDefault_TSource_2 = new Func, Expression>, object?>(Queryable.SingleOrDefault).GetMethodInfo().GetGenericMethodDefinition())) .MakeGenericMethod(TSource); private static MethodInfo? s_Skip_TSource_2; diff --git a/src/libraries/System.Linq.Queryable/src/System/Linq/Queryable.cs b/src/libraries/System.Linq.Queryable/src/System/Linq/Queryable.cs index e3ed64c..902474b 100644 --- a/src/libraries/System.Linq.Queryable/src/System/Linq/Queryable.cs +++ b/src/libraries/System.Linq.Queryable/src/System/Linq/Queryable.cs @@ -740,8 +740,7 @@ namespace System.Linq )); } - [return: MaybeNull] - public static TSource FirstOrDefault(this IQueryable source) + public static TSource? FirstOrDefault(this IQueryable source) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -751,8 +750,7 @@ namespace System.Linq CachedReflectionInfo.FirstOrDefault_TSource_1(typeof(TSource)), source.Expression)); } - [return: MaybeNull] - public static TSource FirstOrDefault(this IQueryable source, Expression> predicate) + public static TSource? FirstOrDefault(this IQueryable source, Expression> predicate) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -790,8 +788,7 @@ namespace System.Linq )); } - [return: MaybeNull] - public static TSource LastOrDefault(this IQueryable source) + public static TSource? LastOrDefault(this IQueryable source) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -801,8 +798,7 @@ namespace System.Linq CachedReflectionInfo.LastOrDefault_TSource_1(typeof(TSource)), source.Expression)); } - [return: MaybeNull] - public static TSource LastOrDefault(this IQueryable source, Expression> predicate) + public static TSource? LastOrDefault(this IQueryable source, Expression> predicate) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -840,8 +836,7 @@ namespace System.Linq )); } - [return: MaybeNull] - public static TSource SingleOrDefault(this IQueryable source) + public static TSource? SingleOrDefault(this IQueryable source) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -851,8 +846,7 @@ namespace System.Linq CachedReflectionInfo.SingleOrDefault_TSource_1(typeof(TSource)), source.Expression)); } - [return: MaybeNull] - public static TSource SingleOrDefault(this IQueryable source, Expression> predicate) + public static TSource? SingleOrDefault(this IQueryable source, Expression> predicate) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -880,8 +874,7 @@ namespace System.Linq )); } - [return: MaybeNull] - public static TSource ElementAtOrDefault(this IQueryable source, int index) + public static TSource? ElementAtOrDefault(this IQueryable source, int index) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -1065,8 +1058,7 @@ namespace System.Linq )); } - [return: MaybeNull] - public static TSource Min(this IQueryable source) + public static TSource? Min(this IQueryable source) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -1076,8 +1068,7 @@ namespace System.Linq CachedReflectionInfo.Min_TSource_1(typeof(TSource)), source.Expression)); } - [return: MaybeNull] - public static TResult Min(this IQueryable source, Expression> selector) + public static TResult? Min(this IQueryable source, Expression> selector) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -1091,8 +1082,7 @@ namespace System.Linq )); } - [return: MaybeNull] - public static TSource Max(this IQueryable source) + public static TSource? Max(this IQueryable source) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -1102,8 +1092,7 @@ namespace System.Linq CachedReflectionInfo.Max_TSource_1(typeof(TSource)), source.Expression)); } - [return: MaybeNull] - public static TResult Max(this IQueryable source, Expression> selector) + public static TResult? Max(this IQueryable source, Expression> selector) { if (source == null) throw Error.ArgumentNull(nameof(source)); diff --git a/src/libraries/System.Linq/ref/System.Linq.cs b/src/libraries/System.Linq/ref/System.Linq.cs index bf41a28..91d5432 100644 --- a/src/libraries/System.Linq/ref/System.Linq.cs +++ b/src/libraries/System.Linq/ref/System.Linq.cs @@ -42,17 +42,17 @@ namespace System.Linq public static bool Contains(this System.Collections.Generic.IEnumerable source, TSource value, System.Collections.Generic.IEqualityComparer? comparer) { throw null; } public static int Count(this System.Collections.Generic.IEnumerable source) { throw null; } public static int Count(this System.Collections.Generic.IEnumerable source, System.Func predicate) { throw null; } - public static System.Collections.Generic.IEnumerable DefaultIfEmpty(this System.Collections.Generic.IEnumerable source) { throw null; } + public static System.Collections.Generic.IEnumerable DefaultIfEmpty(this System.Collections.Generic.IEnumerable source) { throw null; } public static System.Collections.Generic.IEnumerable DefaultIfEmpty(this System.Collections.Generic.IEnumerable source, TSource defaultValue) { throw null; } public static System.Collections.Generic.IEnumerable Distinct(this System.Collections.Generic.IEnumerable source) { throw null; } public static System.Collections.Generic.IEnumerable Distinct(this System.Collections.Generic.IEnumerable source, System.Collections.Generic.IEqualityComparer? comparer) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TSource ElementAtOrDefault(this System.Collections.Generic.IEnumerable source, int index) { throw null; } + public static TSource? ElementAtOrDefault(this System.Collections.Generic.IEnumerable source, int index) { throw null; } public static TSource ElementAt(this System.Collections.Generic.IEnumerable source, int index) { throw null; } public static System.Collections.Generic.IEnumerable Empty() { throw null; } public static System.Collections.Generic.IEnumerable Except(this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second) { throw null; } public static System.Collections.Generic.IEnumerable Except(this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second, System.Collections.Generic.IEqualityComparer? comparer) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TSource FirstOrDefault(this System.Collections.Generic.IEnumerable source) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TSource FirstOrDefault(this System.Collections.Generic.IEnumerable source, System.Func predicate) { throw null; } + public static TSource? FirstOrDefault(this System.Collections.Generic.IEnumerable source) { throw null; } + public static TSource? FirstOrDefault(this System.Collections.Generic.IEnumerable source, System.Func predicate) { throw null; } public static TSource First(this System.Collections.Generic.IEnumerable source) { throw null; } public static TSource First(this System.Collections.Generic.IEnumerable source, System.Func predicate) { throw null; } public static System.Collections.Generic.IEnumerable> GroupBy(this System.Collections.Generic.IEnumerable source, System.Func keySelector) { throw null; } @@ -69,8 +69,8 @@ namespace System.Linq public static System.Collections.Generic.IEnumerable Intersect(this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second, System.Collections.Generic.IEqualityComparer? comparer) { throw null; } public static System.Collections.Generic.IEnumerable Join(this System.Collections.Generic.IEnumerable outer, System.Collections.Generic.IEnumerable inner, System.Func outerKeySelector, System.Func innerKeySelector, System.Func resultSelector) { throw null; } public static System.Collections.Generic.IEnumerable Join(this System.Collections.Generic.IEnumerable outer, System.Collections.Generic.IEnumerable inner, System.Func outerKeySelector, System.Func innerKeySelector, System.Func resultSelector, System.Collections.Generic.IEqualityComparer? comparer) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TSource LastOrDefault(this System.Collections.Generic.IEnumerable source) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TSource LastOrDefault(this System.Collections.Generic.IEnumerable source, System.Func predicate) { throw null; } + public static TSource? LastOrDefault(this System.Collections.Generic.IEnumerable source) { throw null; } + public static TSource? LastOrDefault(this System.Collections.Generic.IEnumerable source, System.Func predicate) { throw null; } public static TSource Last(this System.Collections.Generic.IEnumerable source) { throw null; } public static TSource Last(this System.Collections.Generic.IEnumerable source, System.Func predicate) { throw null; } public static long LongCount(this System.Collections.Generic.IEnumerable source) { throw null; } @@ -85,7 +85,7 @@ namespace System.Linq public static long? Max(this System.Collections.Generic.IEnumerable source) { throw null; } public static float? Max(this System.Collections.Generic.IEnumerable source) { throw null; } public static float Max(this System.Collections.Generic.IEnumerable source) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TSource Max(this System.Collections.Generic.IEnumerable source) { throw null; } + public static TSource? Max(this System.Collections.Generic.IEnumerable source) { throw null; } public static decimal Max(this System.Collections.Generic.IEnumerable source, System.Func selector) { throw null; } public static double Max(this System.Collections.Generic.IEnumerable source, System.Func selector) { throw null; } public static int Max(this System.Collections.Generic.IEnumerable source, System.Func selector) { throw null; } @@ -96,7 +96,7 @@ namespace System.Linq public static long? Max(this System.Collections.Generic.IEnumerable source, System.Func selector) { throw null; } public static float? Max(this System.Collections.Generic.IEnumerable source, System.Func selector) { throw null; } public static float Max(this System.Collections.Generic.IEnumerable source, System.Func selector) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TResult Max(this System.Collections.Generic.IEnumerable source, System.Func selector) { throw null; } + public static TResult? Max(this System.Collections.Generic.IEnumerable source, System.Func selector) { throw null; } public static decimal Min(this System.Collections.Generic.IEnumerable source) { throw null; } public static double Min(this System.Collections.Generic.IEnumerable source) { throw null; } public static int Min(this System.Collections.Generic.IEnumerable source) { throw null; } @@ -107,7 +107,7 @@ namespace System.Linq public static long? Min(this System.Collections.Generic.IEnumerable source) { throw null; } public static float? Min(this System.Collections.Generic.IEnumerable source) { throw null; } public static float Min(this System.Collections.Generic.IEnumerable source) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TSource Min(this System.Collections.Generic.IEnumerable source) { throw null; } + public static TSource? Min(this System.Collections.Generic.IEnumerable source) { throw null; } public static decimal Min(this System.Collections.Generic.IEnumerable source, System.Func selector) { throw null; } public static double Min(this System.Collections.Generic.IEnumerable source, System.Func selector) { throw null; } public static int Min(this System.Collections.Generic.IEnumerable source, System.Func selector) { throw null; } @@ -118,7 +118,7 @@ namespace System.Linq public static long? Min(this System.Collections.Generic.IEnumerable source, System.Func selector) { throw null; } public static float? Min(this System.Collections.Generic.IEnumerable source, System.Func selector) { throw null; } public static float Min(this System.Collections.Generic.IEnumerable source, System.Func selector) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TResult Min(this System.Collections.Generic.IEnumerable source, System.Func selector) { throw null; } + public static TResult? Min(this System.Collections.Generic.IEnumerable source, System.Func selector) { throw null; } public static System.Collections.Generic.IEnumerable OfType(this System.Collections.IEnumerable source) { throw null; } public static System.Linq.IOrderedEnumerable OrderByDescending(this System.Collections.Generic.IEnumerable source, System.Func keySelector) { throw null; } public static System.Linq.IOrderedEnumerable OrderByDescending(this System.Collections.Generic.IEnumerable source, System.Func keySelector, System.Collections.Generic.IComparer? comparer) { throw null; } @@ -136,8 +136,8 @@ namespace System.Linq public static System.Collections.Generic.IEnumerable Select(this System.Collections.Generic.IEnumerable source, System.Func selector) { throw null; } public static bool SequenceEqual(this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second) { throw null; } public static bool SequenceEqual(this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second, System.Collections.Generic.IEqualityComparer? comparer) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TSource SingleOrDefault(this System.Collections.Generic.IEnumerable source) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TSource SingleOrDefault(this System.Collections.Generic.IEnumerable source, System.Func predicate) { throw null; } + public static TSource? SingleOrDefault(this System.Collections.Generic.IEnumerable source) { throw null; } + public static TSource? SingleOrDefault(this System.Collections.Generic.IEnumerable source, System.Func predicate) { throw null; } public static TSource Single(this System.Collections.Generic.IEnumerable source) { throw null; } public static TSource Single(this System.Collections.Generic.IEnumerable source, System.Func predicate) { throw null; } public static System.Collections.Generic.IEnumerable SkipLast(this System.Collections.Generic.IEnumerable source, int count) { throw null; } diff --git a/src/libraries/System.Linq/src/System/Linq/DefaultIfEmpty.cs b/src/libraries/System.Linq/src/System/Linq/DefaultIfEmpty.cs index e358538..a513a6e 100644 --- a/src/libraries/System.Linq/src/System/Linq/DefaultIfEmpty.cs +++ b/src/libraries/System.Linq/src/System/Linq/DefaultIfEmpty.cs @@ -8,7 +8,7 @@ namespace System.Linq { public static partial class Enumerable { - public static IEnumerable DefaultIfEmpty(this IEnumerable source) => + public static IEnumerable DefaultIfEmpty(this IEnumerable source) => DefaultIfEmpty(source, default!); public static IEnumerable DefaultIfEmpty(this IEnumerable source, TSource defaultValue) diff --git a/src/libraries/System.Linq/src/System/Linq/ElementAt.cs b/src/libraries/System.Linq/src/System/Linq/ElementAt.cs index a857819..da8dc8f 100644 --- a/src/libraries/System.Linq/src/System/Linq/ElementAt.cs +++ b/src/libraries/System.Linq/src/System/Linq/ElementAt.cs @@ -51,8 +51,7 @@ namespace System.Linq return default; } - [return: MaybeNull] - public static TSource ElementAtOrDefault(this IEnumerable source, int index) + public static TSource? ElementAtOrDefault(this IEnumerable source, int index) { if (source == null) { @@ -90,7 +89,7 @@ namespace System.Linq } } - return default!; + return default; } } } diff --git a/src/libraries/System.Linq/src/System/Linq/First.cs b/src/libraries/System.Linq/src/System/Linq/First.cs index 6ebeb80..295acb5 100644 --- a/src/libraries/System.Linq/src/System/Linq/First.cs +++ b/src/libraries/System.Linq/src/System/Linq/First.cs @@ -30,16 +30,13 @@ namespace System.Linq return first!; } - [return: MaybeNull] - public static TSource FirstOrDefault(this IEnumerable source) => + public static TSource? FirstOrDefault(this IEnumerable source) => source.TryGetFirst(out bool _); - [return: MaybeNull] - public static TSource FirstOrDefault(this IEnumerable source, Func predicate) => + public static TSource? FirstOrDefault(this IEnumerable source, Func predicate) => source.TryGetFirst(predicate, out bool _); - [return: MaybeNull] - private static TSource TryGetFirst(this IEnumerable source, out bool found) + private static TSource? TryGetFirst(this IEnumerable source, out bool found) { if (source == null) { @@ -72,11 +69,10 @@ namespace System.Linq } found = false; - return default!; + return default; } - [return: MaybeNull] - private static TSource TryGetFirst(this IEnumerable source, Func predicate, out bool found) + private static TSource? TryGetFirst(this IEnumerable source, Func predicate, out bool found) { if (source == null) { @@ -98,7 +94,7 @@ namespace System.Linq } found = false; - return default!; + return default; } } } diff --git a/src/libraries/System.Linq/src/System/Linq/IPartition.cs b/src/libraries/System.Linq/src/System/Linq/IPartition.cs index d1c5e2e..68b676f 100644 --- a/src/libraries/System.Linq/src/System/Linq/IPartition.cs +++ b/src/libraries/System.Linq/src/System/Linq/IPartition.cs @@ -30,23 +30,20 @@ namespace System.Linq /// The 0-based index to access. /// true if the sequence contains an element at that index, false otherwise. /// The element if is true, otherwise, the default value of . - [return: MaybeNull] - TElement TryGetElementAt(int index, out bool found); + TElement? TryGetElementAt(int index, out bool found); /// /// Gets the first item in this sequence. /// /// true if the sequence contains an element, false otherwise. /// The element if is true, otherwise, the default value of . - [return: MaybeNull] - TElement TryGetFirst(out bool found); + TElement? TryGetFirst(out bool found); /// /// Gets the last item in this sequence. /// /// true if the sequence contains an element, false otherwise. /// The element if is true, otherwise, the default value of . - [return: MaybeNull] - TElement TryGetLast(out bool found); + TElement? TryGetLast(out bool found); } } diff --git a/src/libraries/System.Linq/src/System/Linq/Last.cs b/src/libraries/System.Linq/src/System/Linq/Last.cs index d08bbf9..d781961 100644 --- a/src/libraries/System.Linq/src/System/Linq/Last.cs +++ b/src/libraries/System.Linq/src/System/Linq/Last.cs @@ -30,16 +30,13 @@ namespace System.Linq return last!; } - [return: MaybeNull] - public static TSource LastOrDefault(this IEnumerable source) => + public static TSource? LastOrDefault(this IEnumerable source) => source.TryGetLast(out bool _); - [return: MaybeNull] - public static TSource LastOrDefault(this IEnumerable source, Func predicate) => + public static TSource? LastOrDefault(this IEnumerable source, Func predicate) => source.TryGetLast(predicate, out bool _); - [return: MaybeNull] - private static TSource TryGetLast(this IEnumerable source, out bool found) + private static TSource? TryGetLast(this IEnumerable source, out bool found) { if (source == null) { @@ -80,11 +77,10 @@ namespace System.Linq } found = false; - return default!; + return default; } - [return: MaybeNull] - private static TSource TryGetLast(this IEnumerable source, Func predicate, out bool found) + private static TSource? TryGetLast(this IEnumerable source, Func predicate, out bool found) { if (source == null) { @@ -139,7 +135,7 @@ namespace System.Linq } found = false; - return default!; + return default; } } } diff --git a/src/libraries/System.Linq/src/System/Linq/Max.cs b/src/libraries/System.Linq/src/System/Linq/Max.cs index 21e1f8d..9dc4c92 100644 --- a/src/libraries/System.Linq/src/System/Linq/Max.cs +++ b/src/libraries/System.Linq/src/System/Linq/Max.cs @@ -441,8 +441,7 @@ namespace System.Linq return value; } - [return: MaybeNull] - public static TSource Max(this IEnumerable source) + public static TSource? Max(this IEnumerable source) { if (source == null) { @@ -450,7 +449,7 @@ namespace System.Linq } Comparer comparer = Comparer.Default; - TSource value = default!; + TSource? value = default; if (value == null) { using (IEnumerator e = source.GetEnumerator()) @@ -983,8 +982,7 @@ namespace System.Linq return value; } - [return: MaybeNull] - public static TResult Max(this IEnumerable source, Func selector) + public static TResult? Max(this IEnumerable source, Func selector) { if (source == null) { @@ -997,7 +995,7 @@ namespace System.Linq } Comparer comparer = Comparer.Default; - TResult value = default!; + TResult? value = default; if (value == null) { using (IEnumerator e = source.GetEnumerator()) diff --git a/src/libraries/System.Linq/src/System/Linq/Min.cs b/src/libraries/System.Linq/src/System/Linq/Min.cs index b3a7e62..9958c84 100644 --- a/src/libraries/System.Linq/src/System/Linq/Min.cs +++ b/src/libraries/System.Linq/src/System/Linq/Min.cs @@ -399,8 +399,7 @@ namespace System.Linq return value; } - [return: MaybeNull] - public static TSource Min(this IEnumerable source) + public static TSource? Min(this IEnumerable source) { if (source == null) { @@ -408,7 +407,7 @@ namespace System.Linq } Comparer comparer = Comparer.Default; - TSource value = default!; + TSource? value = default; if (value == null) { using (IEnumerator e = source.GetEnumerator()) @@ -899,8 +898,7 @@ namespace System.Linq return value; } - [return: MaybeNull] - public static TResult Min(this IEnumerable source, Func selector) + public static TResult? Min(this IEnumerable source, Func selector) { if (source == null) { @@ -913,7 +911,7 @@ namespace System.Linq } Comparer comparer = Comparer.Default; - TResult value = default!; + TResult? value = default; if (value == null) { using (IEnumerator e = source.GetEnumerator()) diff --git a/src/libraries/System.Linq/src/System/Linq/OrderedEnumerable.SpeedOpt.cs b/src/libraries/System.Linq/src/System/Linq/OrderedEnumerable.SpeedOpt.cs index 5d3946e..b90dbf2 100644 --- a/src/libraries/System.Linq/src/System/Linq/OrderedEnumerable.SpeedOpt.cs +++ b/src/libraries/System.Linq/src/System/Linq/OrderedEnumerable.SpeedOpt.cs @@ -138,8 +138,7 @@ namespace System.Linq public IPartition Take(int count) => new OrderedPartition(this, 0, count - 1); - [return: MaybeNull] - public TElement TryGetElementAt(int index, out bool found) + public TElement? TryGetElementAt(int index, out bool found) { if (index == 0) { @@ -158,11 +157,10 @@ namespace System.Linq } found = false; - return default!; + return default; } - [return: MaybeNull] - public TElement TryGetFirst(out bool found) + public TElement? TryGetFirst(out bool found) { CachingComparer comparer = GetComparer(); using (IEnumerator e = _source.GetEnumerator()) @@ -170,7 +168,7 @@ namespace System.Linq if (!e.MoveNext()) { found = false; - return default!; + return default; } TElement value = e.Current; @@ -189,15 +187,14 @@ namespace System.Linq } } - [return: MaybeNull] - public TElement TryGetLast(out bool found) + public TElement? TryGetLast(out bool found) { using (IEnumerator e = _source.GetEnumerator()) { if (!e.MoveNext()) { found = false; - return default!; + return default; } CachingComparer comparer = GetComparer(); @@ -217,15 +214,14 @@ namespace System.Linq } } - [return: MaybeNull] - public TElement TryGetLast(int minIdx, int maxIdx, out bool found) + public TElement? TryGetLast(int minIdx, int maxIdx, out bool found) { Buffer buffer = new Buffer(_source); int count = buffer._count; if (minIdx >= count) { found = false; - return default!; + return default; } found = true; diff --git a/src/libraries/System.Linq/src/System/Linq/OrderedEnumerable.cs b/src/libraries/System.Linq/src/System/Linq/OrderedEnumerable.cs index 8f985a4..2c8cf01 100644 --- a/src/libraries/System.Linq/src/System/Linq/OrderedEnumerable.cs +++ b/src/libraries/System.Linq/src/System/Linq/OrderedEnumerable.cs @@ -72,8 +72,7 @@ namespace System.Linq IOrderedEnumerable IOrderedEnumerable.CreateOrderedEnumerable(Func keySelector, IComparer? comparer, bool descending) => new OrderedEnumerable(_source, keySelector, comparer, @descending, this); - [return: MaybeNull] - public TElement TryGetLast(Func predicate, out bool found) + public TElement? TryGetLast(Func predicate, out bool found) { CachingComparer comparer = GetComparer(); using (IEnumerator e = _source.GetEnumerator()) @@ -84,7 +83,7 @@ namespace System.Linq if (!e.MoveNext()) { found = false; - return default!; + return default; } value = e.Current; @@ -176,7 +175,7 @@ namespace System.Linq protected readonly Func _keySelector; protected readonly IComparer _comparer; protected readonly bool _descending; - [MaybeNull] protected TKey _lastKey = default!; + protected TKey? _lastKey; public CachingComparer(Func keySelector, IComparer comparer, bool descending) { diff --git a/src/libraries/System.Linq/src/System/Linq/Partition.SpeedOpt.cs b/src/libraries/System.Linq/src/System/Linq/Partition.SpeedOpt.cs index f2f39c0..c46465f 100644 --- a/src/libraries/System.Linq/src/System/Linq/Partition.SpeedOpt.cs +++ b/src/libraries/System.Linq/src/System/Linq/Partition.SpeedOpt.cs @@ -38,7 +38,6 @@ namespace System.Linq public TElement Current => default!; [ExcludeFromCodeCoverage(Justification = "Shouldn't be called, and as undefined can return or throw anything anyway")] - [MaybeNull] object IEnumerator.Current => default!; void IEnumerator.Reset() @@ -55,25 +54,22 @@ namespace System.Linq public IPartition Take(int count) => this; - [return: MaybeNull] - public TElement TryGetElementAt(int index, out bool found) + public TElement? TryGetElementAt(int index, out bool found) { found = false; - return default!; + return default; } - [return: MaybeNull] - public TElement TryGetFirst(out bool found) + public TElement? TryGetFirst(out bool found) { found = false; - return default!; + return default; } - [return: MaybeNull] - public TElement TryGetLast(out bool found) + public TElement? TryGetLast(out bool found) { found = false; - return default!; + return default; } public TElement[] ToArray() => Array.Empty(); @@ -117,8 +113,7 @@ namespace System.Linq return new OrderedPartition(_source, _minIndexInclusive, maxIndex); } - [return: MaybeNull] - public TElement TryGetElementAt(int index, out bool found) + public TElement? TryGetElementAt(int index, out bool found) { if (unchecked((uint)index <= (uint)(_maxIndexInclusive - _minIndexInclusive))) { @@ -126,14 +121,12 @@ namespace System.Linq } found = false; - return default!; + return default; } - [return: MaybeNull] - public TElement TryGetFirst(out bool found) => _source.TryGetElementAt(_minIndexInclusive, out found); + public TElement? TryGetFirst(out bool found) => _source.TryGetElementAt(_minIndexInclusive, out found); - [return: MaybeNull] - public TElement TryGetLast(out bool found) => + public TElement? TryGetLast(out bool found) => _source.TryGetLast(_minIndexInclusive, _maxIndexInclusive, out found); public TElement[] ToArray() => _source.ToArray(_minIndexInclusive, _maxIndexInclusive); @@ -201,8 +194,7 @@ namespace System.Linq return unchecked((uint)maxIndex >= (uint)_maxIndexInclusive) ? this : new ListPartition(_source, _minIndexInclusive, maxIndex); } - [return: MaybeNull] - public TSource TryGetElementAt(int index, out bool found) + public TSource? TryGetElementAt(int index, out bool found) { if (unchecked((uint)index <= (uint)(_maxIndexInclusive - _minIndexInclusive) && index < _source.Count - _minIndexInclusive)) { @@ -211,11 +203,10 @@ namespace System.Linq } found = false; - return default!; + return default; } - [return: MaybeNull] - public TSource TryGetFirst(out bool found) + public TSource? TryGetFirst(out bool found) { if (_source.Count > _minIndexInclusive) { @@ -224,11 +215,10 @@ namespace System.Linq } found = false; - return default!; + return default; } - [return: MaybeNull] - public TSource TryGetLast(out bool found) + public TSource? TryGetLast(out bool found) { int lastIndex = _source.Count - 1; if (lastIndex >= _minIndexInclusive) @@ -238,7 +228,7 @@ namespace System.Linq } found = false; - return default!; + return default; } private int Count @@ -480,8 +470,7 @@ namespace System.Linq return new EnumerablePartition(_source, _minIndexInclusive, maxIndex); } - [return: MaybeNull] - public TSource TryGetElementAt(int index, out bool found) + public TSource? TryGetElementAt(int index, out bool found) { // If the index is negative or >= our max count, return early. if (index >= 0 && (!HasLimit || index < Limit)) @@ -499,11 +488,10 @@ namespace System.Linq } found = false; - return default!; + return default; } - [return: MaybeNull] - public TSource TryGetFirst(out bool found) + public TSource? TryGetFirst(out bool found) { using (IEnumerator en = _source.GetEnumerator()) { @@ -515,11 +503,10 @@ namespace System.Linq } found = false; - return default!; + return default; } - [return: MaybeNull] - public TSource TryGetLast(out bool found) + public TSource? TryGetLast(out bool found) { using (IEnumerator en = _source.GetEnumerator()) { @@ -542,7 +529,7 @@ namespace System.Linq } found = false; - return default!; + return default; } public TSource[] ToArray() diff --git a/src/libraries/System.Linq/src/System/Linq/Repeat.SpeedOpt.cs b/src/libraries/System.Linq/src/System/Linq/Repeat.SpeedOpt.cs index 7cc12d6..3840acd 100644 --- a/src/libraries/System.Linq/src/System/Linq/Repeat.SpeedOpt.cs +++ b/src/libraries/System.Linq/src/System/Linq/Repeat.SpeedOpt.cs @@ -62,8 +62,7 @@ namespace System.Linq return new RepeatIterator(_current, count); } - [return: MaybeNull] - public TResult TryGetElementAt(int index, out bool found) + public TResult? TryGetElementAt(int index, out bool found) { if ((uint)index < (uint)_count) { @@ -72,7 +71,7 @@ namespace System.Linq } found = false; - return default!; + return default; } public TResult TryGetFirst(out bool found) diff --git a/src/libraries/System.Linq/src/System/Linq/Select.SpeedOpt.cs b/src/libraries/System.Linq/src/System/Linq/Select.SpeedOpt.cs index 530f92b..e23cbd4 100644 --- a/src/libraries/System.Linq/src/System/Linq/Select.SpeedOpt.cs +++ b/src/libraries/System.Linq/src/System/Linq/Select.SpeedOpt.cs @@ -133,8 +133,7 @@ namespace System.Linq new SelectListPartitionIterator(_source, _selector, 0, count - 1); } - [return: MaybeNull] - public TResult TryGetElementAt(int index, out bool found) + public TResult? TryGetElementAt(int index, out bool found) { if (unchecked((uint)index < (uint)_source.Length)) { @@ -143,7 +142,7 @@ namespace System.Linq } found = false; - return default!; + return default; } public TResult TryGetFirst(out bool found) @@ -262,8 +261,7 @@ namespace System.Linq return new SelectRangeIterator(_start, _start + count, _selector); } - [return: MaybeNull] - public TResult TryGetElementAt(int index, out bool found) + public TResult? TryGetElementAt(int index, out bool found) { if ((uint)index < (uint)(_end - _start)) { @@ -272,7 +270,7 @@ namespace System.Linq } found = false; - return default!; + return default; } public TResult TryGetFirst(out bool found) @@ -351,8 +349,7 @@ namespace System.Linq return new SelectListPartitionIterator(_source, _selector, 0, count - 1); } - [return: MaybeNull] - public TResult TryGetElementAt(int index, out bool found) + public TResult? TryGetElementAt(int index, out bool found) { if (unchecked((uint)index < (uint)_source.Count)) { @@ -361,11 +358,10 @@ namespace System.Linq } found = false; - return default!; + return default; } - [return: MaybeNull] - public TResult TryGetFirst(out bool found) + public TResult? TryGetFirst(out bool found) { if (_source.Count != 0) { @@ -374,11 +370,10 @@ namespace System.Linq } found = false; - return default!; + return default; } - [return: MaybeNull] - public TResult TryGetLast(out bool found) + public TResult? TryGetLast(out bool found) { int len = _source.Count; if (len != 0) @@ -388,7 +383,7 @@ namespace System.Linq } found = false; - return default!; + return default; } } @@ -453,8 +448,7 @@ namespace System.Linq return new SelectListPartitionIterator(_source, _selector, 0, count - 1); } - [return: MaybeNull] - public TResult TryGetElementAt(int index, out bool found) + public TResult? TryGetElementAt(int index, out bool found) { if (unchecked((uint)index < (uint)_source.Count)) { @@ -463,11 +457,10 @@ namespace System.Linq } found = false; - return default!; + return default; } - [return: MaybeNull] - public TResult TryGetFirst(out bool found) + public TResult? TryGetFirst(out bool found) { if (_source.Count != 0) { @@ -476,11 +469,10 @@ namespace System.Linq } found = false; - return default!; + return default; } - [return: MaybeNull] - public TResult TryGetLast(out bool found) + public TResult? TryGetLast(out bool found) { int len = _source.Count; if (len != 0) @@ -490,7 +482,7 @@ namespace System.Linq } found = false; - return default!; + return default; } } @@ -565,8 +557,7 @@ namespace System.Linq return new SelectIPartitionIterator(_source.Take(count), _selector); } - [return: MaybeNull] - public TResult TryGetElementAt(int index, out bool found) + public TResult? TryGetElementAt(int index, out bool found) { bool sourceFound; TSource input = _source.TryGetElementAt(index, out sourceFound); @@ -574,8 +565,7 @@ namespace System.Linq return sourceFound ? _selector(input!) : default!; } - [return: MaybeNull] - public TResult TryGetFirst(out bool found) + public TResult? TryGetFirst(out bool found) { bool sourceFound; TSource input = _source.TryGetFirst(out sourceFound); @@ -583,8 +573,7 @@ namespace System.Linq return sourceFound ? _selector(input!) : default!; } - [return: MaybeNull] - public TResult TryGetLast(out bool found) + public TResult? TryGetLast(out bool found) { bool sourceFound; TSource input = _source.TryGetLast(out sourceFound); @@ -739,8 +728,7 @@ namespace System.Linq return (uint)maxIndex >= (uint)_maxIndexInclusive ? this : new SelectListPartitionIterator(_source, _selector, _minIndexInclusive, maxIndex); } - [return: MaybeNull] - public TResult TryGetElementAt(int index, out bool found) + public TResult? TryGetElementAt(int index, out bool found) { if ((uint)index <= (uint)(_maxIndexInclusive - _minIndexInclusive) && index < _source.Count - _minIndexInclusive) { @@ -749,11 +737,10 @@ namespace System.Linq } found = false; - return default!; + return default; } - [return: MaybeNull] - public TResult TryGetFirst(out bool found) + public TResult? TryGetFirst(out bool found) { if (_source.Count > _minIndexInclusive) { @@ -762,11 +749,10 @@ namespace System.Linq } found = false; - return default!; + return default; } - [return: MaybeNull] - public TResult TryGetLast(out bool found) + public TResult? TryGetLast(out bool found) { int lastIndex = _source.Count - 1; if (lastIndex >= _minIndexInclusive) @@ -776,7 +762,7 @@ namespace System.Linq } found = false; - return default!; + return default; } private int Count diff --git a/src/libraries/System.Linq/src/System/Linq/Single.cs b/src/libraries/System.Linq/src/System/Linq/Single.cs index 7640bc7..913405d 100644 --- a/src/libraries/System.Linq/src/System/Linq/Single.cs +++ b/src/libraries/System.Linq/src/System/Linq/Single.cs @@ -83,8 +83,7 @@ namespace System.Linq return default; } - [return: MaybeNull] - public static TSource SingleOrDefault(this IEnumerable source) + public static TSource? SingleOrDefault(this IEnumerable source) { if (source == null) { @@ -96,7 +95,7 @@ namespace System.Linq switch (list.Count) { case 0: - return default!; + return default; case 1: return list[0]; } @@ -107,7 +106,7 @@ namespace System.Linq { if (!e.MoveNext()) { - return default!; + return default; } TSource result = e.Current; @@ -122,8 +121,7 @@ namespace System.Linq return default; } - [return: MaybeNull] - public static TSource SingleOrDefault(this IEnumerable source, Func predicate) + public static TSource? SingleOrDefault(this IEnumerable source, Func predicate) { if (source == null) { @@ -155,7 +153,7 @@ namespace System.Linq } } - return default!; + return default; } } } diff --git a/src/libraries/System.Memory/src/System/Buffers/ReadOnlySequence.cs b/src/libraries/System.Memory/src/System/Buffers/ReadOnlySequence.cs index 273a970..7fd6b13 100644 --- a/src/libraries/System.Memory/src/System/Buffers/ReadOnlySequence.cs +++ b/src/libraries/System.Memory/src/System/Buffers/ReadOnlySequence.cs @@ -17,8 +17,8 @@ namespace System.Buffers public readonly partial struct ReadOnlySequence { // The data is essentially two SequencePositions, however the Start and End SequencePositions are deconstructed to improve packing. - [AllowNull] private readonly object? _startObject; - [AllowNull] private readonly object? _endObject; + private readonly object? _startObject; + private readonly object? _endObject; private readonly int _startInteger; private readonly int _endInteger; diff --git a/src/libraries/System.Net.Http.Json/ref/System.Net.Http.Json.cs b/src/libraries/System.Net.Http.Json/ref/System.Net.Http.Json.cs index c8d7a3c..34e35f7 100644 --- a/src/libraries/System.Net.Http.Json/ref/System.Net.Http.Json.cs +++ b/src/libraries/System.Net.Http.Json/ref/System.Net.Http.Json.cs @@ -12,10 +12,10 @@ namespace System.Net.Http.Json public static System.Threading.Tasks.Task GetFromJsonAsync(this System.Net.Http.HttpClient client, string? requestUri, System.Type type, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public static System.Threading.Tasks.Task GetFromJsonAsync(this System.Net.Http.HttpClient client, System.Uri? requestUri, System.Type type, System.Text.Json.JsonSerializerOptions? options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public static System.Threading.Tasks.Task GetFromJsonAsync(this System.Net.Http.HttpClient client, System.Uri? requestUri, System.Type type, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public static System.Threading.Tasks.Task GetFromJsonAsync(this System.Net.Http.HttpClient client, string? requestUri, System.Text.Json.JsonSerializerOptions? options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public static System.Threading.Tasks.Task GetFromJsonAsync(this System.Net.Http.HttpClient client, string? requestUri, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public static System.Threading.Tasks.Task GetFromJsonAsync(this System.Net.Http.HttpClient client, System.Uri? requestUri, System.Text.Json.JsonSerializerOptions? options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public static System.Threading.Tasks.Task GetFromJsonAsync(this System.Net.Http.HttpClient client, System.Uri? requestUri, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static System.Threading.Tasks.Task GetFromJsonAsync(this System.Net.Http.HttpClient client, string? requestUri, System.Text.Json.JsonSerializerOptions? options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static System.Threading.Tasks.Task GetFromJsonAsync(this System.Net.Http.HttpClient client, string? requestUri, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static System.Threading.Tasks.Task GetFromJsonAsync(this System.Net.Http.HttpClient client, System.Uri? requestUri, System.Text.Json.JsonSerializerOptions? options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static System.Threading.Tasks.Task GetFromJsonAsync(this System.Net.Http.HttpClient client, System.Uri? requestUri, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public static System.Threading.Tasks.Task PostAsJsonAsync(this System.Net.Http.HttpClient client, string? requestUri, TValue value, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public static System.Threading.Tasks.Task PostAsJsonAsync(this System.Net.Http.HttpClient client, string? requestUri, TValue value, System.Threading.CancellationToken cancellationToken) { throw null; } public static System.Threading.Tasks.Task PostAsJsonAsync(this System.Net.Http.HttpClient client, System.Uri? requestUri, TValue value, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } @@ -28,7 +28,7 @@ namespace System.Net.Http.Json public static partial class HttpContentJsonExtensions { public static System.Threading.Tasks.Task ReadFromJsonAsync(this System.Net.Http.HttpContent content, System.Type type, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public static System.Threading.Tasks.Task ReadFromJsonAsync(this System.Net.Http.HttpContent content, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static System.Threading.Tasks.Task ReadFromJsonAsync(this System.Net.Http.HttpContent content, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } public sealed partial class JsonContent : System.Net.Http.HttpContent { diff --git a/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpClientJsonExtensions.Get.cs b/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpClientJsonExtensions.Get.cs index dd50490..908b5bc 100644 --- a/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpClientJsonExtensions.Get.cs +++ b/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpClientJsonExtensions.Get.cs @@ -34,7 +34,7 @@ namespace System.Net.Http.Json return GetFromJsonAsyncCore(taskResponse, type, options, cancellationToken); } - public static Task GetFromJsonAsync(this HttpClient client, string? requestUri, JsonSerializerOptions? options, CancellationToken cancellationToken = default) + public static Task GetFromJsonAsync(this HttpClient client, string? requestUri, JsonSerializerOptions? options, CancellationToken cancellationToken = default) { if (client == null) { @@ -45,7 +45,7 @@ namespace System.Net.Http.Json return GetFromJsonAsyncCore(taskResponse, options, cancellationToken); } - public static Task GetFromJsonAsync(this HttpClient client, Uri? requestUri, JsonSerializerOptions? options, CancellationToken cancellationToken = default) + public static Task GetFromJsonAsync(this HttpClient client, Uri? requestUri, JsonSerializerOptions? options, CancellationToken cancellationToken = default) { if (client == null) { @@ -62,10 +62,10 @@ namespace System.Net.Http.Json public static Task GetFromJsonAsync(this HttpClient client, Uri? requestUri, Type type, CancellationToken cancellationToken = default) => client.GetFromJsonAsync(requestUri, type, options: null, cancellationToken); - public static Task GetFromJsonAsync(this HttpClient client, string? requestUri, CancellationToken cancellationToken = default) + public static Task GetFromJsonAsync(this HttpClient client, string? requestUri, CancellationToken cancellationToken = default) => client.GetFromJsonAsync(requestUri, options: null, cancellationToken); - public static Task GetFromJsonAsync(this HttpClient client, Uri? requestUri, CancellationToken cancellationToken = default) + public static Task GetFromJsonAsync(this HttpClient client, Uri? requestUri, CancellationToken cancellationToken = default) => client.GetFromJsonAsync(requestUri, options: null, cancellationToken); private static async Task GetFromJsonAsyncCore(Task taskResponse, Type type, JsonSerializerOptions? options, CancellationToken cancellationToken) @@ -80,7 +80,7 @@ namespace System.Net.Http.Json } } - private static async Task GetFromJsonAsyncCore(Task taskResponse, JsonSerializerOptions? options, CancellationToken cancellationToken) + private static async Task GetFromJsonAsyncCore(Task taskResponse, JsonSerializerOptions? options, CancellationToken cancellationToken) { using (HttpResponseMessage response = await taskResponse.ConfigureAwait(false)) { diff --git a/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.cs b/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.cs index 753c031..e73c6fb 100644 --- a/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.cs +++ b/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.cs @@ -21,7 +21,7 @@ namespace System.Net.Http.Json return ReadFromJsonAsyncCore(content, type, sourceEncoding, options, cancellationToken); } - public static Task ReadFromJsonAsync(this HttpContent content, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default) + public static Task ReadFromJsonAsync(this HttpContent content, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default) { ValidateContent(content); Debug.Assert(content.Headers.ContentType != null); @@ -46,7 +46,7 @@ namespace System.Net.Http.Json } } - private static async Task ReadFromJsonAsyncCore(HttpContent content, Encoding? sourceEncoding, JsonSerializerOptions? options, CancellationToken cancellationToken) + private static async Task ReadFromJsonAsyncCore(HttpContent content, Encoding? sourceEncoding, JsonSerializerOptions? options, CancellationToken cancellationToken) { Stream contentStream = await ReadHttpContentStreamAsync(content, cancellationToken).ConfigureAwait(false); diff --git a/src/libraries/System.Net.Http/tests/StressTests/HttpStress/StressClient.cs b/src/libraries/System.Net.Http/tests/StressTests/HttpStress/StressClient.cs index 415ccbd..9e1b3a3 100644 --- a/src/libraries/System.Net.Http/tests/StressTests/HttpStress/StressClient.cs +++ b/src/libraries/System.Net.Http/tests/StressTests/HttpStress/StressClient.cs @@ -452,7 +452,7 @@ namespace HttpStress private class StructuralEqualityComparer : IEqualityComparer where T : IStructuralEquatable { - public bool Equals([AllowNull] T left, [AllowNull] T right) => left != null && left.Equals(right, StructuralComparisons.StructuralEqualityComparer); + public bool Equals(T? left, T? right) => left != null && left.Equals(right, StructuralComparisons.StructuralEqualityComparer); public int GetHashCode(T value) => value.GetHashCode(StructuralComparisons.StructuralEqualityComparer); } } diff --git a/src/libraries/System.Net.Security/src/System/Security/Authentication/ExtendedProtection/ServiceNameCollection.cs b/src/libraries/System.Net.Security/src/System/Security/Authentication/ExtendedProtection/ServiceNameCollection.cs index 7bfa4f7..8797f31 100644 --- a/src/libraries/System.Net.Security/src/System/Security/Authentication/ExtendedProtection/ServiceNameCollection.cs +++ b/src/libraries/System.Net.Security/src/System/Security/Authentication/ExtendedProtection/ServiceNameCollection.cs @@ -133,7 +133,7 @@ namespace System.Security.Authentication.ExtendedProtection /// /// Normalize, check for duplicates, and add if the value is unique. /// - private void AddIfNew([MaybeNull]string serviceName) + private void AddIfNew(string serviceName) { if (string.IsNullOrEmpty(serviceName)) { @@ -164,6 +164,7 @@ namespace System.Security.Authentication.ExtendedProtection // prefix/host:port // prefix/host/DistinguishedName // prefix/host:port/DistinguishedName + [return: NotNullIfNotNull("inputServiceName")] private static string? NormalizeServiceName(string? inputServiceName) { if (string.IsNullOrWhiteSpace(inputServiceName)) diff --git a/src/libraries/System.ObjectModel/src/System/Collections/ObjectModel/KeyedCollection.cs b/src/libraries/System.ObjectModel/src/System/Collections/ObjectModel/KeyedCollection.cs index 93cd10b..3c0c0a4 100644 --- a/src/libraries/System.ObjectModel/src/System/Collections/ObjectModel/KeyedCollection.cs +++ b/src/libraries/System.ObjectModel/src/System/Collections/ObjectModel/KeyedCollection.cs @@ -114,7 +114,7 @@ namespace System.Collections.ObjectModel } } - item = default(TItem)!; + item = default; return false; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Action.cs b/src/libraries/System.Private.CoreLib/src/System/Action.cs index 539e5fd..dacc4fa 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Action.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Action.cs @@ -23,7 +23,10 @@ namespace System public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15); public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16); - public delegate int Comparison([AllowNull] T x, [AllowNull] T y); + // This should probably technically be T? rather than T to match `IComparer`. However, the use cases are generally different, + // with Comparison typically being used via a lambda, with the T inferred from the type of the collection being sorted, + // and forcing nullable warnings onto all such usage leads to many spurious warnings. + public delegate int Comparison(T x, T y); public delegate TOutput Converter(TInput input); diff --git a/src/libraries/System.Private.CoreLib/src/System/Array.cs b/src/libraries/System.Private.CoreLib/src/System/Array.cs index 030e8e2..1e0fca6 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Array.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Array.cs @@ -752,8 +752,7 @@ namespace System } } - [return: MaybeNull] - public static T Find(T[] array, Predicate match) + public static T? Find(T[] array, Predicate match) { if (array == null) { @@ -772,7 +771,7 @@ namespace System return array[i]; } } - return default!; + return default; } public static T[] FindAll(T[] array, Predicate match) @@ -849,8 +848,7 @@ namespace System return -1; } - [return: MaybeNull] - public static T FindLast(T[] array, Predicate match) + public static T? FindLast(T[] array, Predicate match) { if (array == null) { @@ -869,7 +867,7 @@ namespace System return array[i]; } } - return default!; + return default; } public static int FindLastIndex(T[] array, Predicate match) diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueue.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueue.cs index 76f0ea2..08eb093 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueue.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueue.cs @@ -689,7 +689,7 @@ namespace System.Collections.Concurrent // check and this check, another item could have arrived). if (head._nextSegment == null) { - item = default!; + item = default; return false; } @@ -783,7 +783,7 @@ namespace System.Collections.Concurrent // and we'll traverse to that segment. } - result = default!; + result = default; return false; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueueSegment.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueueSegment.cs index 56a758e..1cd8235 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueueSegment.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueueSegment.cs @@ -173,7 +173,7 @@ namespace System.Collections.Concurrent int currentTail = Volatile.Read(ref _headAndTail.Tail); if (currentTail - currentHead <= 0 || (frozen && (currentTail - FreezeOffset - currentHead <= 0))) { - item = default!; + item = default; return false; } @@ -234,7 +234,7 @@ namespace System.Collections.Concurrent int currentTail = Volatile.Read(ref _headAndTail.Tail); if (currentTail - currentHead <= 0 || (frozen && (currentTail - FreezeOffset - currentHead <= 0))) { - result = default!; + result = default; return false; } @@ -311,7 +311,7 @@ namespace System.Collections.Concurrent internal struct Slot { /// The item. - [AllowNull, MaybeNull] public T Item; // SOS's ThreadPool command depends on this being at the beginning of the struct when T is a reference type + public T? Item; // SOS's ThreadPool command depends on this being at the beginning of the struct when T is a reference type /// The sequence number for this slot, used to synchronize between enqueuers and dequeuers. public int SequenceNumber; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Comparer.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Comparer.cs index 0b4f12d..2ee414a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Comparer.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Comparer.cs @@ -21,7 +21,7 @@ namespace System.Collections.Generic return new ComparisonComparer(comparison); } - public abstract int Compare([AllowNull] T x, [AllowNull] T y); + public abstract int Compare(T? x, T? y); int IComparer.Compare(object? x, object? y) { @@ -42,10 +42,7 @@ namespace System.Collections.Generic _comparison = comparison; } - public override int Compare([AllowNull] T x, [AllowNull] T y) - { - return _comparison(x, y); - } + public override int Compare(T? x, T? y) => _comparison(x!, y!); } // Note: although there is a lot of shared code in the following @@ -58,7 +55,7 @@ namespace System.Collections.Generic // Needs to be public to support binary serialization compatibility public sealed partial class GenericComparer : Comparer where T : IComparable { - public override int Compare([AllowNull] T x, [AllowNull] T y) + public override int Compare(T? x, T? y) { if (x != null) { @@ -106,7 +103,7 @@ namespace System.Collections.Generic // Needs to be public to support binary serialization compatibility public sealed partial class ObjectComparer : Comparer { - public override int Compare([AllowNull] T x, [AllowNull] T y) + public override int Compare(T? x, T? y) { return System.Collections.Comparer.Default.Compare(x, y); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs index 6c5682e..39245df 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs @@ -1461,7 +1461,7 @@ namespace System.Collections.Generic private readonly Dictionary _dictionary; private int _index; private readonly int _version; - [AllowNull, MaybeNull] private TKey _currentKey; + private TKey? _currentKey; internal Enumerator(Dictionary dictionary) { @@ -1653,7 +1653,7 @@ namespace System.Collections.Generic private readonly Dictionary _dictionary; private int _index; private readonly int _version; - [AllowNull, MaybeNull] private TValue _currentValue; + private TValue? _currentValue; internal Enumerator(Dictionary dictionary) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs index 6b6830e..180bea6 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs @@ -13,7 +13,7 @@ namespace System.Collections.Generic { // public static EqualityComparer Default is runtime-specific - public abstract bool Equals([AllowNull] T x, [AllowNull] T y); + public abstract bool Equals(T? x, T? y); public abstract int GetHashCode([DisallowNull] T obj); int IEqualityComparer.GetHashCode(object? obj) @@ -42,7 +42,7 @@ namespace System.Collections.Generic public sealed partial class GenericEqualityComparer : EqualityComparer where T : IEquatable { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override bool Equals([AllowNull] T x, [AllowNull] T y) + public override bool Equals(T? x, T? y) { if (x != null) { @@ -100,7 +100,7 @@ namespace System.Collections.Generic public sealed partial class ObjectEqualityComparer : EqualityComparer { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override bool Equals([AllowNull] T x, [AllowNull] T y) + public override bool Equals(T? x, T? y) { if (x != null) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IComparer.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IComparer.cs index 82394ef..59a9b90 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IComparer.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IComparer.cs @@ -14,6 +14,6 @@ namespace System.Collections.Generic // value less than zero if x is less than y, zero if x is equal to y, or a // value greater than zero if x is greater than y. // - int Compare([AllowNull] T x, [AllowNull] T y); + int Compare(T? x, T? y); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IEqualityComparer.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IEqualityComparer.cs index b83b54e..19545c6 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IEqualityComparer.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IEqualityComparer.cs @@ -10,7 +10,7 @@ namespace System.Collections.Generic // It is used in Dictionary class. public interface IEqualityComparer { - bool Equals([AllowNull] T x, [AllowNull] T y); + bool Equals(T? x, T? y); int GetHashCode([DisallowNull] T obj); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs index 13ab166..6da36e0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs @@ -412,8 +412,7 @@ namespace System.Collections.Generic public bool Exists(Predicate match) => FindIndex(match) != -1; - [return: MaybeNull] - public T Find(Predicate match) + public T? Find(Predicate match) { if (match == null) { @@ -427,7 +426,7 @@ namespace System.Collections.Generic return _items[i]; } } - return default!; + return default; } public List FindAll(Predicate match) @@ -479,8 +478,7 @@ namespace System.Collections.Generic return -1; } - [return: MaybeNull] - public T FindLast(Predicate match) + public T? FindLast(Predicate match) { if (match == null) { @@ -494,7 +492,7 @@ namespace System.Collections.Generic return _items[i]; } } - return default!; + return default; } public int FindLastIndex(Predicate match) @@ -1077,7 +1075,7 @@ namespace System.Collections.Generic private readonly List _list; private int _index; private readonly int _version; - [AllowNull, MaybeNull] private T _current; + private T? _current; internal Enumerator(List list) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/Collection.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/Collection.cs index 2f2676a..fcafafe 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/Collection.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/Collection.cs @@ -244,7 +244,7 @@ namespace System.Collections.ObjectModel { ThrowHelper.IfNullAndNullsAreIllegalThenThrow(value, ExceptionArgument.value); - T item = default!; + T? item = default; try { @@ -285,7 +285,7 @@ namespace System.Collections.ObjectModel } ThrowHelper.IfNullAndNullsAreIllegalThenThrow(value, ExceptionArgument.value); - T item = default!; + T? item = default; try { @@ -327,7 +327,7 @@ namespace System.Collections.ObjectModel } ThrowHelper.IfNullAndNullsAreIllegalThenThrow(value, ExceptionArgument.value); - T item = default!; + T? item = default; try { diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs index 6c6e22b..6085322 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs @@ -1363,14 +1363,14 @@ namespace System.Diagnostics.Tracing if (m_etwProvider != null) { m_etwProvider.Dispose(); - m_etwProvider = null!; // TODO-NULLABLE: Avoid nulling out in Dispose + m_etwProvider = null!; } #endif #if FEATURE_PERFTRACING if (m_eventPipeProvider != null) { m_eventPipeProvider.Dispose(); - m_eventPipeProvider = null!; // TODO-NULLABLE: Avoid nulling out in Dispose + m_eventPipeProvider = null!; } #endif } diff --git a/src/libraries/System.Private.CoreLib/src/System/IComparable.cs b/src/libraries/System.Private.CoreLib/src/System/IComparable.cs index 3c0f50b..3599bbd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IComparable.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IComparable.cs @@ -33,6 +33,6 @@ namespace System // if this is equal to object, or a value greater than zero // if this is greater than object. // - int CompareTo([AllowNull] T other); + int CompareTo(T? other); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/IEquatable.cs b/src/libraries/System.Private.CoreLib/src/System/IEquatable.cs index 1edba44..89f0771 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IEquatable.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IEquatable.cs @@ -7,6 +7,6 @@ namespace System { public interface IEquatable // invariant due to questionable semantics around equality and inheritance { - bool Equals([AllowNull] T other); + bool Equals(T? other); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Lazy.cs b/src/libraries/System.Private.CoreLib/src/System/Lazy.cs index 4fcfbc9..ac676de 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Lazy.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Lazy.cs @@ -195,7 +195,7 @@ namespace System private Func? _factory; // _value eventually stores the lazily created value. It is valid when _state = null. - private T _value = default!; + private T? _value; /// /// Initializes a new instance of the class that @@ -447,14 +447,13 @@ namespace System } /// Gets the value of the Lazy<T> for debugging display purposes. - [MaybeNull] - internal T ValueForDebugDisplay + internal T? ValueForDebugDisplay { get { if (!IsValueCreated) { - return default!; + return default; } return _value; } @@ -503,7 +502,7 @@ namespace System /// from initialization delegate. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public T Value => _state == null ? _value : CreateValue(); + public T Value => _state == null ? _value! : CreateValue(); } /// A debugger view of the Lazy<T> to surface additional debugging properties and @@ -524,8 +523,7 @@ namespace System public bool IsValueCreated => _lazy.IsValueCreated; /// Returns the value of the Lazy object. - [MaybeNull] - public T Value => _lazy.ValueForDebugDisplay; + public T? Value => _lazy.ValueForDebugDisplay; /// Returns the execution mode of the Lazy object public LazyThreadSafetyMode? Mode => _lazy.Mode; diff --git a/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.cs b/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.cs index baf733b..c43899c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.cs @@ -157,11 +157,11 @@ namespace System.Resources // Close the stream in a thread-safe way. This fix means // that we may call Close n times, but that's safe. BinaryReader copyOfStore = _store; - _store = null!; // TODO-NULLABLE: Avoid nulling out in Dispose + _store = null!; if (copyOfStore != null) copyOfStore.Close(); } - _store = null!; // TODO-NULLABLE: Avoid nulling out in Dispose + _store = null!; _namePositions = null; _nameHashes = null; _ums = null; diff --git a/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceSet.cs b/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceSet.cs index dbb3342..6ad05b6 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceSet.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceSet.cs @@ -29,7 +29,7 @@ namespace System.Resources public class ResourceSet : IDisposable, IEnumerable { protected IResourceReader Reader = null!; - internal Hashtable? Table; // TODO-NULLABLE: Avoid nulling out in Dispose + internal Hashtable? Table; private Hashtable? _caseInsensitiveTable; // For case-insensitive lookups. @@ -90,11 +90,11 @@ namespace System.Resources { // Close the Reader in a thread-safe way. IResourceReader? copyOfReader = Reader; - Reader = null!; // TODO-NULLABLE: Avoid nulling out in Dispose + Reader = null!; if (copyOfReader != null) copyOfReader.Close(); } - Reader = null!; // TODO-NULLABLE: Avoid nulling out in Dispose + Reader = null!; _caseInsensitiveTable = null; Table = null; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Resources/RuntimeResourceSet.cs b/src/libraries/System.Private.CoreLib/src/System/Resources/RuntimeResourceSet.cs index c00ebb2..f6de75e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Resources/RuntimeResourceSet.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Resources/RuntimeResourceSet.cs @@ -175,12 +175,12 @@ namespace System.Resources // for arbitrarily long times, since the object is usually a string // literal that will live for the lifetime of the appdomain. The // value is a ResourceLocator instance, which might cache the object. - private Dictionary? _resCache; // TODO-NULLABLE: Avoid nulling out in Dispose + private Dictionary? _resCache; // For our special load-on-demand reader, cache the cast. The // RuntimeResourceSet's implementation knows how to treat this reader specially. - private ResourceReader? _defaultReader; // TODO-NULLABLE: Avoid nulling out in Dispose + private ResourceReader? _defaultReader; // This is a lookup table for case-insensitive lookups, and may be null. // Consider always using a case-insensitive resource cache, as we don't diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskCache.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskCache.cs index 363371f..1c654cd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskCache.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskCache.cs @@ -45,7 +45,7 @@ namespace System.Runtime.CompilerServices /// Specifies the result type. /// The result for the task. /// The cacheable task. - internal static Task CreateCacheableTask([AllowNull] TResult result) => + internal static Task CreateCacheableTask(TResult? result) => new Task(false, result, (TaskCreationOptions)InternalTaskOptions.DoNotDispose, default); /// Creates an array of cached tasks for the values in the range [INCLUSIVE_MIN,EXCLUSIVE_MAX). diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs index 4a3d1df..70ac433 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @@ -292,8 +292,7 @@ namespace System.Runtime.CompilerServices /// A delegate to the method. private Action? _moveNextAction; /// The state machine itself. - [AllowNull, MaybeNull] - public TStateMachine StateMachine = default; // mutable struct; do not make this readonly. SOS DumpAsync command depends on this name. + public TStateMachine? StateMachine; // mutable struct; do not make this readonly. SOS DumpAsync command depends on this name. /// Captured ExecutionContext with which to invoke ; may be null. public ExecutionContext? Context; @@ -428,7 +427,7 @@ namespace System.Runtime.CompilerServices /// Completes the already initialized task with the specified result. /// The result to use to complete the task. /// The task to complete. - internal static void SetExistingTaskResult(Task task, [AllowNull] TResult result) + internal static void SetExistingTaskResult(Task task, TResult? result) { Debug.Assert(task != null, "Expected non-null task"); diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilderT.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilderT.cs index 1c88475..846c649 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilderT.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilderT.cs @@ -364,8 +364,7 @@ namespace System.Runtime.CompilerServices /// If this box is stored in the cache, the next box in the cache. private StateMachineBox? _next; /// The state machine itself. - [AllowNull, MaybeNull] - public TStateMachine StateMachine = default; + public TStateMachine? StateMachine; /// Gets a box object to use for an operation. This may be a reused, pooled object, or it may be new. [MethodImpl(MethodImplOptions.AggressiveInlining)] // only one caller diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/ConditionalWeakTable.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/ConditionalWeakTable.cs index 8d3b9ad..d5caca5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/ConditionalWeakTable.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/ConditionalWeakTable.cs @@ -552,7 +552,7 @@ namespace System.Runtime.CompilerServices } key = default; - value = default!; + value = default; return false; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.NoCom.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.NoCom.cs index 477717e..ed7d492 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.NoCom.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.NoCom.cs @@ -52,7 +52,7 @@ namespace System.Runtime.InteropServices } [SupportedOSPlatform("windows")] - public static TWrapper CreateWrapperOfType([AllowNull] T o) + public static TWrapper CreateWrapperOfType(T? o) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop); } @@ -122,7 +122,7 @@ namespace System.Runtime.InteropServices } [SupportedOSPlatform("windows")] - public static void GetNativeVariantForObject([AllowNull] T obj, IntPtr pDstNativeVariant) + public static void GetNativeVariantForObject(T? obj, IntPtr pDstNativeVariant) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop); } @@ -146,8 +146,7 @@ namespace System.Runtime.InteropServices } [SupportedOSPlatform("windows")] - [return: MaybeNull] - public static T GetObjectForNativeVariant(IntPtr pSrcNativeVariant) + public static T? GetObjectForNativeVariant(IntPtr pSrcNativeVariant) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs index 40c0396..7a2e976 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs @@ -572,8 +572,7 @@ namespace System.Runtime.InteropServices PtrToStructure(ptr, (object)structure!); } - [return: MaybeNull] - public static T PtrToStructure<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]T>(IntPtr ptr) => (T)PtrToStructure(ptr, typeof(T))!; + public static T? PtrToStructure<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]T>(IntPtr ptr) => (T)PtrToStructure(ptr, typeof(T))!; public static void DestroyStructure(IntPtr ptr) => DestroyStructure(ptr, typeof(T)); diff --git a/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.BinarySearch.cs b/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.BinarySearch.cs index 2da00f9..4b8c912 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.BinarySearch.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.BinarySearch.cs @@ -75,7 +75,7 @@ namespace System } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int CompareTo([AllowNull] T other) => _comparer.Compare(_value, other); + public int CompareTo(T? other) => _comparer.Compare(_value, other); } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/AsyncLocal.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/AsyncLocal.cs index 1a81b1d..288ffbd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/AsyncLocal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/AsyncLocal.cs @@ -86,8 +86,8 @@ namespace System.Threading public readonly struct AsyncLocalValueChangedArgs { - [MaybeNull] public T PreviousValue { get; } - [MaybeNull] public T CurrentValue { get; } + public T? PreviousValue { get; } + public T? CurrentValue { get; } // // If the value changed because we changed to a different ExecutionContext, this is true. If it changed @@ -95,7 +95,7 @@ namespace System.Threading // public bool ThreadContextChanged { get; } - internal AsyncLocalValueChangedArgs([AllowNull] T previousValue, [AllowNull] T currentValue, bool contextChanged) + internal AsyncLocalValueChangedArgs(T? previousValue, T? currentValue, bool contextChanged) { PreviousValue = previousValue!; CurrentValue = currentValue!; diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs index b993f26..32dceb9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs @@ -59,7 +59,7 @@ namespace System.Threading.Tasks public class Task : Task { // The value itself, if set. - [MaybeNull, AllowNull] internal TResult m_result = default!; + internal TResult? m_result; private static readonly TaskFactory s_Factory = new TaskFactory(); @@ -93,7 +93,7 @@ namespace System.Threading.Tasks m_result = result; } - internal Task(bool canceled, [AllowNull] TResult result, TaskCreationOptions creationOptions, CancellationToken ct) + internal Task(bool canceled, TResult? result, TaskCreationOptions creationOptions, CancellationToken ct) : base(canceled, creationOptions, ct) { if (!canceled) @@ -364,7 +364,7 @@ namespace System.Threading.Tasks // internal helper function breaks out logic used by TaskCompletionSource - internal bool TrySetResult([AllowNull] TResult result) + internal bool TrySetResult(TResult? result) { Debug.Assert(m_action == null, "Task.TrySetResult(): non-null m_action"); @@ -1357,7 +1357,7 @@ namespace System.Threading.Tasks m_task = task; } - [MaybeNull] public TResult Result => m_task.Status == TaskStatus.RanToCompletion ? m_task.Result : default!; + public TResult? Result => m_task.Status == TaskStatus.RanToCompletion ? m_task.Result : default; public object? AsyncState => m_task.AsyncState; public TaskCreationOptions CreationOptions => m_task.CreationOptions; public Exception? Exception => m_task.Exception; diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ProducerConsumerQueues.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ProducerConsumerQueues.cs index f067ffd..b1ef1c1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ProducerConsumerQueues.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ProducerConsumerQueues.cs @@ -239,7 +239,7 @@ namespace System.Threading.Tasks if (first == segment.m_state.m_last) { - result = default!; + result = default; return false; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Sources/ManualResetValueTaskSourceCore.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Sources/ManualResetValueTaskSourceCore.cs index 8a4a2db..b9caa53 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Sources/ManualResetValueTaskSourceCore.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Sources/ManualResetValueTaskSourceCore.cs @@ -31,7 +31,7 @@ namespace System.Threading.Tasks.Sources /// Whether the current operation has completed. private bool _completed; /// The result with which the operation succeeded, or the default value if it hasn't yet completed or failed. - [AllowNull, MaybeNull] private TResult _result; + private TResult? _result; /// The exception with which the operation failed, or null if it hasn't yet completed or completed successfully. private ExceptionDispatchInfo? _error; /// The current version of this value, used to help prevent misuse. @@ -98,7 +98,7 @@ namespace System.Threading.Tasks.Sources } _error?.Throw(); - return _result; + return _result!; } /// Schedules the continuation action for this operation. diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs index 7a04c04..afc8f5a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs @@ -445,7 +445,7 @@ namespace System.Threading.Tasks /// null if has the result, otherwise a or a . internal readonly object? _obj; /// The result to be used if the operation completed successfully synchronously. - [AllowNull] internal readonly TResult _result; + internal readonly TResult? _result; /// Opaque value passed through to the . internal readonly short _token; /// true to continue on the captured context; otherwise, false. @@ -508,7 +508,7 @@ namespace System.Threading.Tasks /// The token. /// true to continue on captured context; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - private ValueTask(object? obj, TResult result, short token, bool continueOnCapturedContext) + private ValueTask(object? obj, TResult? result, short token, bool continueOnCapturedContext) { _obj = obj; _result = result; @@ -556,7 +556,7 @@ namespace System.Threading.Tasks if (obj == null) { - return AsyncTaskMethodBuilder.GetTaskForResult(_result); + return AsyncTaskMethodBuilder.GetTaskForResult(_result!); } if (obj is Task t) @@ -781,7 +781,7 @@ namespace System.Threading.Tasks if (obj == null) { - return _result; + return _result!; } if (obj is Task t) diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadLocal.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadLocal.cs index 2d0c67c..4d7188e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadLocal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadLocal.cs @@ -305,8 +305,7 @@ namespace System.Threading } } - [return: MaybeNull] - private T GetValueSlow() + private T? GetValueSlow() { // If the object has been disposed, the id will be -1. int id = ~_idComplement; @@ -538,8 +537,7 @@ namespace System.Threading /// Gets the value of the ThreadLocal<T> for debugging display purposes. It takes care of getting /// the value for the current thread in the ThreadLocal mode. - [MaybeNull] - internal T ValueForDebugDisplay + internal T? ValueForDebugDisplay { get { @@ -548,7 +546,7 @@ namespace System.Threading LinkedSlot? slot; if (slotArray == null || id >= slotArray.Length || (slot = slotArray[id].Value) == null || !_initialized) - return default!; + return default; return slot._value; } } @@ -672,7 +670,7 @@ namespace System.Threading internal volatile LinkedSlotVolatile[]? _slotArray; // The value for this slot. - [AllowNull, MaybeNull] internal T _value = default; + internal T? _value; } /// @@ -804,8 +802,7 @@ namespace System.Threading public bool IsValueCreated => _tlocal.IsValueCreated; /// Returns the value of the ThreadLocal object. - [MaybeNull] - public T Value => _tlocal.ValueForDebugDisplay; + public T? Value => _tlocal.ValueForDebugDisplay; /// Return all values for all threads that have accessed this instance. public List? Values => _tlocal.ValuesForDebugDisplay; diff --git a/src/libraries/System.Private.CoreLib/src/System/Type.Helpers.cs b/src/libraries/System.Private.CoreLib/src/System/Type.Helpers.cs index 491f7ac..d28dcd8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Type.Helpers.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Type.Helpers.cs @@ -304,7 +304,7 @@ namespace System { for (i = 0; i < e.Length; i++) if (e[i] != null) - ret[cnt++] = e[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644) + ret[cnt++] = e[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644) } // Copy the Types @@ -312,7 +312,7 @@ namespace System { for (i = 0; i < t.Length; i++) if (t[i] != null) - ret[cnt++] = t[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644) + ret[cnt++] = t[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644) } return ret; diff --git a/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/EnumerableExtensions.cs b/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/EnumerableExtensions.cs index aaec606..99545a0 100644 --- a/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/EnumerableExtensions.cs +++ b/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/EnumerableExtensions.cs @@ -13,8 +13,7 @@ namespace System.Reflection.Internal /// internal static class EnumerableExtensions { - [return: MaybeNull] - public static T FirstOrDefault(this ImmutableArray collection, Func predicate) + public static T? FirstOrDefault(this ImmutableArray collection, Func predicate) { foreach (var item in collection) { @@ -24,7 +23,7 @@ namespace System.Reflection.Internal } } - return default!; + return default; } // used only in debugger display so we needn't get fancy with optimizations. diff --git a/src/libraries/System.Runtime.CompilerServices.Unsafe/ref/System.Runtime.CompilerServices.Unsafe.cs b/src/libraries/System.Runtime.CompilerServices.Unsafe/ref/System.Runtime.CompilerServices.Unsafe.cs index 7c9d4fc..f495874 100644 --- a/src/libraries/System.Runtime.CompilerServices.Unsafe/ref/System.Runtime.CompilerServices.Unsafe.cs +++ b/src/libraries/System.Runtime.CompilerServices.Unsafe/ref/System.Runtime.CompilerServices.Unsafe.cs @@ -17,10 +17,9 @@ namespace System.Runtime.CompilerServices public unsafe static ref T AsRef(void* source) { throw null; } public static ref T AsRef(in T source) { throw null; } #if NETSTANDARD2_1 - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("o")] #endif - public static T As(object? o) where T : class? { throw null; } + public static T? As(object? o) where T : class? { throw null; } public static ref TTo As(ref TFrom source) { throw null; } public static System.IntPtr ByteOffset(ref T origin, ref T target) { throw null; } public static void CopyBlock(ref byte destination, ref byte source, uint byteCount) { } diff --git a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs index 67b487c..7bc7065 100644 --- a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs +++ b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs @@ -500,7 +500,7 @@ namespace System.Runtime.InteropServices [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute("o")] public static object? CreateWrapperOfType(object? o, System.Type t) { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] - public static TWrapper CreateWrapperOfType([System.Diagnostics.CodeAnalysis.AllowNullAttribute] T o) { throw null; } + public static TWrapper CreateWrapperOfType(T? o) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static void DestroyStructure(System.IntPtr ptr, System.Type structuretype) { } public static void DestroyStructure(System.IntPtr ptr) { } @@ -548,7 +548,7 @@ namespace System.Runtime.InteropServices public static void GetNativeVariantForObject(object? obj, System.IntPtr pDstNativeVariant) { } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public static void GetNativeVariantForObject([System.Diagnostics.CodeAnalysis.AllowNullAttribute] T obj, System.IntPtr pDstNativeVariant) { } + public static void GetNativeVariantForObject(T? obj, System.IntPtr pDstNativeVariant) { } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] public static object GetObjectForIUnknown(System.IntPtr pUnk) { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] @@ -556,8 +556,7 @@ namespace System.Runtime.InteropServices public static object? GetObjectForNativeVariant(System.IntPtr pSrcNativeVariant) { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T GetObjectForNativeVariant(System.IntPtr pSrcNativeVariant) { throw null; } + public static T? GetObjectForNativeVariant(System.IntPtr pSrcNativeVariant) { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static object?[] GetObjectsForNativeVariants(System.IntPtr aSrcNativeVariant, int cVars) { throw null; } @@ -594,8 +593,7 @@ namespace System.Runtime.InteropServices public static void PtrToStructure(System.IntPtr ptr, object structure) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static object? PtrToStructure(System.IntPtr ptr, System.Type structureType) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T PtrToStructure(System.IntPtr ptr) { throw null; } + public static T? PtrToStructure(System.IntPtr ptr) { throw null; } public static void PtrToStructure(System.IntPtr ptr, [System.Diagnostics.CodeAnalysis.DisallowNullAttribute] T structure) { } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] public static int QueryInterface(System.IntPtr pUnk, ref System.Guid iid, out System.IntPtr ppv) { throw null; } diff --git a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectWriter.cs b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectWriter.cs index 8ecc282..d4207fb 100644 --- a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectWriter.cs +++ b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectWriter.cs @@ -159,7 +159,7 @@ namespace System.Runtime.Serialization.Formatters.Binary { Type type = memberTypes[i] != null ? memberTypes[i] : - memberData[i] != null ? GetType(memberData[i]!) : // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/34644 + memberData[i] != null ? GetType(memberData[i]!) : // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644) Converter.s_typeofObject; InternalPrimitiveTypeE code = ToCode(type); @@ -170,7 +170,7 @@ namespace System.Runtime.Serialization.Formatters.Binary if (memberData[i] != null) { memberObjectInfos[i] = WriteObjectInfo.Serialize( - memberData[i]!, // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/34644 + memberData[i]!, // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644) _surrogates, _context, _serObjectInfoInit, diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index aaaf4da..8ebce34 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -343,10 +343,8 @@ namespace System public static int FindLastIndex(T[] array, int startIndex, int count, System.Predicate match) { throw null; } public static int FindLastIndex(T[] array, int startIndex, System.Predicate match) { throw null; } public static int FindLastIndex(T[] array, System.Predicate match) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T FindLast(T[] array, System.Predicate match) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static T Find(T[] array, System.Predicate match) { throw null; } + public static T? FindLast(T[] array, System.Predicate match) { throw null; } + public static T? Find(T[] array, System.Predicate match) { throw null; } public static void ForEach(T[] array, System.Action action) { } public System.Collections.IEnumerator GetEnumerator() { throw null; } public int GetLength(int dimension) { throw null; } @@ -816,7 +814,7 @@ namespace System public CLSCompliantAttribute(bool isCompliant) { } public bool IsCompliant { get { throw null; } } } - public delegate int Comparison([System.Diagnostics.CodeAnalysis.AllowNullAttribute] T x, [System.Diagnostics.CodeAnalysis.AllowNullAttribute] T y); + public delegate int Comparison(T x, T y); public abstract partial class ContextBoundObject : System.MarshalByRefObject { protected ContextBoundObject() { } @@ -2298,7 +2296,7 @@ namespace System } public partial interface IComparable { - int CompareTo([System.Diagnostics.CodeAnalysis.AllowNullAttribute] T other); + int CompareTo(T? other); } [System.CLSCompliantAttribute(false)] public partial interface IConvertible @@ -2331,7 +2329,7 @@ namespace System } public partial interface IEquatable { - bool Equals([System.Diagnostics.CodeAnalysis.AllowNullAttribute] T other); + bool Equals(T? other); } public partial interface IFormatProvider { @@ -5375,7 +5373,7 @@ namespace System.Collections.Generic } public partial interface IComparer { - int Compare([System.Diagnostics.CodeAnalysis.AllowNullAttribute] T x, [System.Diagnostics.CodeAnalysis.AllowNullAttribute] T y); + int Compare(T? x, T? y); } public partial interface IDictionary : System.Collections.Generic.ICollection>, System.Collections.Generic.IEnumerable>, System.Collections.IEnumerable { @@ -5397,7 +5395,7 @@ namespace System.Collections.Generic } public partial interface IEqualityComparer { - bool Equals([System.Diagnostics.CodeAnalysis.AllowNullAttribute] T x, [System.Diagnostics.CodeAnalysis.AllowNullAttribute] T y); + bool Equals(T? x, T? y); int GetHashCode([System.Diagnostics.CodeAnalysis.DisallowNullAttribute] T obj); } public partial interface IList : System.Collections.Generic.ICollection, System.Collections.Generic.IEnumerable, System.Collections.IEnumerable diff --git a/src/libraries/System.Security.Cryptography.Cng/ref/System.Security.Cryptography.Cng.cs b/src/libraries/System.Security.Cryptography.Cng/ref/System.Security.Cryptography.Cng.cs index 9fb5bee..97fbd6c 100644 --- a/src/libraries/System.Security.Cryptography.Cng/ref/System.Security.Cryptography.Cng.cs +++ b/src/libraries/System.Security.Cryptography.Cng/ref/System.Security.Cryptography.Cng.cs @@ -169,7 +169,6 @@ namespace System.Security.Cryptography public System.Security.Cryptography.CngKeyUsages? KeyUsage { get { throw null; } set { } } public System.Security.Cryptography.CngPropertyCollection Parameters { get { throw null; } } public System.IntPtr ParentWindowHandle { get { throw null; } set { } } - [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public System.Security.Cryptography.CngProvider Provider { get { throw null; } set { } } public System.Security.Cryptography.CngUIPolicy? UIPolicy { get { throw null; } set { } } } diff --git a/src/libraries/System.Security.Cryptography.Cng/src/Microsoft/Win32/SafeHandles/NCryptSafeHandles.cs b/src/libraries/System.Security.Cryptography.Cng/src/Microsoft/Win32/SafeHandles/NCryptSafeHandles.cs index 13c292f..2850885 100644 --- a/src/libraries/System.Security.Cryptography.Cng/src/Microsoft/Win32/SafeHandles/NCryptSafeHandles.cs +++ b/src/libraries/System.Security.Cryptography.Cng/src/Microsoft/Win32/SafeHandles/NCryptSafeHandles.cs @@ -98,8 +98,8 @@ namespace Microsoft.Win32.SafeHandles /// /// Wrapper for the _holder field which ensures that we're in a consistent state /// - [MaybeNull] - private SafeNCryptHandle Holder + [DisallowNull] + private SafeNCryptHandle? Holder { get { diff --git a/src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/AnyOS/ManagedPal.cs b/src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/AnyOS/ManagedPal.cs index d9c9f46..94e8c46 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/AnyOS/ManagedPal.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/AnyOS/ManagedPal.cs @@ -67,14 +67,12 @@ namespace Internal.Cryptography.Pal.AnyOS } } - [return: MaybeNull] - public override T GetPrivateKeyForSigning(X509Certificate2 certificate, bool silent) + public override T? GetPrivateKeyForSigning(X509Certificate2 certificate, bool silent) where T : class { return GetPrivateKey(certificate); } - [return: MaybeNull] - public override T GetPrivateKeyForDecryption(X509Certificate2 certificate, bool silent) + public override T? GetPrivateKeyForDecryption(X509Certificate2 certificate, bool silent) where T : class { return GetPrivateKey(certificate); } diff --git a/src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/Windows/PkcsPalWindows.cs b/src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/Windows/PkcsPalWindows.cs index 414f222..a720ce0 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/Windows/PkcsPalWindows.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/Windows/PkcsPalWindows.cs @@ -91,14 +91,12 @@ namespace Internal.Cryptography.Pal.Windows } } - [return: MaybeNull] - public override T GetPrivateKeyForSigning(X509Certificate2 certificate, bool silent) + public override T? GetPrivateKeyForSigning(X509Certificate2 certificate, bool silent) where T : class { return GetPrivateKey(certificate, silent, preferNCrypt: true); } - [return: MaybeNull] - public override T GetPrivateKeyForDecryption(X509Certificate2 certificate, bool silent) + public override T? GetPrivateKeyForDecryption(X509Certificate2 certificate, bool silent) where T : class { return GetPrivateKey(certificate, silent, preferNCrypt: false); } diff --git a/src/libraries/System.Text.Json/ref/System.Text.Json.cs b/src/libraries/System.Text.Json/ref/System.Text.Json.cs index 533f4f4..4184827 100644 --- a/src/libraries/System.Text.Json/ref/System.Text.Json.cs +++ b/src/libraries/System.Text.Json/ref/System.Text.Json.cs @@ -191,13 +191,10 @@ namespace System.Text.Json public static object? Deserialize(string json, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static object? Deserialize(ref System.Text.Json.Utf8JsonReader reader, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream utf8Json, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public static System.Threading.Tasks.ValueTask DeserializeAsync<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] TValue>(System.IO.Stream utf8Json, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TValue Deserialize<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] TValue>(System.ReadOnlySpan utf8Json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TValue Deserialize<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] TValue>(string json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TValue Deserialize<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] TValue>(ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } + public static System.Threading.Tasks.ValueTask DeserializeAsync<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] TValue>(System.IO.Stream utf8Json, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static TValue? Deserialize<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] TValue>(System.ReadOnlySpan utf8Json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } + public static TValue? Deserialize<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] TValue>(string json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } + public static TValue? Deserialize<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] TValue>(ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static string Serialize(object? value, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnWrite)] System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static void Serialize(System.Text.Json.Utf8JsonWriter writer, object? value, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnWrite)] System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { } public static System.Threading.Tasks.Task SerializeAsync(System.IO.Stream utf8Json, object? value, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnWrite)] System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } @@ -211,13 +208,10 @@ namespace System.Text.Json public static object? Deserialize(string json, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static object? Deserialize(ref System.Text.Json.Utf8JsonReader reader, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream utf8Json, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public static System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream utf8Json, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TValue Deserialize(System.ReadOnlySpan utf8Json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TValue Deserialize(string json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public static TValue Deserialize(ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } + public static System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream utf8Json, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static TValue? Deserialize(System.ReadOnlySpan utf8Json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } + public static TValue? Deserialize(string json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } + public static TValue? Deserialize(ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static string Serialize(object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static void Serialize(System.Text.Json.Utf8JsonWriter writer, object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { } public static System.Threading.Tasks.Task SerializeAsync(System.IO.Stream utf8Json, object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } @@ -533,8 +527,7 @@ namespace System.Text.Json.Serialization protected internal JsonConverter() { } public override bool CanConvert(System.Type typeToConvert) { throw null; } public virtual bool HandleNull { get { throw null; } } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public abstract T Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options); + public abstract T? Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options); public abstract void Write(System.Text.Json.Utf8JsonWriter writer, T value, System.Text.Json.JsonSerializerOptions options); } [System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Property | System.AttributeTargets.Field, AllowMultiple = false)] diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.ReadCore.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.ReadCore.cs index cd6c39c..57dfef6 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.ReadCore.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.ReadCore.cs @@ -15,8 +15,7 @@ namespace System.Text.Json.Serialization return ReadCore(ref reader, options, ref state); } - [return: MaybeNull] - internal T ReadCore( + internal T? ReadCore( ref Utf8JsonReader reader, JsonSerializerOptions options, ref ReadStack state) @@ -35,7 +34,7 @@ namespace System.Text.Json.Serialization if (state.Current.ReturnValue == null) { // Avoid returning null for value types. - return default!; + return default; } return (T)state.Current.ReturnValue!; @@ -44,7 +43,7 @@ namespace System.Text.Json.Serialization { // Read more data until we have the full element. state.BytesConsumed += reader.BytesConsumed; - return default!; + return default; } } } @@ -55,7 +54,7 @@ namespace System.Text.Json.Serialization if (!SingleValueReadWithReadAhead(ClassType.Value, ref reader, ref state)) { state.BytesConsumed += reader.BytesConsumed; - return default!; + return default; } } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs index dfd81ff..e6f7d84 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs @@ -83,7 +83,7 @@ namespace System.Text.Json.Serialization } // Provide a default implementation for value converters. - internal virtual bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, [MaybeNull] out T value) + internal virtual bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, out T? value) { value = Read(ref reader, typeToConvert, options); return true; @@ -99,10 +99,9 @@ namespace System.Text.Json.Serialization /// The being converted. /// The being used. /// The value that was converted. - [return: MaybeNull] - public abstract T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options); + public abstract T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options); - internal bool TryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, [MaybeNull] out T value) + internal bool TryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, out T? value) { if (ClassType == ClassType.Value) { diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonPropertyInfoOfT.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonPropertyInfoOfT.cs index 85962cd..9e24e25 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonPropertyInfoOfT.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonPropertyInfoOfT.cs @@ -249,7 +249,7 @@ namespace System.Text.Json ThrowHelper.ThrowJsonException_DeserializeUnableToConvertValue(Converter.TypeToConvert); } - value = default(T)!; + value = default(T); success = true; } else diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonResumableConverterOfT.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonResumableConverterOfT.cs index fc0ce66..fbe746d 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonResumableConverterOfT.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonResumableConverterOfT.cs @@ -12,8 +12,7 @@ namespace System.Text.Json.Serialization /// internal abstract class JsonResumableConverter : JsonConverter { - [return: MaybeNull] - public sealed override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + public sealed override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { // Bridge from resumable to value converters. if (options == null) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Helpers.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Helpers.cs index 4e79468..76dd25b 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Helpers.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Helpers.cs @@ -12,8 +12,7 @@ namespace System.Text.Json // Members accessed by the serializer when deserializing. private const DynamicallyAccessedMemberTypes MembersAccessedOnRead = DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.PublicProperties; - [return: MaybeNull] - private static TValue ReadCore(ref Utf8JsonReader reader, Type returnType, JsonSerializerOptions options) + private static TValue? ReadCore(ref Utf8JsonReader reader, Type returnType, JsonSerializerOptions options) { ReadStack state = default; state.Initialize(returnType, options, supportContinuation: false); @@ -21,8 +20,7 @@ namespace System.Text.Json return ReadCore(jsonConverter, ref reader, options, ref state); } - [return: MaybeNull] - private static TValue ReadCore(JsonConverter jsonConverter, ref Utf8JsonReader reader, JsonSerializerOptions options, ref ReadStack state) + private static TValue? ReadCore(JsonConverter jsonConverter, ref Utf8JsonReader reader, JsonSerializerOptions options, ref ReadStack state) { if (jsonConverter is JsonConverter converter) { diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Span.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Span.cs index 974ed2a..af9dd0e 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Span.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Span.cs @@ -22,8 +22,7 @@ namespace System.Text.Json /// There is no compatible /// for or its serializable members. /// - [return: MaybeNull] - public static TValue Deserialize<[DynamicallyAccessedMembers(MembersAccessedOnRead)] TValue>(ReadOnlySpan utf8Json, JsonSerializerOptions? options = null) + public static TValue? Deserialize<[DynamicallyAccessedMembers(MembersAccessedOnRead)] TValue>(ReadOnlySpan utf8Json, JsonSerializerOptions? options = null) { if (options == null) { diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Stream.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Stream.cs index 24d1421..b0c471c 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Stream.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Stream.cs @@ -35,7 +35,7 @@ namespace System.Text.Json /// There is no compatible /// for or its serializable members. /// - public static ValueTask DeserializeAsync<[DynamicallyAccessedMembers(MembersAccessedOnRead)] TValue>( + public static ValueTask DeserializeAsync<[DynamicallyAccessedMembers(MembersAccessedOnRead)] TValue>( Stream utf8Json, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default) @@ -86,7 +86,7 @@ namespace System.Text.Json return ReadAsync(utf8Json, returnType, options, cancellationToken); } - private static async ValueTask ReadAsync( + private static async ValueTask ReadAsync( Stream utf8Json, Type returnType, JsonSerializerOptions? options, diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.String.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.String.cs index bd9edb8..af1f35d 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.String.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.String.cs @@ -34,8 +34,7 @@ namespace System.Text.Json /// Using a is not as efficient as using the /// UTF-8 methods since the implementation natively uses UTF-8. /// - [return: MaybeNull] - public static TValue Deserialize<[DynamicallyAccessedMembers(MembersAccessedOnRead)] TValue>(string json, JsonSerializerOptions? options = null) + public static TValue? Deserialize<[DynamicallyAccessedMembers(MembersAccessedOnRead)] TValue>(string json, JsonSerializerOptions? options = null) { if (json == null) { @@ -84,8 +83,7 @@ namespace System.Text.Json return value; } - [return: MaybeNull] - private static TValue Deserialize(string json, Type returnType, JsonSerializerOptions? options) + private static TValue? Deserialize(string json, Type returnType, JsonSerializerOptions? options) { const long ArrayPoolMaxSizeBeforeUsingNormalAlloc = 1024 * 1024; diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Utf8JsonReader.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Utf8JsonReader.cs index 9daac01..4b42458 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Utf8JsonReader.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Utf8JsonReader.cs @@ -52,8 +52,7 @@ namespace System.Text.Json /// Hence, , , are used while reading. /// /// - [return: MaybeNull] - public static TValue Deserialize<[DynamicallyAccessedMembers(MembersAccessedOnRead)] TValue>(ref Utf8JsonReader reader, JsonSerializerOptions? options = null) + public static TValue? Deserialize<[DynamicallyAccessedMembers(MembersAccessedOnRead)] TValue>(ref Utf8JsonReader reader, JsonSerializerOptions? options = null) { if (options == null) { @@ -137,8 +136,7 @@ namespace System.Text.Json } } - [return: MaybeNull] - private static TValue ReadValueCore(JsonSerializerOptions options, ref Utf8JsonReader reader, ref ReadStack state) + private static TValue? ReadValueCore(JsonSerializerOptions options, ref Utf8JsonReader reader, ref ReadStack state) { JsonReaderState readerState = reader.CurrentState; CheckSupportedOptions(readerState.Options, nameof(reader)); diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Collections/HashtableExtensions.cs b/src/libraries/System.Text.RegularExpressions/src/System/Collections/HashtableExtensions.cs index e45e584..0df0e57 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System/Collections/HashtableExtensions.cs +++ b/src/libraries/System.Text.RegularExpressions/src/System/Collections/HashtableExtensions.cs @@ -7,14 +7,15 @@ namespace System.Collections { internal static class HashtableExtensions { - public static bool TryGetValue(this Hashtable table, object key, [MaybeNull] out T value) + public static bool TryGetValue(this Hashtable table, object key, out T? value) { if (table.ContainsKey(key)) { value = (T)table[key]!; return true; } - value = default!; + + value = default; return false; } } diff --git a/src/libraries/System.Threading.Channels/src/System/Threading/Channels/AsyncOperation.cs b/src/libraries/System.Threading.Channels/src/System/Threading/Channels/AsyncOperation.cs index 67106d3..9412cc2 100644 --- a/src/libraries/System.Threading.Channels/src/System/Threading/Channels/AsyncOperation.cs +++ b/src/libraries/System.Threading.Channels/src/System/Threading/Channels/AsyncOperation.cs @@ -51,8 +51,7 @@ namespace System.Threading.Channels /// Only relevant to cancelable operations; 0 if the operation hasn't had completion reserved, 1 if it has. private volatile int _completionReserved; /// The result of the operation. - [MaybeNull, AllowNull] - private TResult _result = default; + private TResult? _result; /// Any error that occurred during the operation. private ExceptionDispatchInfo? _error; /// The continuation callback. @@ -454,7 +453,6 @@ namespace System.Threading.Channels } /// The item being written. - [MaybeNull, AllowNull] - public TData Item { get; set; } = default!; + public TData? Item { get; set; } } } diff --git a/src/libraries/System.Threading.Channels/src/System/Threading/Channels/BoundedChannel.cs b/src/libraries/System.Threading.Channels/src/System/Threading/Channels/BoundedChannel.cs index be088c5..cec397b 100644 --- a/src/libraries/System.Threading.Channels/src/System/Threading/Channels/BoundedChannel.cs +++ b/src/libraries/System.Threading.Channels/src/System/Threading/Channels/BoundedChannel.cs @@ -105,7 +105,7 @@ namespace System.Threading.Channels } } - item = default!; + item = default; return false; } diff --git a/src/libraries/System.Threading.Channels/src/System/Threading/Channels/UnboundedChannel.cs b/src/libraries/System.Threading.Channels/src/System/Threading/Channels/UnboundedChannel.cs index 6ac25fb..612d6b5 100644 --- a/src/libraries/System.Threading.Channels/src/System/Threading/Channels/UnboundedChannel.cs +++ b/src/libraries/System.Threading.Channels/src/System/Threading/Channels/UnboundedChannel.cs @@ -119,7 +119,7 @@ namespace System.Threading.Channels return true; } - item = default!; + item = default; return false; } diff --git a/src/libraries/System.Threading.Tasks.Dataflow/ref/System.Threading.Tasks.Dataflow.cs b/src/libraries/System.Threading.Tasks.Dataflow/ref/System.Threading.Tasks.Dataflow.cs index e860e69..4931e85 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/ref/System.Threading.Tasks.Dataflow.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/ref/System.Threading.Tasks.Dataflow.cs @@ -30,8 +30,7 @@ namespace System.Threading.Tasks.Dataflow public void Complete() { } public System.IDisposable LinkTo(System.Threading.Tasks.Dataflow.ITargetBlock target, System.Threading.Tasks.Dataflow.DataflowLinkOptions linkOptions) { throw null; } void System.Threading.Tasks.Dataflow.IDataflowBlock.Fault(System.Exception exception) { } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - T[] System.Threading.Tasks.Dataflow.ISourceBlock.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target, out bool messageConsumed) { throw null; } + T[]? System.Threading.Tasks.Dataflow.ISourceBlock.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target, out bool messageConsumed) { throw null; } void System.Threading.Tasks.Dataflow.ISourceBlock.ReleaseReservation(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target) { } bool System.Threading.Tasks.Dataflow.ISourceBlock.ReserveMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target) { throw null; } System.Threading.Tasks.Dataflow.DataflowMessageStatus System.Threading.Tasks.Dataflow.ITargetBlock.OfferMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, T messageValue, System.Threading.Tasks.Dataflow.ISourceBlock? source, bool consumeToAccept) { throw null; } @@ -88,8 +87,7 @@ namespace System.Threading.Tasks.Dataflow public System.IDisposable LinkTo(System.Threading.Tasks.Dataflow.ITargetBlock target, System.Threading.Tasks.Dataflow.DataflowLinkOptions linkOptions) { throw null; } void System.Threading.Tasks.Dataflow.IDataflowBlock.Fault(System.Exception exception) { } bool System.Threading.Tasks.Dataflow.IReceivableSourceBlock.TryReceiveAll([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Collections.Generic.IList? items) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - T System.Threading.Tasks.Dataflow.ISourceBlock.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target, out bool messageConsumed) { throw null; } + T? System.Threading.Tasks.Dataflow.ISourceBlock.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target, out bool messageConsumed) { throw null; } void System.Threading.Tasks.Dataflow.ISourceBlock.ReleaseReservation(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target) { } bool System.Threading.Tasks.Dataflow.ISourceBlock.ReserveMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target) { throw null; } System.Threading.Tasks.Dataflow.DataflowMessageStatus System.Threading.Tasks.Dataflow.ITargetBlock.OfferMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, T messageValue, System.Threading.Tasks.Dataflow.ISourceBlock? source, bool consumeToAccept) { throw null; } @@ -105,8 +103,7 @@ namespace System.Threading.Tasks.Dataflow public void Complete() { } public System.IDisposable LinkTo(System.Threading.Tasks.Dataflow.ITargetBlock target, System.Threading.Tasks.Dataflow.DataflowLinkOptions linkOptions) { throw null; } void System.Threading.Tasks.Dataflow.IDataflowBlock.Fault(System.Exception exception) { } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - T System.Threading.Tasks.Dataflow.ISourceBlock.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target, out bool messageConsumed) { throw null; } + T? System.Threading.Tasks.Dataflow.ISourceBlock.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target, out bool messageConsumed) { throw null; } void System.Threading.Tasks.Dataflow.ISourceBlock.ReleaseReservation(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target) { } bool System.Threading.Tasks.Dataflow.ISourceBlock.ReserveMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target) { throw null; } System.Threading.Tasks.Dataflow.DataflowMessageStatus System.Threading.Tasks.Dataflow.ITargetBlock.OfferMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, T messageValue, System.Threading.Tasks.Dataflow.ISourceBlock? source, bool consumeToAccept) { throw null; } @@ -208,8 +205,7 @@ namespace System.Threading.Tasks.Dataflow } public partial interface ISourceBlock : System.Threading.Tasks.Dataflow.IDataflowBlock { - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - TOutput ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target, out bool messageConsumed); + TOutput? ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target, out bool messageConsumed); System.IDisposable LinkTo(System.Threading.Tasks.Dataflow.ITargetBlock target, System.Threading.Tasks.Dataflow.DataflowLinkOptions linkOptions); void ReleaseReservation(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target); bool ReserveMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target); @@ -267,8 +263,7 @@ namespace System.Threading.Tasks.Dataflow public void Complete() { } public System.IDisposable LinkTo(System.Threading.Tasks.Dataflow.ITargetBlock target, System.Threading.Tasks.Dataflow.DataflowLinkOptions linkOptions) { throw null; } void System.Threading.Tasks.Dataflow.IDataflowBlock.Fault(System.Exception exception) { } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - TOutput System.Threading.Tasks.Dataflow.ISourceBlock.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target, out bool messageConsumed) { throw null; } + TOutput? System.Threading.Tasks.Dataflow.ISourceBlock.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target, out bool messageConsumed) { throw null; } void System.Threading.Tasks.Dataflow.ISourceBlock.ReleaseReservation(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target) { } bool System.Threading.Tasks.Dataflow.ISourceBlock.ReserveMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target) { throw null; } System.Threading.Tasks.Dataflow.DataflowMessageStatus System.Threading.Tasks.Dataflow.ITargetBlock.OfferMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, TInput messageValue, System.Threading.Tasks.Dataflow.ISourceBlock? source, bool consumeToAccept) { throw null; } @@ -288,8 +283,7 @@ namespace System.Threading.Tasks.Dataflow public void Complete() { } public System.IDisposable LinkTo(System.Threading.Tasks.Dataflow.ITargetBlock target, System.Threading.Tasks.Dataflow.DataflowLinkOptions linkOptions) { throw null; } void System.Threading.Tasks.Dataflow.IDataflowBlock.Fault(System.Exception exception) { } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - TOutput System.Threading.Tasks.Dataflow.ISourceBlock.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target, out bool messageConsumed) { throw null; } + TOutput? System.Threading.Tasks.Dataflow.ISourceBlock.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target, out bool messageConsumed) { throw null; } void System.Threading.Tasks.Dataflow.ISourceBlock.ReleaseReservation(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target) { } bool System.Threading.Tasks.Dataflow.ISourceBlock.ReserveMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target) { throw null; } System.Threading.Tasks.Dataflow.DataflowMessageStatus System.Threading.Tasks.Dataflow.ITargetBlock.OfferMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, TInput messageValue, System.Threading.Tasks.Dataflow.ISourceBlock? source, bool consumeToAccept) { throw null; } @@ -306,8 +300,7 @@ namespace System.Threading.Tasks.Dataflow public System.IDisposable LinkTo(System.Threading.Tasks.Dataflow.ITargetBlock target, System.Threading.Tasks.Dataflow.DataflowLinkOptions linkOptions) { throw null; } void System.Threading.Tasks.Dataflow.IDataflowBlock.Fault(System.Exception exception) { } bool System.Threading.Tasks.Dataflow.IReceivableSourceBlock.TryReceiveAll([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Collections.Generic.IList? items) { throw null; } - [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - T System.Threading.Tasks.Dataflow.ISourceBlock.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target, out bool messageConsumed) { throw null; } + T? System.Threading.Tasks.Dataflow.ISourceBlock.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target, out bool messageConsumed) { throw null; } void System.Threading.Tasks.Dataflow.ISourceBlock.ReleaseReservation(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target) { } bool System.Threading.Tasks.Dataflow.ISourceBlock.ReserveMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock target) { throw null; } System.Threading.Tasks.Dataflow.DataflowMessageStatus System.Threading.Tasks.Dataflow.ITargetBlock.OfferMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, T messageValue, System.Threading.Tasks.Dataflow.ISourceBlock? source, bool consumeToAccept) { throw null; } diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Base/DataflowBlock.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Base/DataflowBlock.cs index 45d7c5c..2785f3e 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Base/DataflowBlock.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Base/DataflowBlock.cs @@ -154,8 +154,7 @@ namespace System.Threading.Tasks.Dataflow } /// - [return: MaybeNull] - T ISourceBlock.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) + T? ISourceBlock.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) { // This message should have only made it to the target if it passes the filter, so we shouldn't need to check again. // The real source will also be doing verifications, so we don't need to validate args here. @@ -621,8 +620,7 @@ namespace System.Threading.Tasks.Dataflow } /// Called by the target to consume the buffered message. - [return: MaybeNull] - TOutput ISourceBlock.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) + TOutput? ISourceBlock.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) { // Validate arguments if (!messageHeader.IsValid) throw new ArgumentException(SR.Argument_InvalidMessageHeader, nameof(messageHeader)); @@ -1129,8 +1127,7 @@ namespace System.Threading.Tasks.Dataflow }; /// The received value if we accepted a value from the source. - [AllowNull, MaybeNull] - private T _receivedValue = default!; + private T? _receivedValue; /// The cancellation token source representing both external and internal cancellation. internal readonly CancellationTokenSource _cts = new CancellationTokenSource(); @@ -1664,8 +1661,7 @@ namespace System.Threading.Tasks.Dataflow } /// - [return: MaybeNull] - public TOutput ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) + public TOutput? ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) { return _source.ConsumeMessage(messageHeader, target, out messageConsumed); } diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Base/ISourceBlock.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Base/ISourceBlock.cs index 518f8fb..8e4d27a 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Base/ISourceBlock.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Base/ISourceBlock.cs @@ -27,8 +27,7 @@ namespace System.Threading.Tasks.Dataflow // IMPLEMENT EXPLICITLY /// - [return: MaybeNull] - TOutput ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed); + TOutput? ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed); /// bool ReserveMessage(DataflowMessageHeader messageHeader, ITargetBlock target); diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BatchBlock.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BatchBlock.cs index df9bb9c..af2775e 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BatchBlock.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BatchBlock.cs @@ -154,8 +154,7 @@ namespace System.Threading.Tasks.Dataflow } /// - [return: MaybeNull] - T[] ISourceBlock.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) + T[]? ISourceBlock.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) { return _source.ConsumeMessage(messageHeader, target, out messageConsumed); } diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BatchedJoinBlock.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BatchedJoinBlock.cs index 054eaa3..8099f49 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BatchedJoinBlock.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BatchedJoinBlock.cs @@ -172,8 +172,7 @@ namespace System.Threading.Tasks.Dataflow } /// - [return: MaybeNull] - Tuple, IList> ISourceBlock, IList>>.ConsumeMessage( + Tuple, IList>? ISourceBlock, IList>>.ConsumeMessage( DataflowMessageHeader messageHeader, ITargetBlock, IList>> target, out bool messageConsumed) { return _source.ConsumeMessage(messageHeader, target, out messageConsumed); @@ -436,8 +435,7 @@ namespace System.Threading.Tasks.Dataflow } /// - [return: MaybeNull] - Tuple, IList, IList> ISourceBlock, IList, IList>>.ConsumeMessage( + Tuple, IList, IList>? ISourceBlock, IList, IList>>.ConsumeMessage( DataflowMessageHeader messageHeader, ITargetBlock, IList, IList>> target, out bool messageConsumed) { return _source.ConsumeMessage(messageHeader, target, out messageConsumed); diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BroadcastBlock.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BroadcastBlock.cs index 508d151..9f9b932 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BroadcastBlock.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BroadcastBlock.cs @@ -417,8 +417,7 @@ namespace System.Threading.Tasks.Dataflow } /// - [return: MaybeNull] - T ISourceBlock.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) + T? ISourceBlock.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) { return _source.ConsumeMessage(messageHeader, target, out messageConsumed); } @@ -531,8 +530,7 @@ namespace System.Threading.Tasks.Dataflow /// An indicator whether _currentMessage has a value. private bool _currentMessageIsValid; /// The message currently being broadcast. - [AllowNull, MaybeNull] - private TOutput _currentMessage = default; + private TOutput? _currentMessage; /// The target that the next message is reserved for, or null if nothing is reserved. private ITargetBlock? _nextMessageReservedFor; /// Whether this block should again attempt to offer messages to targets. @@ -1049,8 +1047,7 @@ namespace System.Threading.Tasks.Dataflow } /// - [return: MaybeNull] - internal TOutput ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) + internal TOutput? ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) { // Validate arguments if (!messageHeader.IsValid) throw new ArgumentException(SR.Argument_InvalidMessageHeader, nameof(messageHeader)); diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BufferBlock.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BufferBlock.cs index dc7b45d..6d5e702 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BufferBlock.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BufferBlock.cs @@ -197,8 +197,7 @@ namespace System.Threading.Tasks.Dataflow public Task Completion { get { return _source.Completion; } } /// - [return: MaybeNull] - T ISourceBlock.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) + T? ISourceBlock.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) { return _source.ConsumeMessage(messageHeader, target, out messageConsumed); } diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformBlock.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformBlock.cs index cbaff49..b5267ca 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformBlock.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformBlock.cs @@ -368,8 +368,7 @@ namespace System.Threading.Tasks.Dataflow } /// - [return: MaybeNull] - TOutput ISourceBlock.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) + TOutput? ISourceBlock.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) { return _source.ConsumeMessage(messageHeader, target, out messageConsumed); } diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformManyBlock.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformManyBlock.cs index a1d7dcc..0e6ddfa 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformManyBlock.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformManyBlock.cs @@ -601,8 +601,7 @@ namespace System.Threading.Tasks.Dataflow } /// - [return: MaybeNull] - TOutput ISourceBlock.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) + TOutput? ISourceBlock.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) { return _source.ConsumeMessage(messageHeader, target, out messageConsumed); } diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/WriteOnceBlock.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/WriteOnceBlock.cs index 22d052a..244703a 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/WriteOnceBlock.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/WriteOnceBlock.cs @@ -39,8 +39,7 @@ namespace System.Threading.Tasks.Dataflow /// The header of the singly-assigned value. private DataflowMessageHeader _header; /// The singly-assigned value. - [AllowNull, MaybeNull] - private T _value = default; + private T? _value; /// Gets the object used as the value lock. private object ValueLock { get { return _targetRegistry; } } @@ -381,7 +380,7 @@ namespace System.Threading.Tasks.Dataflow } /// - T ISourceBlock.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) + T? ISourceBlock.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) { // Validate arguments if (!messageHeader.IsValid) throw new ArgumentException(SR.Argument_InvalidMessageHeader, nameof(messageHeader)); @@ -397,7 +396,7 @@ namespace System.Threading.Tasks.Dataflow else { messageConsumed = false; - return default(T)!; + return default; } } @@ -506,8 +505,7 @@ namespace System.Threading.Tasks.Dataflow /// Gets whether the block is storing a value. private bool HasValue { get { return _header.IsValid; } } /// Gets the value being stored by the block. - [MaybeNull] - private T Value { get { return _header.IsValid ? _value : default(T); } } + private T? Value { get { return _header.IsValid ? _value : default(T); } } /// public override string ToString() { return Common.GetNameForDebugger(this, _dataflowBlockOptions); } @@ -546,8 +544,7 @@ namespace System.Threading.Tasks.Dataflow /// Gets whether the WriteOnceBlock has a value. public bool HasValue { get { return _writeOnceBlock.HasValue; } } /// Gets the WriteOnceBlock's value if it has one, or default(T) if it doesn't. - [MaybeNull] - public T Value { get { return _writeOnceBlock.Value; } } + public T? Value { get { return _writeOnceBlock.Value; } } /// Gets the DataflowBlockOptions used to configure this block. public DataflowBlockOptions DataflowBlockOptions { get { return _writeOnceBlock._dataflowBlockOptions; } } diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/Common.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/Common.cs index 275b293..0022621 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/Common.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/Common.cs @@ -93,8 +93,7 @@ namespace System.Threading.Tasks.Dataflow.Internal /// The type of the data to be unwrapped. /// The weak reference. /// The T instance. - [return: MaybeNull] - internal static T UnwrapWeakReference(object state) where T : class + internal static T? UnwrapWeakReference(object state) where T : class { var wr = state as WeakReference; Debug.Assert(wr != null, "Expected a WeakReference as the state argument"); diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/ReorderingBuffer.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/ReorderingBuffer.cs index e69865b..80513f6 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/ReorderingBuffer.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/ReorderingBuffer.cs @@ -66,7 +66,7 @@ namespace System.Threading.Tasks.Dataflow.Internal /// The ID of the item. /// The completed item. /// Specifies whether the item is valid (true) or just a placeholder (false). - internal void AddItem(long id, [AllowNull] TOutput item, bool itemIsValid) + internal void AddItem(long id, TOutput? item, bool itemIsValid) { Debug.Assert(id != Common.INVALID_REORDERING_ID, "This ID should never have been handed out."); Common.ContractAssertMonitorStatus(ValueLock, held: false); @@ -104,7 +104,7 @@ namespace System.Threading.Tasks.Dataflow.Internal /// true if the item was not added but is next in line. /// false if the item was not added and is not next in line. /// - internal bool? AddItemIfNextAndTrusted(long id, [AllowNull] TOutput item, bool isTrusted) + internal bool? AddItemIfNextAndTrusted(long id, TOutput? item, bool isTrusted) { Debug.Assert(id != Common.INVALID_REORDERING_ID, "This ID should never have been handed out."); Common.ContractAssertMonitorStatus(ValueLock, held: false); @@ -138,7 +138,7 @@ namespace System.Threading.Tasks.Dataflow.Internal /// Outputs the item. The item must have already been confirmed to have the next ID. /// The item to output. /// Whether the item is valid. - private void OutputNextItem([AllowNull] TOutput theNextItem, bool itemIsValid) + private void OutputNextItem(TOutput? theNextItem, bool itemIsValid) { Common.ContractAssertMonitorStatus(ValueLock, held: true); diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/SourceCore.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/SourceCore.cs index 99d772c..a9e86e6 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/SourceCore.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/SourceCore.cs @@ -155,8 +155,7 @@ namespace System.Threading.Tasks.Dataflow.Internal } /// - [return: MaybeNull] - internal TOutput ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) + internal TOutput? ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) { // Validate arguments if (!messageHeader.IsValid) throw new ArgumentException(SR.Argument_InvalidMessageHeader, nameof(messageHeader)); diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/TargetRegistry.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/TargetRegistry.cs index 9420fc8..6cc23ec 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/TargetRegistry.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/TargetRegistry.cs @@ -331,8 +331,7 @@ namespace System.Threading.Tasks.Dataflow.Internal } /// - [return: MaybeNull] - T ISourceBlock.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) + T? ISourceBlock.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock target, out bool messageConsumed) { return _owningSource.ConsumeMessage(messageHeader, this, out messageConsumed); } diff --git a/src/libraries/System.Threading/ref/System.Threading.cs b/src/libraries/System.Threading/ref/System.Threading.cs index d5fceaa..888abda 100644 --- a/src/libraries/System.Threading/ref/System.Threading.cs +++ b/src/libraries/System.Threading/ref/System.Threading.cs @@ -35,10 +35,8 @@ namespace System.Threading private readonly T _PreviousValue_k__BackingField; private readonly T _CurrentValue_k__BackingField; private readonly int _dummyPrimitive; - [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public T CurrentValue { get { throw null; } } - [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] - public T PreviousValue { get { throw null; } } + public T? CurrentValue { get { throw null; } } + public T? PreviousValue { get { throw null; } } public bool ThreadContextChanged { get { throw null; } } } public sealed partial class AsyncLocal diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/TypeIdentifier.cs b/src/mono/netcore/System.Private.CoreLib/src/System/TypeIdentifier.cs index a4bc5ac..e54fecd 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/TypeIdentifier.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/TypeIdentifier.cs @@ -74,7 +74,7 @@ namespace System public abstract ITypeName NestedName(ITypeIdentifier innerName); - public bool Equals([AllowNull] ITypeName other) + public bool Equals(ITypeName? other) { return other != null && DisplayName == other.DisplayName; } diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/WeakReference.T.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/WeakReference.T.Mono.cs index 8ab12b5..e4c4b0a 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/WeakReference.T.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/WeakReference.T.Mono.cs @@ -11,8 +11,7 @@ namespace System private GCHandle handle; private bool trackResurrection; - [MaybeNull] - private T Target + private T? Target { get {