Skip to content

Add safety comments proposal#10201

Open
richlander wants to merge 1 commit into
dotnet:mainfrom
richlander:safetydocs
Open

Add safety comments proposal#10201
richlander wants to merge 1 commit into
dotnet:mainfrom
richlander:safetydocs

Conversation

@richlander

Copy link
Copy Markdown
Member

Replaces #10197

@333fred

@richlander
richlander requested a review from a team as a code owner May 26, 2026 23:59
byte* addr = (byte*)ptr;
unsafe
{
// SAFETY: relies on caller obligation.

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.

I'd personally prefer this at the top of the unsafe block, since the corresponding doc comment is directly above the unsafe member

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.

at the top of the unsafe block

It is the Rust convention as well if we want to follow that.

## Requirements

We need the following:

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.

Compiler should also be sure to emit docs with the tag

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.

Compiler already supports this (it forwards any element to the final XML, even those it doesn't know about).

But if you want IDE tooltip support, that would need to be implemented.


We need the following:

- Document + standardize the form, in both regular docs and best-practice guidance.

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.

For reference, https://tbt.qkation.com/posts/safety-comments-matter/ is very detailed best-practice guidance for Rust

@@ -0,0 +1,72 @@
# C/# safety comments

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.

Suggested change
# C/# safety comments
# C# safety comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants