diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/ClientUtils.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/ClientUtils.cs index c9d7cfb6efe42..f7bffe8898abb 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/ClientUtils.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/ClientUtils.cs @@ -112,8 +112,7 @@ public override bool Equals(object? obj) { if (InnerList[i] != other.InnerList[i]) { - // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644 - if (InnerList[i] == null || !InnerList[i]!.Equals(other.InnerList[i])) + if (InnerList[i] == null || !InnerList[i]!.Equals(other.InnerList[i])) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644 { return false; } diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintingServices.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintingServices.Unix.cs index baf19efb84f6c..b0737ad731b4b 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintingServices.Unix.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintingServices.Unix.cs @@ -664,12 +664,10 @@ internal static void GetPrintDialogInfo(string printer, ref string port, ref str NameValueCollection options = LoadPrinterOptions(cups_dests.options, cups_dests.num_options); if (options["printer-state"] != null) - // TODO-NULLABLE dotnet/roslyn#34644 - state = int.Parse(options["printer-state"]!); + state = int.Parse(options["printer-state"]!); // TODO-NULLABLE dotnet/roslyn#34644 if (options["printer-comment"] != null) - // TODO-NULLABLE dotnet/roslyn#34644 - comment = options["printer-state"]!; + comment = options["printer-state"]!; // TODO-NULLABLE dotnet/roslyn#34644 switch (state) { 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 c45b6bb934856..bc758b39dd041 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 @@ -68,7 +68,7 @@ public bool Remove(TElement value) int last = -1; for (int i = _buckets[bucket] - 1; i >= 0; last = i, i = _slots[i].next) { - if (_slots[i].hashCode == hashCode && _comparer.Equals(_slots[i].value!, value)) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/2872 + if (_slots[i].hashCode == hashCode && _comparer.Equals(_slots[i].value, value)) { if (last < 0) { @@ -92,7 +92,7 @@ private bool Find(TElement value, bool add) int hashCode = InternalGetHashCode(value); for (int i = _buckets[hashCode % _buckets.Length] - 1; i >= 0; i = _slots[i].next) { - if (_slots[i].hashCode == hashCode && _comparer.Equals(_slots[i].value!, value)) return true; // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/2872 + if (_slots[i].hashCode == hashCode && _comparer.Equals(_slots[i].value, value)) return true; } if (add) { 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 ca0b0f60df556..0a4a1d9295420 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 @@ -33,7 +33,7 @@ internal sealed class AsynchronousChannelMergeEnumerator : MergeEnumerator 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. TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/37511 + [MaybeNull, AllowNull] private T _currentElement = default; // The remembered element from the previous MoveNext. //----------------------------------------------------------------------------------- // Allocates a new enumerator over a set of one-to-one channels. @@ -99,7 +99,7 @@ public override bool MoveNext() } // Else try the fast path. - if (!_done[index] && _channels[index].TryDequeue(ref _currentElement!)) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/2872 + if (!_done[index] && _channels[index].TryDequeue(ref _currentElement)) { _channelIndex = (index + 1) % _channels.Length; return true; @@ -127,7 +127,7 @@ private bool MoveNextSlowPath() AsynchronousChannel current = _channels[currChannelIndex]; bool isDone = _done[currChannelIndex]; - if (!isDone && current.TryDequeue(ref _currentElement!)) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/2872 + if (!isDone && current.TryDequeue(ref _currentElement)) { // The channel has an item to be processed. We already remembered the current // element (Dequeue stores it as an out-parameter), so we just return true @@ -147,7 +147,7 @@ private bool MoveNextSlowPath() // we still need to continue processing them. if (!current.IsChunkBufferEmpty) { - bool dequeueResult = current.TryDequeue(ref _currentElement!); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/2872 + bool dequeueResult = current.TryDequeue(ref _currentElement); Debug.Assert(dequeueResult, "channel isn't empty, yet the dequeue failed, hmm"); return true; } @@ -192,7 +192,7 @@ private bool MoveNextSlowPath() for (int i = 0; i < _channels.Length; i++) { bool channelIsDone = false; - if (!_done[i] && _channels[i].TryDequeue(ref _currentElement!, ref channelIsDone)) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/2872 + if (!_done[i] && _channels[i].TryDequeue(ref _currentElement, ref channelIsDone)) { // The channel has received an item since the last time we checked. // Just return and let the consumer process the element returned. diff --git a/src/libraries/System.Memory/src/System/Buffers/ReadOnlySequence.cs b/src/libraries/System.Memory/src/System/Buffers/ReadOnlySequence.cs index a427620fe6b4a..2d286438ce2cf 100644 --- a/src/libraries/System.Memory/src/System/Buffers/ReadOnlySequence.cs +++ b/src/libraries/System.Memory/src/System/Buffers/ReadOnlySequence.cs @@ -121,7 +121,7 @@ public ReadOnlySequence(T[] array) _startObject = array; _endObject = array; _startInteger = ReadOnlySequence.ArrayToSequenceStart(0); - _endInteger = ReadOnlySequence.ArrayToSequenceEnd(array!.Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + _endInteger = ReadOnlySequence.ArrayToSequenceEnd(array.Length); } /// @@ -146,9 +146,7 @@ public ReadOnlySequence(T[] array, int start, int length) /// public ReadOnlySequence(ReadOnlyMemory memory) { -#pragma warning disable CS8631 // TODO-NULLABLE: ILLink rewriter removing some necessary metadata (https://github.com/dotnet/corefx/pull/38983#issuecomment-506757237) if (MemoryMarshal.TryGetMemoryManager(memory, out MemoryManager? manager, out int index, out int length)) -#pragma warning restore CS8631 { _startObject = manager; _endObject = manager; diff --git a/src/libraries/System.Memory/src/System/ThrowHelper.cs b/src/libraries/System.Memory/src/System/ThrowHelper.cs index 9c6c973a20fbc..61d7ff2f0ad3f 100644 --- a/src/libraries/System.Memory/src/System/ThrowHelper.cs +++ b/src/libraries/System.Memory/src/System/ThrowHelper.cs @@ -2,8 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Runtime.CompilerServices; using System.Buffers; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; namespace System { @@ -24,30 +25,37 @@ namespace System internal static class ThrowHelper { + [DoesNotReturn] internal static void ThrowArgumentNullException(ExceptionArgument argument) { throw CreateArgumentNullException(argument); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateArgumentNullException(ExceptionArgument argument) { return new ArgumentNullException(argument.ToString()); } + [DoesNotReturn] internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument) { throw CreateArgumentOutOfRangeException(argument); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateArgumentOutOfRangeException(ExceptionArgument argument) { return new ArgumentOutOfRangeException(argument.ToString()); } + [DoesNotReturn] internal static void ThrowInvalidOperationException() { throw CreateInvalidOperationException(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateInvalidOperationException() { return new InvalidOperationException(); } + [DoesNotReturn] internal static void ThrowInvalidOperationException_EndPositionNotReached() { throw CreateInvalidOperationException_EndPositionNotReached(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateInvalidOperationException_EndPositionNotReached() { return new InvalidOperationException(SR.EndPositionNotReached); } + [DoesNotReturn] internal static void ThrowArgumentOutOfRangeException_PositionOutOfRange() { throw CreateArgumentOutOfRangeException_PositionOutOfRange(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateArgumentOutOfRangeException_PositionOutOfRange() { return new ArgumentOutOfRangeException("position"); } + [DoesNotReturn] internal static void ThrowArgumentOutOfRangeException_OffsetOutOfRange() { throw CreateArgumentOutOfRangeException_OffsetOutOfRange(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateArgumentOutOfRangeException_OffsetOutOfRange() { return new ArgumentOutOfRangeException(nameof(ExceptionArgument.offset)); } + [DoesNotReturn] internal static void ThrowObjectDisposedException_ArrayMemoryPoolBuffer() { throw CreateObjectDisposedException_ArrayMemoryPoolBuffer(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateObjectDisposedException_ArrayMemoryPoolBuffer() { return new ObjectDisposedException("ArrayMemoryPoolBuffer"); } @@ -55,6 +63,7 @@ internal static class ThrowHelper // // ReadOnlySequence .ctor validation Throws coalesced to enable inlining of the .ctor // + [DoesNotReturn] public static void ThrowArgumentValidationException(ReadOnlySequenceSegment? startSegment, int startIndex, ReadOnlySequenceSegment? endSegment) => throw CreateArgumentValidationException(startSegment, startIndex, endSegment); @@ -72,6 +81,7 @@ private static Exception CreateArgumentValidationException(ReadOnlySequenceSe return CreateArgumentOutOfRangeException(ExceptionArgument.endIndex); } + [DoesNotReturn] public static void ThrowArgumentValidationException(Array? array, int start) => throw CreateArgumentValidationException(array, start); @@ -88,6 +98,7 @@ private static Exception CreateArgumentValidationException(Array? array, int sta // // ReadOnlySequence Slice validation Throws coalesced to enable inlining of the Slice // + [DoesNotReturn] public static void ThrowStartOrEndArgumentValidationException(long start) => throw CreateStartOrEndArgumentValidationException(start); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlSubtreeReader.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlSubtreeReader.cs index 9432bb5d9cdaa..ba436fa65c791 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlSubtreeReader.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlSubtreeReader.cs @@ -260,7 +260,6 @@ public override int AttributeCount { if (name == _nsAttributes![i].name) { - // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644 return _nsAttributes[i].value; } } @@ -284,7 +283,6 @@ public override int AttributeCount { if (name == _nsAttributes![i].localName && namespaceURI == _xmlnsUri) { - // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644 return _nsAttributes[i].value; } } @@ -1353,12 +1351,12 @@ private void RemoveNamespace(string prefix, string localName) for (int i = 0; i < _nsAttrCount; i++) { if (Ref.Equal(prefix, _nsAttributes![i].prefix) && - Ref.Equal(localName, _nsAttributes![i].localName)) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644 + Ref.Equal(localName, _nsAttributes[i].localName)) { if (i < _nsAttrCount - 1) { // swap - NodeData tmpNodeData = _nsAttributes![i]; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644 + NodeData tmpNodeData = _nsAttributes[i]; _nsAttributes[i] = _nsAttributes[_nsAttrCount - 1]; _nsAttributes[_nsAttrCount - 1] = tmpNodeData; } diff --git a/src/libraries/System.Runtime/tests/System/NullableMetadataTests.cs b/src/libraries/System.Runtime/tests/System/NullableMetadataTests.cs index 5b3c99354429e..de85325b2b3de 100644 --- a/src/libraries/System.Runtime/tests/System/NullableMetadataTests.cs +++ b/src/libraries/System.Runtime/tests/System/NullableMetadataTests.cs @@ -62,7 +62,7 @@ public static void NullableAttributesOnPublicApiOnly(Type type) { // When using BindingFlags.NonPublic protected members are included and those are expected // to have Nullable attributes. - if (internalMember.IsProtected() || internalMember is PropertyInfo) // TODO-NULLABLE: validate properties (https://github.com/dotnet/roslyn/issues/37161) + if (internalMember.IsProtected() || internalMember is PropertyInfo) continue; Assert.Empty(internalMember.CustomAttributes.GetNullableAttributes()); diff --git a/src/libraries/System.Threading.Channels/src/System/Threading/Channels/SingleConsumerUnboundedChannel.cs b/src/libraries/System.Threading.Channels/src/System/Threading/Channels/SingleConsumerUnboundedChannel.cs index 43961b594f3ab..4da42cf7c0284 100644 --- a/src/libraries/System.Threading.Channels/src/System/Threading/Channels/SingleConsumerUnboundedChannel.cs +++ b/src/libraries/System.Threading.Channels/src/System/Threading/Channels/SingleConsumerUnboundedChannel.cs @@ -32,13 +32,11 @@ internal sealed class SingleConsumerUnboundedChannel : Channel, IDebugEnum /// non-null if the channel has been marked as complete for writing. private volatile Exception? _doneWriting; -#pragma warning disable CA1823 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/38195 /// An if there's a blocked reader. private AsyncOperation? _blockedReader; /// A waiting reader (e.g. WaitForReadAsync) if there is one. private AsyncOperation? _waitingReader; -#pragma warning restore CA1823 /// Initialize the channel. /// Whether to force continuations to be executed asynchronously. 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 48976abd85f41..3a244ba2aaaef 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BatchBlock.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BatchBlock.cs @@ -127,9 +127,7 @@ public IDisposable LinkTo(ITargetBlock target, DataflowLinkOptions linkOpti } /// -#pragma warning disable CS8614 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/42470 public bool TryReceive(Predicate? filter, [NotNullWhen(true)] out T[]? item) -#pragma warning restore CS8614 { return _source.TryReceive(filter, out item); } 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 4e4f576fad7b3..e430889b89f83 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BatchedJoinBlock.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BatchedJoinBlock.cs @@ -132,9 +132,7 @@ public IDisposable LinkTo(ITargetBlock, IList>> target, Data } /// -#pragma warning disable CS8614 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/42470 public bool TryReceive(Predicate, IList>>? filter, [NotNullWhen(true)] out Tuple, IList>? item) -#pragma warning restore CS8614 { return _source.TryReceive(filter, out item); } @@ -396,9 +394,7 @@ public IDisposable LinkTo(ITargetBlock, IList, IList>> t } /// -#pragma warning disable CS8614 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/42470 public bool TryReceive(Predicate, IList, IList>>? filter, [NotNullWhen(true)] out Tuple, IList, IList>? item) -#pragma warning restore CS8614 { return _source.TryReceive(filter, out item); } diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/JoinBlock.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/JoinBlock.cs index 9d8b1ad79d64c..262f78e4c4d2f 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/JoinBlock.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/JoinBlock.cs @@ -117,9 +117,7 @@ public IDisposable LinkTo(ITargetBlock> target, DataflowLinkOption } /// -#pragma warning disable CS8614 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/42470 public bool TryReceive(Predicate>? filter, [NotNullWhen(true)] out Tuple? item) -#pragma warning restore CS8614 { return _source.TryReceive(filter, out item); } @@ -166,9 +164,7 @@ void IDataflowBlock.Fault(Exception exception) public ITargetBlock Target2 { get { return _target2; } } /// -#pragma warning disable CS8616 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/42470 Tuple? ISourceBlock>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock> target, out bool messageConsumed) -#pragma warning restore CS8616 { return _source.ConsumeMessage(messageHeader, target, out messageConsumed); } @@ -349,9 +345,7 @@ public IDisposable LinkTo(ITargetBlock> target, DataflowLinkOp } /// -#pragma warning disable CS8614 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/42470 public bool TryReceive(Predicate>? filter, [NotNullWhen(true)] out Tuple? item) -#pragma warning restore CS8614 { return _source.TryReceive(filter, out item); } @@ -403,9 +397,7 @@ void IDataflowBlock.Fault(Exception exception) public ITargetBlock Target3 { get { return _target3; } } /// -#pragma warning disable CS8616 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/42470 Tuple? ISourceBlock>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock> target, out bool messageConsumed) -#pragma warning restore CS8616 { return _source.ConsumeMessage(messageHeader, target, out messageConsumed); }