Skip to content

Commit

Permalink
Runtime changes for DetectPreviewFeaturesAnalyzer (#59062)
Browse files Browse the repository at this point in the history
* Turn on DetectPreviewFeaturesAnalyzer and runtime changes

* Missed decimal

* Add comments and update S.Runtime.csproj

* sq

* sq
  • Loading branch information
Prashanth Govindarajan authored Sep 15, 2021
1 parent 82993d2 commit d2cef2f
Show file tree
Hide file tree
Showing 25 changed files with 49 additions and 44 deletions.
2 changes: 1 addition & 1 deletion eng/CodeAnalysis.src.globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ dotnet_diagnostic.CA2250.severity = warning
dotnet_diagnostic.CA2251.severity = warning

# CA2252: This API requires opting into preview features
dotnet_diagnostic.CA2252.severity = none
dotnet_diagnostic.CA2252.severity = error

# CA2253: Named placeholders should not be numeric values
dotnet_diagnostic.CA2253.severity = none
Expand Down
2 changes: 1 addition & 1 deletion eng/CodeAnalysis.test.globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ dotnet_diagnostic.CA2250.severity = none
dotnet_diagnostic.CA2251.severity = none

# CA2252: This API requires opting into preview features
dotnet_diagnostic.CA2252.severity = none
dotnet_diagnostic.CA2252.severity = error

# CA2253: Named placeholders should not be numeric values
dotnet_diagnostic.CA2253.severity = none
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/Byte.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ namespace System
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly struct Byte : IComparable, IConvertible, ISpanFormattable, IComparable<byte>, IEquatable<byte>
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IBinaryInteger<byte>,
IMinMaxValue<byte>,
IUnsignedNumber<byte>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
private readonly byte m_value; // Do not rename (binary serialization)
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/Char.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ namespace System
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly struct Char : IComparable, IComparable<char>, IEquatable<char>, IConvertible, ISpanFormattable
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IBinaryInteger<char>,
IMinMaxValue<char>,
IUnsignedNumber<char>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
//
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/DateOnly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ namespace System
/// </summary>
public readonly struct DateOnly : IComparable, IComparable<DateOnly>, IEquatable<DateOnly>, ISpanFormattable
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IComparisonOperators<DateOnly, DateOnly>,
IMinMaxValue<DateOnly>,
ISpanParseable<DateOnly>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
private readonly int _dayNumber;
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/DateTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ namespace System
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly partial struct DateTime : IComparable, ISpanFormattable, IConvertible, IComparable<DateTime>, IEquatable<DateTime>, ISerializable
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IAdditionOperators<DateTime, TimeSpan, DateTime>,
IAdditiveIdentity<DateTime, TimeSpan>,
IComparisonOperators<DateTime, DateTime>,
IMinMaxValue<DateTime>,
ISpanParseable<DateTime>,
ISubtractionOperators<DateTime, TimeSpan, DateTime>,
ISubtractionOperators<DateTime, DateTime, TimeSpan>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
// Number of 100ns ticks per time unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ namespace System
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly struct DateTimeOffset : IComparable, ISpanFormattable, IComparable<DateTimeOffset>, IEquatable<DateTimeOffset>, ISerializable, IDeserializationCallback
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IAdditionOperators<DateTimeOffset, TimeSpan, DateTimeOffset>,
IAdditiveIdentity<DateTimeOffset, TimeSpan>,
IComparisonOperators<DateTimeOffset, DateTimeOffset>,
IMinMaxValue<DateTimeOffset>,
ISpanParseable<DateTimeOffset>,
ISubtractionOperators<DateTimeOffset, TimeSpan, DateTimeOffset>,
ISubtractionOperators<DateTimeOffset, DateTimeOffset, TimeSpan>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
// Constants
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/Decimal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ namespace System
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly partial struct Decimal : ISpanFormattable, IComparable, IConvertible, IComparable<decimal>, IEquatable<decimal>, ISerializable, IDeserializationCallback
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IMinMaxValue<decimal>,
ISignedNumber<decimal>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
// Sign mask for the flags field. A value of zero in this bit indicates a
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/Double.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ namespace System
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly struct Double : IComparable, IConvertible, ISpanFormattable, IComparable<double>, IEquatable<double>
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IBinaryFloatingPoint<double>,
IMinMaxValue<double>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
private readonly double m_value; // Do not rename (binary serialization)
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/Guid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ namespace System
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly partial struct Guid : ISpanFormattable, IComparable, IComparable<Guid>, IEquatable<Guid>
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IComparisonOperators<Guid, Guid>,
ISpanParseable<Guid>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
public static readonly Guid Empty;
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/Half.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ namespace System
[StructLayout(LayoutKind.Sequential)]
public readonly struct Half : IComparable, ISpanFormattable, IComparable<Half>, IEquatable<Half>
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IBinaryFloatingPoint<Half>,
IMinMaxValue<Half>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
private const NumberStyles DefaultParseStyle = NumberStyles.Float | NumberStyles.AllowThousands;
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/Int16.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ namespace System
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly struct Int16 : IComparable, IConvertible, ISpanFormattable, IComparable<short>, IEquatable<short>
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IBinaryInteger<short>,
IMinMaxValue<short>,
ISignedNumber<short>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
private readonly short m_value; // Do not rename (binary serialization)
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/Int32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ namespace System
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly struct Int32 : IComparable, IConvertible, ISpanFormattable, IComparable<int>, IEquatable<int>
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IBinaryInteger<int>,
IMinMaxValue<int>,
ISignedNumber<int>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
private readonly int m_value; // Do not rename (binary serialization)
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/Int64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ namespace System
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly struct Int64 : IComparable, IConvertible, ISpanFormattable, IComparable<long>, IEquatable<long>
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IBinaryInteger<long>,
IMinMaxValue<long>,
ISignedNumber<long>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
private readonly long m_value; // Do not rename (binary serialization)
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/IntPtr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ namespace System
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly struct IntPtr : IEquatable<nint>, IComparable, IComparable<nint>, ISpanFormattable, ISerializable
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IBinaryInteger<nint>,
IMinMaxValue<nint>,
ISignedNumber<nint>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
// WARNING: We allow diagnostic tools to directly inspect this member (_value).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public static bool IsSupported(string feature)
case CovariantReturnsOfClasses:
case UnmanagedSignatureCallingConvention:
case DefaultImplementationsOfInterfaces:
#pragma warning disable CA2252
case VirtualStaticsInInterfaces:
#pragma warning restore CA2252
return true;
case nameof(IsDynamicCodeSupported):
return IsDynamicCodeSupported;
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/SByte.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ namespace System
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly struct SByte : IComparable, IConvertible, ISpanFormattable, IComparable<sbyte>, IEquatable<sbyte>
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IBinaryInteger<sbyte>,
IMinMaxValue<sbyte>,
ISignedNumber<sbyte>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
private readonly sbyte m_value; // Do not rename (binary serialization)
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/Single.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ namespace System
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly struct Single : IComparable, IConvertible, ISpanFormattable, IComparable<float>, IEquatable<float>
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IBinaryFloatingPoint<float>,
IMinMaxValue<float>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
private readonly float m_value; // Do not rename (binary serialization)
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/TimeOnly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ namespace System
/// </summary>
public readonly struct TimeOnly : IComparable, IComparable<TimeOnly>, IEquatable<TimeOnly>, ISpanFormattable
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IComparisonOperators<TimeOnly, TimeOnly>,
IMinMaxValue<TimeOnly>,
ISpanParseable<TimeOnly>,
ISubtractionOperators<TimeOnly, TimeOnly, TimeSpan>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
// represent the number of ticks map to the time of the day. 1 ticks = 100-nanosecond in time measurements.
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/TimeSpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace System
[Serializable]
public readonly struct TimeSpan : IComparable, IComparable<TimeSpan>, IEquatable<TimeSpan>, ISpanFormattable
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IAdditionOperators<TimeSpan, TimeSpan, TimeSpan>,
IAdditiveIdentity<TimeSpan, TimeSpan>,
IComparisonOperators<TimeSpan, TimeSpan>,
Expand All @@ -41,7 +41,7 @@ namespace System
ISubtractionOperators<TimeSpan, TimeSpan, TimeSpan>,
IUnaryNegationOperators<TimeSpan, TimeSpan>,
IUnaryPlusOperators<TimeSpan, TimeSpan>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
public const long TicksPerMillisecond = 10000;
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/UInt16.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ namespace System
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly struct UInt16 : IComparable, IConvertible, ISpanFormattable, IComparable<ushort>, IEquatable<ushort>
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IBinaryInteger<ushort>,
IMinMaxValue<ushort>,
IUnsignedNumber<ushort>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
private readonly ushort m_value; // Do not rename (binary serialization)
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/UInt32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ namespace System
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly struct UInt32 : IComparable, IConvertible, ISpanFormattable, IComparable<uint>, IEquatable<uint>
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IBinaryInteger<uint>,
IMinMaxValue<uint>,
IUnsignedNumber<uint>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
private readonly uint m_value; // Do not rename (binary serialization)
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/UInt64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ namespace System
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly struct UInt64 : IComparable, IConvertible, ISpanFormattable, IComparable<ulong>, IEquatable<ulong>
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IBinaryInteger<ulong>,
IMinMaxValue<ulong>,
IUnsignedNumber<ulong>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
private readonly ulong m_value; // Do not rename (binary serialization)
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ namespace System
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly struct UIntPtr : IEquatable<nuint>, IComparable, IComparable<nuint>, ISpanFormattable, ISerializable
#if FEATURE_GENERIC_MATH
#pragma warning disable SA1001
#pragma warning disable SA1001, CA2252 // SA1001: Comma positioning; CA2252: Preview Features
, IBinaryInteger<nuint>,
IMinMaxValue<nuint>,
IUnsignedNumber<nuint>
#pragma warning restore SA1001
#pragma warning restore SA1001, CA2252
#endif // FEATURE_GENERIC_MATH
{
private readonly unsafe void* _value; // Do not rename (binary serialization)
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/System.Runtime/src/System.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
<Nullable>enable</Nullable>
<!-- The following 2 lines disable the automatic generation of the [RequiresPreviewFeatures] assembly level attribute and set LangVersion to Preview on the latest TFM-->
<EnablePreviewFeatures>True</EnablePreviewFeatures>
<GenerateRequiresPreviewFeaturesAttribute>False</GenerateRequiresPreviewFeaturesAttribute>
</PropertyGroup>
<ItemGroup>
<!-- Compiler throws error if you try to use System.Void and instructs you to use void keyword instead. So we have manually added a typeforward for this type. -->
Expand Down

0 comments on commit d2cef2f

Please sign in to comment.