Skip to content

Conversation

@manhatsu
Copy link
Contributor

@manhatsu manhatsu commented Dec 8, 2025

Closes #246.

@netlify
Copy link

netlify bot commented Dec 8, 2025

Deploy Preview for scrc-coding-guidelines ready!

Name Link
🔨 Latest commit a016d71
🔍 Latest deploy log https://app.netlify.com/projects/scrc-coding-guidelines/deploys/693b1c3bb1aaac0007f8f595
😎 Deploy Preview https://deploy-preview-264--scrc-coding-guidelines.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@manhatsu manhatsu changed the title doc: prohibit comparing raw pointers with different allocation origins #246 [Coding Guideline]: Prohibit comparing raw pointers with different allocation origins Dec 8, 2025
@rcseacord
Copy link
Collaborator

rcseacord commented Dec 8, 2025

@manhatsu This is going to continue to be a rule about provenance so it should definitely have provenance in the title, otherwise I won't be able to find it.

For now I suggest the title be "Do not access memory using a pointer with incorrect provenance"

Updated guidelines on pointer comparisons and memory access to clarify the importance of provenance and the implications of comparing pointers from different allocations.
@manhatsu manhatsu changed the title #246 [Coding Guideline]: Prohibit comparing raw pointers with different allocation origins #246 [Coding Guideline]: Do not access memory using a pointer with an incorrect provenance Dec 8, 2025
@manhatsu
Copy link
Contributor Author

manhatsu commented Dec 8, 2025

@rcseacord It was my lack of understanding. I changed the title as you suggested.

added new noncompliant / compliant solution
Do not access memory using a pointer with an incorrect provenance.
Pointers, including values of reference type, have two components.
The pointer’s address identifies the memory location where the pointer is currently pointing.
The pointer’s provenance determines where and when the pointer is allowed to access memory.

Choose a reason for hiding this comment

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

The provenance also determines if the pointer is allowed to mutate the memory. See also the std docs for this: https://doc.rust-lang.org/std/ptr/index.html#provenance

This should maybe also be taken into account below when discussing when a memory access is UB.

Copy link
Collaborator

Choose a reason for hiding this comment

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

resolved.

- Outcomes of pointer arithmetic across allocation boundaries

This rule ignores any metadata that may come with wide pointers;
it only pertains to thin pointers and the data part of a wide pointer.
Copy link

@inkreasing inkreasing Dec 9, 2025

Choose a reason for hiding this comment

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

Suggested change
it only pertains to thin pointers and the data part of a wide pointer.
it only pertains to thin pointers and the address part of a wide pointer.

The additional data of a wide pointer is often called metadata (See the unstable function for reading it: https://doc.rust-lang.org/std/ptr/fn.metadata.html or the previous sentence). So calling the address "data" is confusing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

resolved

Choose a reason for hiding this comment

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

Do you want to link to unstable docs? If yes it may be better to link to https://doc.rust-lang.org/std/ptr/trait.Pointee.html#pointer-metadata as here the current kinds of metadata are explained?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@inkreasing OK, i added this link. do you see any other problems with this or does it look ready to merge?

Copy link
Collaborator

Choose a reason for hiding this comment

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

resolved (again)

Choose a reason for hiding this comment

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

@rcseacord Oh sorry i am not in any position to decide wether this is ready to be merged. This was basically a drive-by review. Will make that clear from the beginning next time.

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.

[Coding Guideline]: Do not compare raw pointers to allocations with different provenance

3 participants