Skip to content

Commit

Permalink
Enable IDE0060 (Remove unused parameter) analyzer (#72667)
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-safar authored Nov 8, 2022
1 parent 134968a commit 8918adf
Show file tree
Hide file tree
Showing 527 changed files with 1,680 additions and 1,947 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,3 @@ indent_size = 2
end_of_line = lf
[*.{cmd,bat}]
end_of_line = crlf

2 changes: 1 addition & 1 deletion eng/CodeAnalysis.src.globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@ dotnet_diagnostic.IDE0058.severity = silent
dotnet_diagnostic.IDE0059.severity = warning

# IDE0060: Remove unused parameter
dotnet_diagnostic.IDE0060.severity = silent
dotnet_diagnostic.IDE0060.severity = warning
dotnet_code_quality_unused_parameters = non_public

# IDE0061: Use expression body for local functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Runtime.InteropServices;
using System.Runtime.Loader;

#pragma warning disable IDE0060

namespace Internal.Runtime.InteropServices
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal static void BulkMoveWithWriteBarrier(ref byte destination, ref byte sou
_BulkMoveWithWriteBarrier(ref destination, ref source, byteCount);
}

#pragma warning disable IDE0060 // https://github.com/dotnet/roslyn-analyzers/issues/6228
// Non-inlinable wrapper around the loop for copying large blocks in chunks
[MethodImpl(MethodImplOptions.NoInlining)]
private static void _BulkMoveWithWriteBarrier(ref byte destination, ref byte source, nuint byteCount)
Expand Down Expand Up @@ -72,6 +73,7 @@ private static void _BulkMoveWithWriteBarrier(ref byte destination, ref byte sou
}
__BulkMoveWithWriteBarrier(ref destination, ref source, byteCount);
}
#pragma warning restore IDE0060 // https://github.com/dotnet/roslyn-analyzers/issues/6228

[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void __BulkMoveWithWriteBarrier(ref byte destination, ref byte source, nuint byteCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ public static string GetTypeInfoName(ITypeInfo typeInfo)
return strTypeLibName;
}

#pragma warning disable IDE0060
// This method is identical to Type.GetTypeFromCLSID. Since it's interop specific, we expose it
// on Marshal for more consistent API surface.
internal static Type? GetTypeFromCLSID(Guid clsid, string? server, bool throwOnError)
Expand All @@ -327,6 +328,7 @@ public static string GetTypeInfoName(ITypeInfo typeInfo)
GetTypeFromCLSID(clsid, server, ObjectHandleOnStack.Create(ref type));
return type;
}
#pragma warning restore IDE0060

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "MarshalNative_GetTypeFromCLSID", StringMarshalling = StringMarshalling.Utf16)]
private static partial void GetTypeFromCLSID(in Guid clsid, string? server, ObjectHandleOnStack retType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3774,7 +3774,7 @@ private CheckValueStatus TryChangeType(
CorElementType dstElementType = GetUnderlyingType(this);
if (dstElementType != srcElementType)
{
value = InvokeUtils.ConvertOrWiden(srcType, srcElementType, value, this, dstElementType);
value = InvokeUtils.ConvertOrWiden(srcType, value, this, dstElementType);
}
}

Expand Down Expand Up @@ -3929,7 +3929,7 @@ private void CreateInstanceCheckThis()
}

// fast path??
instance = CreateInstanceLocal(this, nonPublic: true, wrapExceptions: wrapExceptions);
instance = CreateInstanceLocal(wrapExceptions: wrapExceptions);
}
else
{
Expand All @@ -3943,7 +3943,7 @@ private void CreateInstanceCheckThis()

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2082:UnrecognizedReflectionPattern",
Justification = "Implementation detail of Activator that linker intrinsically recognizes")]
object? CreateInstanceLocal(Type type, bool nonPublic, bool wrapExceptions)
object? CreateInstanceLocal(bool wrapExceptions)
{
return Activator.CreateInstance(this, nonPublic: true, wrapExceptions: wrapExceptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public V GetOrAdd(K key)
return heyIWasHereFirst;
if (!_container.HasCapacity)
_container.Resize(); // This overwrites the _container field.
_container.Add(key, hashCode, value);
_container.Add(hashCode, value);
return value;
}
}
Expand Down Expand Up @@ -218,7 +218,7 @@ public bool TryGetValue(K key, int hashCode, out V value)
return false;
}

