Skip to content

Unsafe evolution: update RequiresUnsafeAttribute namespace#82813

Merged
jjonescz merged 2 commits into
dotnet:mainfrom
jjonescz:Unsafe-25-UnsafeAttributeNamespace
Mar 20, 2026
Merged

Unsafe evolution: update RequiresUnsafeAttribute namespace#82813
jjonescz merged 2 commits into
dotnet:mainfrom
jjonescz:Unsafe-25-UnsafeAttributeNamespace

Conversation

@jjonescz

@jjonescz jjonescz commented Mar 18, 2026

Copy link
Copy Markdown
Member

Test plan: #81207
API review: dotnet/runtime#125134 (comment)

Microsoft Reviewers: Open in CodeFlow

@jjonescz jjonescz marked this pull request as ready for review March 18, 2026 11:45
@jjonescz jjonescz requested a review from a team as a code owner March 18, 2026 11:45
@jjonescz jjonescz requested review from 333fred and jcouv March 18, 2026 11:45
@jcouv jcouv self-assigned this Mar 18, 2026
@jcouv jcouv mentioned this pull request Mar 18, 2026
4 tasks
namespace System.Runtime.CompilerServices
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Event | AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = false)]

@jcouv jcouv Mar 18, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing AttributeTargets.Field to match BCL definition #WontFix

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's by design. It was pre-approved by BCL API review if we want to support RequiresUnsafe fields in the future. But it should not be defined until then since we don't produce any errors if RequiresUnsafe is applied on unsupported symbol kinds apart from the AttributeTargets errors.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, got it. Thanks

@jcouv

jcouv commented Mar 18, 2026

Copy link
Copy Markdown
Member
            public sealed class MemorySafetyRulesAttribute : Attribute

Let's add [AttributeUsage(AttributeTargets.Module, Inherited = false, AllowMultiple = false)] to match BCL definition #Resolved


Refers to: src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs:706 in 63a02b8. [](commit_id = 63a02b8, deletion_comment = False)

@jcouv jcouv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with review pass (commit 1)

@jcouv jcouv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks (commit 2)

@jjonescz jjonescz merged commit c2a993b into dotnet:main Mar 20, 2026
24 checks passed
@jjonescz jjonescz deleted the Unsafe-25-UnsafeAttributeNamespace branch March 20, 2026 09:20
@dotnet-policy-service dotnet-policy-service Bot added this to the Next milestone Mar 20, 2026
@jjonescz jjonescz modified the milestones: Next, 18.6 Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants