Skip to content

Commit 6de7147

Browse files
authored
Enable IDE0059 analyzer: Unnecessary assignment of a value (#63340)
1 parent 635cfb3 commit 6de7147

File tree

505 files changed

+1164
-1740
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

505 files changed

+1164
-1740
lines changed

eng/CodeAnalysis.src.globalconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,7 @@ dotnet_diagnostic.IDE0057.severity = suggestion
14441444
dotnet_diagnostic.IDE0058.severity = silent
14451445

14461446
# IDE0059: Unnecessary assignment of a value
1447-
dotnet_diagnostic.IDE0059.severity = suggestion
1447+
dotnet_diagnostic.IDE0059.severity = warning
14481448

14491449
# IDE0060: Remove unused parameter
14501450
dotnet_diagnostic.IDE0060.severity = silent

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.CoreRT.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,6 @@ private unsafe IntPtr AsRuntimeDefined(in Guid riid)
213213
{
214214
return (IntPtr)(Dispatches + i);
215215
}
216-
217-
i++;
218216
}
219217

220218
return IntPtr.Zero;

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.CoreRT.Windows.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,10 @@ private unsafe bool CreateThread(GCHandle thisThreadHandle)
200200
stackSize = AllocationGranularity;
201201
}
202202

203-
uint threadId;
204203
_osHandle = Interop.Kernel32.CreateThread(IntPtr.Zero, (IntPtr)stackSize,
205204
&ThreadEntryPoint, (IntPtr)thisThreadHandle,
206205
Interop.Kernel32.CREATE_SUSPENDED | Interop.Kernel32.STACK_SIZE_PARAM_IS_A_RESERVATION,
207-
out threadId);
206+
out _);
208207

