Skip to content

Commit f31a692

Browse files
authored
Fix trim warnings (#2398)
* Fix trim warnings * Update snaps
1 parent 23bd2ad commit f31a692

38 files changed

+82
-67
lines changed

TUnit.Analyzers.Tests/MethodDataSourceAnalyzerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ await Verifier.VerifyAnalyzerAsync("""
635635
using TUnit.Core;
636636
using System.Diagnostics.CodeAnalysis;
637637
638-
[SuppressMessage("Usage", "TUnit0046:Return a `Func<T>` rather than a `<T>`")]
638+
[UnconditionalSuppressMessage("Usage", "TUnit0046:Return a `Func<T>` rather than a `<T>`")]
639639
public class MethodDataSourceDrivenWithCancellationTokenTests
640640
{
641641
[Test]

TUnit.Assertions.Tests/AssertMultipleTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace TUnit.Assertions.Tests;
55

6-
[SuppressMessage("Usage", "TUnitAssertions0005:Assert.That(...) should not be used with a constant value")]
6+
[UnconditionalSuppressMessage("Usage", "TUnitAssertions0005:Assert.That(...) should not be used with a constant value")]
77
public class AssertMultipleTests
88
{
99
[Test]

TUnit.Assertions.Tests/Old/AssertMultipleTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace TUnit.Assertions.Tests.Old;
44

5-
[SuppressMessage("Usage", "TUnitAssertions0005:Assert.That(...) should not be used with a constant value")]
5+
[UnconditionalSuppressMessage("Usage", "TUnitAssertions0005:Assert.That(...) should not be used with a constant value")]
66
public class AssertMultipleTests
77
{
88
[Test]

TUnit.Assertions/AssertionBuilders/Groups/AssertionGroup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
namespace TUnit.Assertions.AssertionBuilders.Groups;
55

6-
[SuppressMessage("Usage", "TUnitAssertions0002:Assert statements must be awaited")]
7-
[SuppressMessage("Usage", "TUnitAssertions0008:ValueTasks should be awaited when used within Assert.That(...)")]
6+
[UnconditionalSuppressMessage("Usage", "TUnitAssertions0002:Assert statements must be awaited")]
7+
[UnconditionalSuppressMessage("Usage", "TUnitAssertions0008:ValueTasks should be awaited when used within Assert.That(...)")]
88
public static class AssertionGroup
99
{
1010
public static OrAssertionGroupInvoker<TActual, TAssertionBuilder> Or<TActual, TAssertionBuilder>(AssertionGroup<TActual, TAssertionBuilder> group1, AssertionGroup<TActual, TAssertionBuilder> group2)

TUnit.Assertions/Assertions/Collections/CollectionsIsExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace TUnit.Assertions.Extensions;
1313

14-
[SuppressMessage("Usage", "TUnitAssertions0003:Compiler argument populated")]
14+
[UnconditionalSuppressMessage("Usage", "TUnitAssertions0003:Compiler argument populated")]
1515
public static class CollectionsIsExtensions
1616
{
1717
public static InvokableValueAssertionBuilder<TActual> IsEquivalentTo<TActual,

TUnit.Assertions/Assertions/Collections/ImmutableArrayIsExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace TUnit.Assertions.Extensions;
1313

14-
[SuppressMessage("Usage", "TUnitAssertions0003:Compiler argument populated")]
14+
[UnconditionalSuppressMessage("Usage", "TUnitAssertions0003:Compiler argument populated")]
1515
public static class ImmutableArrayIsExtensions
1616
{
1717
public static InvokableValueAssertionBuilder<ImmutableArray<TInner>> IsEquivalentTo<

TUnit.Core.SourceGenerator.Tests/MethodDataSourceDrivenWithCancellationTokenTests.Test.verified.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ file partial class MethodDataSourceDrivenWithCancellationTokenTests : global::TU
7878
Namespace = "TUnit.TestProject",
7979
Attributes =
8080
[
81-
new global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Usage", "TUnit0046:Return a `Func<T>` rather than a `<T>`")
81+
new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Usage", "TUnit0046:Return a `Func<T>` rather than a `<T>`")
8282
],
8383
Parameters = [],
8484
Properties = [],
@@ -181,7 +181,7 @@ file partial class MethodDataSourceDrivenWithCancellationTokenTests : global::TU
181181
Namespace = "TUnit.TestProject",
182182
Attributes =
183183
[
184-
new global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Usage", "TUnit0046:Return a `Func<T>` rather than a `<T>`")
184+
new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Usage", "TUnit0046:Return a `Func<T>` rather than a `<T>`")
185185
],
186186
Parameters = [],
187187
Properties = [],
@@ -284,7 +284,7 @@ file partial class MethodDataSourceDrivenWithCancellationTokenTests : global::TU
284284
Namespace = "TUnit.TestProject",
285285
Attributes =
286286
[
287-
new global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Usage", "TUnit0046:Return a `Func<T>` rather than a `<T>`")
287+
new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Usage", "TUnit0046:Return a `Func<T>` rather than a `<T>`")
288288
],
289289
Parameters = [],
290290
Properties = [],
@@ -391,7 +391,7 @@ file partial class MethodDataSourceDrivenWithCancellationTokenTests : global::TU
391391
Namespace = "TUnit.TestProject",
392392
Attributes =
393393
[
394-
new global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Usage", "TUnit0046:Return a `Func<T>` rather than a `<T>`")
394+
new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Usage", "TUnit0046:Return a `Func<T>` rather than a `<T>`")
395395
],
396396
Parameters = [],
397397
Properties = [],
@@ -498,7 +498,7 @@ file partial class MethodDataSourceDrivenWithCancellationTokenTests : global::TU
498498
Namespace = "TUnit.TestProject",
499499
Attributes =
500500
[
501-
new global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Usage", "TUnit0046:Return a `Func<T>` rather than a `<T>`")
501+
new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Usage", "TUnit0046:Return a `Func<T>` rather than a `<T>`")
502502
],
503503
Parameters = [],
504504
Properties = [],
@@ -605,7 +605,7 @@ file partial class MethodDataSourceDrivenWithCancellationTokenTests : global::TU
605605
Namespace = "TUnit.TestProject",
606606
Attributes =
607607
[
608-
new global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Usage", "TUnit0046:Return a `Func<T>` rather than a `<T>`")
608+
new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Usage", "TUnit0046:Return a `Func<T>` rather than a `<T>`")
609609
],
610610
Parameters = [],
611611
Properties = [],

TUnit.Core.SourceGenerator.Tests/ReferencesHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace TUnit.Core.SourceGenerator.Tests;
66

7-
[SuppressMessage("SingleFile", "IL3000:Avoid accessing Assembly file path when publishing as a single file")]
7+
[UnconditionalSuppressMessage("SingleFile", "IL3000:Avoid accessing Assembly file path when publishing as a single file")]
88
internal class ReferencesHelper
99
{
1010
public static readonly List<PortableExecutableReference> References =

TUnit.Core.SourceGenerator.Tests/STAThreadHooksTests.Test.verified.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ file partial class Hooks_STAThreadTests : global::TUnit.Core.Interfaces.SourceGe
6464
Namespace = "TUnit.TestProject",
6565
Attributes =
6666
[
67-
new global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility")
67+
new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility")
6868
],
6969
Parameters = [],
7070
Properties = [],
@@ -156,7 +156,7 @@ file partial class Hooks_STAThreadTests : global::TUnit.Core.Interfaces.SourceGe
156156
Namespace = "TUnit.TestProject",
157157
Attributes =
158158
[
159-
new global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility")
159+
new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility")
160160
],
161161
Parameters = [],
162162
Properties = [],

TUnit.Core/AsyncConvert.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,17 @@ public static ValueTask ConvertObject(object? invoke)
100100
if (type.IsGenericType
101101
&& type.GetGenericTypeDefinition().FullName == "Microsoft.FSharp.Control.FSharpAsync`1")
102102
{
103-
#pragma warning disable
104103
return StartAsFSharpTask(invoke, type);
105-
#pragma warning restore
106104
}
107105

108106
throw new ArgumentException("Invalid object type: " + type.Name, nameof(invoke));
109107
}
110108

111-
[RequiresDynamicCode("Dynamic code is required to call F# async methods.")]
112-
[RequiresUnreferencedCode("Dynamic code is required to call F# async methods.")]
109+
[UnconditionalSuppressMessage("Trimming", "IL2077:Target parameter argument does not satisfy \'DynamicallyAccessedMembersAttribute\' in call to target method. The source field does not have matching annotations.")]
110+
[UnconditionalSuppressMessage("Trimming", "IL2072:Target parameter argument does not satisfy \'DynamicallyAccessedMembersAttribute\' in call to target method. The return value of the source method does not have matching annotations.")]
111+
[UnconditionalSuppressMessage("AOT", "IL3050:Calling members annotated with \'RequiresDynamicCodeAttribute\' may break functionality when AOT compiling.")]
112+
[UnconditionalSuppressMessage("Trimming", "IL2060:Call to \'System.Reflection.MethodInfo.MakeGenericMethod\' can not be statically analyzed. It\'s not possible to guarantee the availability of requirements of the generic method.")]
113+
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
113114
private static ValueTask StartAsFSharpTask(object invoke, Type type)
114115
{
115116
var startAsTaskOpenGenericMethod = (_fSharpAsyncType ??= type.Assembly.GetType("Microsoft.FSharp.Control.FSharpAsync"))!

0 commit comments

Comments
 (0)