Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable IDE0054 (Use compound assignment) #70564

Merged
merged 2 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/CodeAnalysis.src.globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@ dotnet_diagnostic.IDE0052.severity = suggestion
dotnet_diagnostic.IDE0053.severity = silent

# IDE0054: Use compound assignment
dotnet_diagnostic.IDE0054.severity = suggestion
dotnet_diagnostic.IDE0054.severity = warning

# IDE0055: Fix formatting
dotnet_diagnostic.IDE0055.severity = suggestion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public unsafe IntPtr AllocateThunk()

int thunkIndex = (int)(((nuint)(nint)nextAvailableThunkPtr) - ((nuint)(nint)nextAvailableThunkPtr & ~Constants.PageSizeMask));
Debug.Assert((thunkIndex % Constants.ThunkDataSize) == 0);
thunkIndex = thunkIndex / Constants.ThunkDataSize;
thunkIndex /= Constants.ThunkDataSize;

IntPtr thunkAddress = InternalCalls.RhpGetThunkStubsBlockAddress(nextAvailableThunkPtr) + thunkIndex * Constants.ThunkCodeSize;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ internal static unsafe Array NewMultiDimArray(EETypePtr eeType, int* pLengths, i
throw new OverflowException();
if (length > MaxLength)
maxArrayDimensionLengthOverflow = true;
totalLength = totalLength * (ulong)length;
totalLength *= (ulong)length;
if (totalLength > int.MaxValue)
throw new OutOfMemoryException(); // "Array dimensions exceeded supported range."
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private LowLevelDictionary<string, QHandle> CreateCaseInsensitiveTypeDictionary(
{
string ns = namespaceHandle.ToNamespaceName(reader);
if (ns.Length != 0)
ns = ns + ".";
ns += ".";
ns = ns.ToLowerInvariant();

NamespaceDefinition namespaceDefinition = namespaceHandle.GetNamespaceDefinition(reader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ public static unsafe string ToHexStringUnsignedLong(ulong u, bool zeroPrepad, in
for (; i >= 0; i--)
{
chars[i] = GetHexChar((uint)(u % 16));
u = u / 16;
u /= 16;

if ((i == 0) || (!zeroPrepad && (u == 0)))
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ internal static string ToDisplayStringIfAvailable(this Type type, List<int> gene
{
genericParameterOffsets.Add(s.Length);
if (genericArgCount > 0)
s = s + ",";
s += ",";
}
s += "]";
}
Expand Down Expand Up @@ -283,7 +283,7 @@ private static string CreateConstructedGenericTypeStringIfAvailable(Type generic
// Similarly, if we found too few, add them at the end.
while (genericTypeArguments.Length > genericParameterOffsets.Count)
{
genericTypeDefinitionString = genericTypeDefinitionString + ",";
genericTypeDefinitionString += ",";
genericParameterOffsets.Add(genericTypeDefinitionString.Length);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ private static unsafe int CreateGCDesc(LowLevelList<bool> bitfield, int size, bo
}
else
{
seriesSize = seriesSize - size;
seriesSize -= size;
*ptr-- = (void*)seriesOffset;
*ptr-- = (void*)seriesSize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public unsafe RuntimeFieldHandle GetRuntimeFieldHandleForComponents(RuntimeTypeH
fieldData->FieldName = fieldName;

// Special flag (lowest bit set) in the handle value to indicate it was dynamically allocated
runtimeFieldHandleValue = runtimeFieldHandleValue + 1;
runtimeFieldHandleValue++;
runtimeFieldHandle = *(RuntimeFieldHandle*)&runtimeFieldHandleValue;

_runtimeFieldHandles.Add(key, runtimeFieldHandle);
Expand All @@ -232,7 +232,7 @@ private unsafe bool TryGetDynamicRuntimeFieldHandleComponents(RuntimeFieldHandle

// Special flag in the handle value to indicate it was dynamically allocated
Debug.Assert((runtimeFieldHandleValue.ToInt64() & 0x1) == 0x1);
runtimeFieldHandleValue = runtimeFieldHandleValue - 1;
runtimeFieldHandleValue--;

DynamicFieldHandleInfo* fieldData = (DynamicFieldHandleInfo*)runtimeFieldHandleValue.ToPointer();
declaringTypeHandle = *(RuntimeTypeHandle*)&(fieldData->DeclaringType);
Expand Down Expand Up @@ -317,7 +317,7 @@ public unsafe RuntimeMethodHandle GetRuntimeMethodHandleForComponents(RuntimeTyp
}

// Special flag in the handle value to indicate it was dynamically allocated, and doesn't point into the InvokeMap blob
runtimeMethodHandleValue = runtimeMethodHandleValue + 1;
runtimeMethodHandleValue++;
runtimeMethodHandle = * (RuntimeMethodHandle*)&runtimeMethodHandleValue;

_runtimeMethodHandles.Add(key, runtimeMethodHandle);
Expand All @@ -344,7 +344,7 @@ private unsafe bool TryGetDynamicRuntimeMethodHandleComponents(RuntimeMethodHand
Debug.Assert((runtimeMethodHandleValue.ToInt64() & 0x1) == 0x1);

// Special flag in the handle value to indicate it was dynamically allocated, and doesn't point into the InvokeMap blob
runtimeMethodHandleValue = runtimeMethodHandleValue - 1;
runtimeMethodHandleValue--;

DynamicMethodHandleInfo* methodData = (DynamicMethodHandleInfo*)runtimeMethodHandleValue.ToPointer();
declaringTypeHandle = *(RuntimeTypeHandle*)&(methodData->DeclaringType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public static unsafe IntPtr TryGetStaticClassConstructionContext(RuntimeTypeHand

// what we have now is the base address of the non-gc statics of the type
// what we need is the cctor context, which is just before that
ptr = ptr - sizeof(System.Runtime.CompilerServices.StaticClassConstructionContext);
ptr -= sizeof(System.Runtime.CompilerServices.StaticClassConstructionContext);

return (IntPtr)ptr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ internal static uint ComputeValueTypeFieldPaddingFieldValue(uint padding, uint a
while ((alignment & 1) == 0)
{
alignmentLog2++;
alignment = alignment >> 1;
alignment >>= 1;
}
Debug.Assert(alignment == 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private void SetFieldLayout(List<FieldLayoutInterval> fieldLayoutInterval, int o
previousInterval.EndSentinel = newInterval.EndSentinel;

fieldLayoutInterval[newIntervalLocation - 1] = previousInterval;
newIntervalLocation = newIntervalLocation - 1;
newIntervalLocation--;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private static string IntToString(int arg)
while (arg != 0)
{
sb.Append((char)('0' + (arg % 10)));
arg = arg / 10;
arg /= 10;
}

// Reverse the string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private string GenerateDeterministicId()

public long Write(BinaryWriter writer)
{
BundleID = BundleID ?? GenerateDeterministicId();
BundleID ??= GenerateDeterministicId();

long startOffset = writer.BaseStream.Position;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private static SslProtocols CalculateEffectiveProtocols(SslAuthenticationOptions
if (protocols != SslProtocols.None &&
CipherSuitesPolicyPal.WantsTls13(protocols))
{
protocols = protocols & (~SslProtocols.Tls13);
protocols &= ~SslProtocols.Tls13;
}
}
else if (CipherSuitesPolicyPal.WantsTls13(protocols) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static unsafe void InitializeReferencedDomainsList(this SafeLsaMemoryHand
if (domainList.Domains != IntPtr.Zero)
{
Interop.LSA_TRUST_INFORMATION* pTrustInformation = (Interop.LSA_TRUST_INFORMATION*)domainList.Domains;
pTrustInformation = pTrustInformation + domainList.Entries;
pTrustInformation += domainList.Entries;

long bufferSize = (byte*)pTrustInformation - pRdl;
System.Diagnostics.Debug.Assert(bufferSize > 0, "bufferSize > 0");
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Common/src/System/IO/RowConfigReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private bool TryFindNextKeyOccurrence(string key, int startIndex, out int keyInd
}
}

startIndex = startIndex + key.Length;
startIndex += key.Length;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ public bool TryDecode(byte b, out int result)
throw new HPackDecodingException(SR.net_http_hpack_bad_integer);
}

_i = _i + ((b & 0x7f) << _m);
_i += ((b & 0x7f) << _m);

// If the addition overflowed, the result will be negative.
if (_i < 0)
{
throw new HPackDecodingException(SR.net_http_hpack_bad_integer);
}

_m = _m + 7;
_m += 7;

if ((b & 128) == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static bool Encode(int value, int numBits, Span<byte> destination, out in
return false;
}

value = value - ((1 << numBits) - 1);
value -= ((1 << numBits) - 1);
int i = 1;

while (value >= 128)
Expand All @@ -63,7 +63,7 @@ public static bool Encode(int value, int numBits, Span<byte> destination, out in
return false;
}

value = value / 128;
value /= 128;
}
destination[i++] = (byte)value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ private bool GetStandardAndLiftedBinopSignatures(List<BinOpFullSig> rgbofs, BinO
switch (GetConvKind(info.ptRaw1, bos.pt1))
{
default:
grflt = grflt | LiftFlags.Convert1;
grflt |= LiftFlags.Convert1;
break;
case ConvKind.Implicit:
case ConvKind.Identity:
grflt = grflt | LiftFlags.Lift1;
grflt |= LiftFlags.Lift1;
break;
}
break;
Expand All @@ -272,11 +272,11 @@ private bool GetStandardAndLiftedBinopSignatures(List<BinOpFullSig> rgbofs, BinO
switch (GetConvKind(info.ptRaw1, bos.pt1))
{
default:
grflt = grflt | LiftFlags.Convert1;
grflt |= LiftFlags.Convert1;
break;
case ConvKind.Implicit:
case ConvKind.Identity:
grflt = grflt | LiftFlags.Lift1;
grflt |= LiftFlags.Lift1;
break;
}
break;
Expand Down Expand Up @@ -330,11 +330,11 @@ private bool GetStandardAndLiftedBinopSignatures(List<BinOpFullSig> rgbofs, BinO
switch (GetConvKind(info.ptRaw2, bos.pt2))
{
default:
grflt = grflt | LiftFlags.Convert2;
grflt |= LiftFlags.Convert2;
break;
case ConvKind.Implicit:
case ConvKind.Identity:
grflt = grflt | LiftFlags.Lift2;
grflt |= LiftFlags.Lift2;
break;
}
break;
Expand All @@ -357,11 +357,11 @@ private bool GetStandardAndLiftedBinopSignatures(List<BinOpFullSig> rgbofs, BinO
switch (GetConvKind(info.ptRaw2, bos.pt2))
{
default:
grflt = grflt | LiftFlags.Convert2;
grflt |= LiftFlags.Convert2;
break;
case ConvKind.Implicit:
case ConvKind.Identity:
grflt = grflt | LiftFlags.Lift2;
grflt |= LiftFlags.Lift2;
break;
}
break;
Expand Down Expand Up @@ -750,7 +750,7 @@ private bool CanConvertArg1(BinOpArgInfo info, CType typeDst, out LiftFlags pgrf

if (info.type2 is NullableType)
{
pgrflt = pgrflt | LiftFlags.Lift2;
pgrflt |= LiftFlags.Lift2;
ptypeSig2 = TypeManager.GetNullable(info.typeRaw2);
}
else
Expand Down Expand Up @@ -785,7 +785,7 @@ private bool CanConvertArg2(BinOpArgInfo info, CType typeDst, out LiftFlags pgrf

if (info.type1 is NullableType)
{
pgrflt = pgrflt | LiftFlags.Lift1;
pgrflt |= LiftFlags.Lift1;
ptypeSig1 = TypeManager.GetNullable(info.typeRaw1);
}
else
Expand All @@ -809,7 +809,7 @@ private static void RecordBinOpSigFromArgs(List<BinOpFullSig> prgbofs, BinOpArgI
if (info.type1 != info.typeRaw1)
{
Debug.Assert(info.type1 is NullableType);
grflt = grflt | LiftFlags.Lift1;
grflt |= LiftFlags.Lift1;
typeSig1 = TypeManager.GetNullable(info.typeRaw1);
}
else
Expand All @@ -820,7 +820,7 @@ private static void RecordBinOpSigFromArgs(List<BinOpFullSig> prgbofs, BinOpArgI
if (info.type2 != info.typeRaw2)
{
Debug.Assert(info.type2 is NullableType);
grflt = grflt | LiftFlags.Lift2;
grflt |= LiftFlags.Lift2;
typeSig2 = TypeManager.GetNullable(info.typeRaw2);
}
else
Expand Down Expand Up @@ -1482,11 +1482,11 @@ private bool FindApplicableSignatures(
switch (GetConvKind(ptRaw, uos.pt))
{
default:
grflt = grflt | LiftFlags.Convert1;
grflt |= LiftFlags.Convert1;
break;
case ConvKind.Implicit:
case ConvKind.Identity:
grflt = grflt | LiftFlags.Lift1;
grflt |= LiftFlags.Lift1;
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private static void AddNamesInInheritanceHierarchy(string name, List<Type> inher
else if (member is EventInfo e)
{
// Store events until after all fields
(events = events ?? new List<EventInfo>()).Add(e);
(events ??= new List<EventInfo>()).Add(e);
}
} while (memberEn.MoveNext());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static int PopCount(uint value)
const uint c3 = 0x_0F0F0F0Fu;
const uint c4 = 0x_01010101u;

value = value - ((value >> 1) & c1);
value -= (value >> 1) & c1;
value = (value & c2) + ((value >> 2) & c2);
value = (((value + (value >> 4)) & c3) * c4) >> 24;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ internal ServiceProvider(ICollection<ServiceDescriptor> serviceDescriptors, Serv
}
catch (Exception e)
{
exceptions = exceptions ?? new List<Exception>();
exceptions ??= new List<Exception>();
exceptions.Add(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override void PushDirectory(DirectoryInfoBase directory)
}

// directory matches segment, advance position in pattern
frame.SegmentIndex = frame.SegmentIndex + 1;
frame.SegmentIndex++;
}

PushDataFrame(frame);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public OptionsManager(IOptionsFactory<TOptions> factory)
/// </summary>
public virtual TOptions Get(string? name)
{
name = name ?? Options.DefaultName;
name ??= Options.DefaultName;

if (!_cache.TryGetValue(name, out TOptions? options))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void RegisterSource(IOptionsChangeTokenSource<TOptions> source)

private void InvokeChanged(string? name)
{
name = name ?? Options.DefaultName;
name ??= Options.DefaultName;
_cache.TryRemove(name);
TOptions options = Get(name);
if (_onChange != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ private static void GenerateFile(List<string> typeNames, string defaultNamespace
var allMappings = mappings.ToArray();

bool gac = assembly.GlobalAssemblyCache;
outputDirectory = outputDirectory ?? (gac ? Environment.CurrentDirectory : Path.GetDirectoryName(assembly.Location));
outputDirectory ??= (gac ? Environment.CurrentDirectory : Path.GetDirectoryName(assembly.Location));

if (!Directory.Exists(outputDirectory))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,8 @@ internal void LocalPush(T item, ref long emptyToNonEmptyListTransitionCount)
// the bit-masking, because we only do this if tail == int.MaxValue, meaning that all
// bits are set, so all of the bits we're keeping will also be set. Thus it's impossible
// for the head to end up > than the tail, since you can't set any more bits than all of them.
_headIndex = _headIndex & _mask;
_tailIndex = tail = tail & _mask;
_headIndex &= _mask;
_tailIndex = tail &= _mask;
Debug.Assert(_headIndex - _tailIndex <= 0);

Interlocked.Exchange(ref _currentOp, (int)Operation.Add); // ensure subsequent reads aren't reordered before this
Expand Down
Loading