209208
if (_osHandle.IsInvalid)
210209
{

src/coreclr/nativeaot/System.Private.Interop/src/Internal/Runtime/CompilerHelpers/RuntimeInteropData.CoreRT.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ public override bool TryGetStructUnsafeStructSize(RuntimeTypeHandle structureTyp
4444

4545
public override bool TryGetStructFieldOffset(RuntimeTypeHandle structureTypeHandle, string fieldName, out bool structExists, out uint offset)
4646
{
47-
ExternalReferencesTable externalReferences;
4847
NativeParser entryParser;
4948
structExists = false;
50-
if (TryGetStructData(structureTypeHandle, out externalReferences, out entryParser))
49+
if (TryGetStructData(structureTypeHandle, out _, out entryParser))
5150
{
5251
structExists = true;
5352

src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/ActivatorImplementation.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ public static object CreateInstance(
8888
if (binder == null)
8989
binder = Type.DefaultBinder;
9090

91-
object state = null;
92-
MethodBase invokeMethod = binder.BindToMethod(bindingAttr, matches.ToArray(), ref args, null, culture, null, out state);
91+
MethodBase invokeMethod = binder.BindToMethod(bindingAttr, matches.ToArray(), ref args, null, culture, null, out object state);
9392
if (invokeMethod.GetParametersNoCopy().Length == 0)
9493
{
9594
if (args.Length != 0)

src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/Assemblies/NativeFormat/NativeFormatRuntimeAssembly.GetTypeCore.CaseInsensitive.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ private LowLevelDictionary<string, QHandle> CreateCaseInsensitiveTypeDictionary(
9999
foreach (TypeDefinitionHandle typeDefinitionHandle in namespaceDefinition.TypeDefinitions)
100100
{
101101
string fullName = ns + typeDefinitionHandle.GetTypeDefinition(reader).Name.GetString(reader).ToLowerInvariant();
102-
QHandle existingValue;
103-
if (!dict.TryGetValue(fullName, out existingValue))
102+
if (!dict.TryGetValue(fullName, out _))
104103
{
105104
dict.Add(fullName, new QHandle(reader, typeDefinitionHandle));
106105
}
@@ -109,8 +108,7 @@ private LowLevelDictionary<string, QHandle> CreateCaseInsensitiveTypeDictionary(
109108
foreach (TypeForwarderHandle typeForwarderHandle in namespaceDefinition.TypeForwarders)
110109
{
111110
string fullName = ns + typeForwarderHandle.GetTypeForwarder(reader).Name.GetString(reader).ToLowerInvariant();
112-
QHandle existingValue;
113-
if (!dict.TryGetValue(fullName, out existingValue))
111+
if (!dict.TryGetValue(fullName, out _))
114112
{
115113
dict.Add(fullName, new QHandle(reader, typeForwarderHandle));
116114
}

src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/BindingFlagSupport/Shared.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,9 @@ public static bool QualifiesBasedOnParameterCount(this MethodBase methodBase, Bi
149149
public static M GetImplicitlyOverriddenBaseClassMember<M>(this M member) where M : MemberInfo
150150
{
151151
MemberPolicies<M> policies = MemberPolicies<M>.Default;
152-
MethodAttributes visibility;
153-
bool isStatic;
154152
bool isVirtual;
155153
bool isNewSlot;
156-
policies.GetMemberAttributes(member, out visibility, out isStatic, out isVirtual, out isNewSlot);
154+
policies.GetMemberAttributes(member, out _, out _, out isVirtual, out isNewSlot);
157155
if (isNewSlot || !isVirtual)
158156
{
159157
return null;
@@ -174,11 +172,8 @@ public static M GetImplicitlyOverriddenBaseClassMember<M>(this M member) where M
174172
{
175173
continue;
176174
}
177-
MethodAttributes candidateVisibility;
178-
bool isCandidateStatic;
179175
bool isCandidateVirtual;
180-
bool isCandidateNewSlot;
181-
policies.GetMemberAttributes(member, out candidateVisibility, out isCandidateStatic, out isCandidateVirtual, out isCandidateNewSlot);
176+
policies.GetMemberAttributes(member, out _, out _, out isCandidateVirtual, out _);
182177
if (!isCandidateVirtual)
183178
{
184179
continue;

src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/CustomAttributes/RuntimeCustomAttributeData.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,10 @@ private static string ComputeTypedArgumentString(CustomAttributeTypedArgument ca
146146

147147
else if (argumentType.IsArray)
148148
{
149-
string result = null;
150149
IList<CustomAttributeTypedArgument> array = value as IList<CustomAttributeTypedArgument>;
151150

152151
Type elementType = argumentType.GetElementType();
153-
result = string.Format(@"new {0}[{1}] {{ ", elementType.IsEnum ? elementType.FullName : elementType.Name, array.Count);
152+
string result = string.Format(@"new {0}[{1}] {{ ", elementType.IsEnum ? elementType.FullName : elementType.Name, array.Count);
154153

155154
for (int i = 0; i < array.Count; i++)
156155
result += string.Format(i == 0 ? "{0}" : ", {0}", ComputeTypedArgumentString(array[i], elementType != typeof(object)));

src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/NamespaceChain.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal NamespaceChain(MetadataReader reader, NamespaceDefinitionHandle innerMo
2121
{
2222
NamespaceDefinition currentNamespaceDefinition = innerMostNamespaceHandle.GetNamespaceDefinition(reader);
2323
ConstantStringValueHandle currentNameHandle = currentNamespaceDefinition.Name;
24-
Handle currentNamespaceHandle = innerMostNamespaceHandle.ToHandle(reader);
24+
Handle currentNamespaceHandle;
2525
LowLevelList<string> names = new LowLevelList<string>();
2626
for (;;)
2727
{

src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/ReflectionCoreCallbacksImplementation.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ private FieldInfo GetFieldInfo(RuntimeTypeHandle declaringTypeHandle, FieldHandl
164164
{
165165
RuntimeTypeInfo contextTypeInfo = declaringTypeHandle.GetTypeForRuntimeTypeHandle();
166166
NativeFormatRuntimeNamedTypeInfo definingTypeInfo = contextTypeInfo.AnchoringTypeDefinitionForDeclaredMembers.CastToNativeFormatRuntimeNamedTypeInfo();
167-
MetadataReader reader = definingTypeInfo.Reader;
168167

169168
// RuntimeFieldHandles always yield FieldInfo's whose ReflectedType equals the DeclaringType.
170169
RuntimeTypeInfo reflectedType = contextTypeInfo;

0 commit comments

Comments
 (0)