public void Add(K key, int hashCode, V value)
public void Add(int hashCode, V value)
{
Debug.Assert(_owner._lock.IsAcquired);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace System
[AttributeUsage(AttributeTargets.Class, Inherited = true)]
public sealed class AttributeUsageAttribute : Attribute
{
#pragma warning disable IDE0060
//Constructors
public AttributeUsageAttribute(AttributeTargets validOn)
{
Expand All @@ -24,6 +25,7 @@ public AttributeUsageAttribute(AttributeTargets validOn)
public AttributeUsageAttribute(AttributeTargets validOn, bool allowMultiple, bool inherited)
{
}
#pragma warning restore IDE0060

//Properties.
// Allowing the set properties as it allows a more readable syntax in the specifiers (and are commonly used)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ private struct EHEnum
private IntPtr _dummy; // For alignment
}

#pragma warning disable IDE0060
// This is a fail-fast function used by the runtime as a last resort that will terminate the process with
// as little effort as possible. No guarantee is made about the semantics of this fail-fast.
internal static void FallbackFailFast(RhFailFastReason reason, object unhandledException)
{
InternalCalls.RhpFallbackFailFast();
}
#pragma warning restore IDE0060

// Given an address pointing somewhere into a managed module, get the classlib-defined fail-fast
// function and invoke it. Any failure to find and invoke the function, or if it returns, results in
Expand Down Expand Up @@ -921,6 +923,7 @@ private static void InvokeSecondPass(ref ExInfo exInfo, uint idxStart, uint idxL
}
}

#pragma warning disable IDE0060
[UnmanagedCallersOnly(EntryPoint = "RhpFailFastForPInvokeExceptionPreemp", CallConvs = new Type[] { typeof(CallConvCdecl) })]
public static void RhpFailFastForPInvokeExceptionPreemp(IntPtr PInvokeCallsiteReturnAddr, void* pExceptionRecord, void* pContextRecord)
{
Expand All @@ -931,5 +934,7 @@ public static void RhpFailFastForPInvokeExceptionCoop(IntPtr classlibBreadcrumb,
{
FailFastViaClasslib(RhFailFastReason.UnhandledExceptionFromPInvoke, null, classlibBreadcrumb);
}
#pragma warning restore IDE0060

} // static class EH
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using System;

#if FEATURE_COMINTEROP || FEATURE_COMWRAPPERS

#pragma warning disable IDE0060

namespace System
{
internal sealed partial class ComAwareWeakReference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

namespace System
{
[DebuggerDisplay("Target method(s) = {GetTargetMethodsDescriptionForDebugger()}")]
public abstract partial class Delegate : ICloneable, ISerializable
{
// V1 API: Create closed instance delegates. Method name matching is case sensitive.
Expand Down Expand Up @@ -218,7 +217,7 @@ private void InitializeClosedStaticThunk(object firstParameter, IntPtr functionP
}

// This function is known to the compiler backend.
private void InitializeOpenStaticThunk(object firstParameter, IntPtr functionPointer, IntPtr functionPointerThunk)
private void InitializeOpenStaticThunk(object _ /*firstParameter*/, IntPtr functionPointer, IntPtr functionPointerThunk)
{
// This sort of delegate is invoked by calling the thunk function pointer with the arguments to the delegate + a reference to the delegate object itself.
m_firstParameter = this;
Expand Down Expand Up @@ -422,48 +421,5 @@ internal static Delegate CreateDelegate(EETypePtr delegateEEType, IntPtr ldftnRe
}
return del;
}

private string GetTargetMethodsDescriptionForDebugger()
{
if (m_functionPointer == GetThunk(MulticastThunk))
{
// Multi-cast delegates return the Target of the last delegate in the list
Delegate[] invocationList = (Delegate[])m_helperObject;
int invocationCount = (int)m_extraFunctionPointerOrData;
StringBuilder builder = new StringBuilder();
for (int c = 0; c < invocationCount; c++)
{
if (c != 0)
builder.Append(", ");

builder.Append(invocationList[c].GetTargetMethodsDescriptionForDebugger());
}

return builder.ToString();
}
else
{
RuntimeTypeHandle typeOfFirstParameterIfInstanceDelegate;
IntPtr functionPointer = GetFunctionPointer(out typeOfFirstParameterIfInstanceDelegate, out bool _, out bool _);
if (!FunctionPointerOps.IsGenericMethodPointer(functionPointer))
{
return DebuggerFunctionPointerFormattingHook(functionPointer, typeOfFirstParameterIfInstanceDelegate);
}
else
{
unsafe
{
GenericMethodDescriptor* pointerDef = FunctionPointerOps.ConvertToGenericDescriptor(functionPointer);
return DebuggerFunctionPointerFormattingHook(pointerDef->InstantiationArgument, typeOfFirstParameterIfInstanceDelegate);
}
}
}
}

private static string DebuggerFunctionPointerFormattingHook(IntPtr functionPointer, RuntimeTypeHandle typeOfFirstParameterIfInstanceDelegate)
{
// This method will be hooked by the debugger and the debugger will cause it to return a description for the function pointer
throw new NotSupportedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace System
{
public abstract partial class Enum : ValueType, IComparable, IFormattable, IConvertible
{
#pragma warning disable IDE0060
internal static EnumInfo GetEnumInfo(Type enumType, bool getNames = true)
{
Debug.Assert(enumType != null);
Expand All @@ -24,6 +25,7 @@ internal static EnumInfo GetEnumInfo(Type enumType, bool getNames = true)

return ReflectionAugments.ReflectionCoreCallbacks.GetEnumInfo(enumType);
}
#pragma warning restore

private static object InternalBoxEnum(Type enumType, long value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void FailFast(string message) =>
public static void FailFast(string message, Exception exception) =>
RuntimeExceptionHelpers.FailFast(message, exception);

internal static void FailFast(string message, Exception exception, string errorSource)
internal static void FailFast(string message, Exception exception, string _ /*errorSource*/)
{
// TODO: errorSource originates from CoreCLR (See: https://github.com/dotnet/coreclr/pull/15895)
// For now, we ignore errorSource but we should distinguish the way FailFast prints exception message using errorSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace System.IO
{
public partial class FileLoadException
{
internal static string FormatFileLoadExceptionMessage(string? fileName, int hResult)
internal static string FormatFileLoadExceptionMessage(string? fileName, int _ /*hResult*/)
{
return fileName == null ? SR.IO_FileLoad : SR.Format(SR.IO_FileLoad_FileName, fileName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private static Exception CreateChangeTypeException(EETypePtr srcEEType, EETypePt
case CheckArgumentSemantics.SetFieldDirect:
return CreateChangeTypeArgumentException(srcEEType, dstEEType);
case CheckArgumentSemantics.ArraySet:
return CreateChangeTypeInvalidCastException(srcEEType, dstEEType);
return CreateChangeTypeInvalidCastException();
default:
Debug.Fail("Unexpected CheckArgumentSemantics value: " + semantics);
throw new InvalidOperationException();
Expand All @@ -259,7 +259,7 @@ internal static ArgumentException CreateChangeTypeArgumentException(EETypePtr sr
return new ArgumentException(SR.Format(SR.Arg_ObjObjEx, Type.GetTypeFromHandle(new RuntimeTypeHandle(srcEEType)), destinationTypeName));
}

private static InvalidCastException CreateChangeTypeInvalidCastException(EETypePtr srcEEType, EETypePtr dstEEType)
private static InvalidCastException CreateChangeTypeInvalidCastException()
{
return new InvalidCastException(SR.InvalidCast_StoreArrayElement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private sealed class ArrayTypeTable : ConcurrentUnifierWKeyed<UnificationKey, Ru
{
protected sealed override RuntimeArrayTypeInfo Factory(UnificationKey key)
{
ValidateElementType(key.ElementType, key.TypeHandle, multiDim: false, rank: 1);
ValidateElementType(key.ElementType, multiDim: false, rank: 1);

return new RuntimeArrayTypeInfo(key, multiDim: false, rank: 1);
}
Expand All @@ -270,7 +270,7 @@ public MultiDimArrayTypeTable(int rank)

protected sealed override RuntimeArrayTypeInfo Factory(UnificationKey key)
{
ValidateElementType(key.ElementType, key.TypeHandle, multiDim: true, rank: _rank);
ValidateElementType(key.ElementType, multiDim: true, rank: _rank);

return new RuntimeArrayTypeInfo(key, multiDim: true, rank: _rank);
}
Expand All @@ -292,7 +292,7 @@ protected sealed override MultiDimArrayTypeTable Factory(int rank)
public static readonly TypeTableForMultiDimArrayTypeTables Table = new TypeTableForMultiDimArrayTypeTables();
}

private static void ValidateElementType(RuntimeTypeInfo elementType, RuntimeTypeHandle typeHandle, bool multiDim, int rank)
private static void ValidateElementType(RuntimeTypeInfo elementType, bool multiDim, int rank)
{
Debug.Assert(multiDim || rank == 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static void InitializeArray(Array array, RuntimeFieldHandle fldHandle)
throw new PlatformNotSupportedException();
}

#pragma warning disable IDE0060
private static unsafe void* GetSpanDataFrom(
RuntimeFieldHandle fldHandle,
RuntimeTypeHandle targetTypeHandle,
Expand All @@ -36,6 +37,7 @@ public static void InitializeArray(Array array, RuntimeFieldHandle fldHandle)
// https://github.com/dotnet/corert/issues/364
throw new PlatformNotSupportedException();
}
#pragma warning disable IDE0060

[RequiresUnreferencedCode("Trimmer can't guarantee existence of class constructor")]
public static void RunClassConstructor(RuntimeTypeHandle type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ public object GetOrRegisterObjectForComInstance(IntPtr externalComObject, Create
return (ComInterfaceDispatch*)comObject;
}

#pragma warning disable IDE0060
/// <summary>
/// Get the currently registered managed object or creates a new managed object and registers it.
/// </summary>
Expand Down Expand Up @@ -541,6 +542,7 @@ private unsafe bool TryGetOrCreateObjectForComInstanceInternal(

return true;
}
#pragma warning restore IDE0060

private void RemoveRCWFromCache(IntPtr comPointer)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,8 @@ public static unsafe void StructureToPtr(object structure, IntPtr ptr, bool fDel
}
}

private static void PrelinkCore(MethodInfo m)
{
// This method is effectively a no-op for NativeAOT, everything pre-generated.
}
// This method is effectively a no-op for NativeAOT, everything pre-generated.
static partial void PrelinkCore(MethodInfo m);

internal static Delegate GetDelegateForFunctionPointerInternal(IntPtr ptr, Type t)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static partial class NativeLibrary
{
private const int LoadWithAlteredSearchPathFlag = 0;

private static IntPtr LoadLibraryHelper(string libraryName, int flags, ref LoadLibErrorTracker errorTracker)
private static IntPtr LoadLibraryHelper(string libraryName, int _ /*flags*/, ref LoadLibErrorTracker errorTracker)
{
// do the Dos/Unix conversion
libraryName = libraryName.Replace('\\', '/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public static partial class JitInfo

public static long GetCompiledMethodCount(bool currentThread = false) => 0;

private static long GetCompilationTimeInTicks(bool currentThread = false) => 0;
private static long GetCompilationTimeInTicks(bool _ /*currentThread*/ = false) => 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public Assembly LoadFromAssemblyName(AssemblyName assemblyName)
return Assembly.Load(assemblyName);
}

#pragma warning disable IDE0060
private static IntPtr InitializeAssemblyLoadContext(IntPtr ptrAssemblyLoadContext, bool fRepresentsTPALoadContext, bool isCollectible)
{
return IntPtr.Zero;
Expand Down Expand Up @@ -46,6 +47,7 @@ private static Assembly InternalLoadFromPath(string? assemblyPath, string? nativ
// so it won't actually work properly when multiple assemblies with the same identity get loaded.
return ReflectionAugments.ReflectionCoreCallbacks.Load(assemblyPath);
}
#pragma warning restore IDE0060

#pragma warning disable CA1822
internal Assembly InternalLoad(ReadOnlySpan<byte> arrAssembly, ReadOnlySpan<byte> arrSymbols)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private void PlatformSpecificInitializeExistingThread()
_stopped = new ManualResetEvent(false);
}

#pragma warning disable CA1822
#pragma warning disable CA1822, IDE0060
private ThreadPriority GetPriorityLive()
{
return ThreadPriority.Normal;
Expand All @@ -38,7 +38,7 @@ private bool SetPriorityLive(ThreadPriority priority)
{
return true;
}
#pragma warning restore CA1822
#pragma warning restore CA1822, IDE0060

[UnmanagedCallersOnly]
private static void OnThreadExit()
Expand Down
Loading

0 comments on commit 8918adf

Please sign in to comment.