Skip to content

#246 [Coding Guideline]: Do not access memory using a pointer with an incorrect provenance#264

Open
manhatsu wants to merge 8 commits intorustfoundation:mainfrom
manhatsu:feat/pointer-comparison-rule
Open

#246 [Coding Guideline]: Do not access memory using a pointer with an incorrect provenance#264
manhatsu wants to merge 8 commits intorustfoundation:mainfrom
manhatsu:feat/pointer-comparison-rule

Conversation

@manhatsu
Copy link
Copy Markdown
Contributor

@manhatsu manhatsu commented Dec 8, 2025

Closes #246.

@netlify
Copy link
Copy Markdown

netlify bot commented Dec 8, 2025

Deploy Preview for scrc-coding-guidelines failed.

Name Link
🔨 Latest commit 7d8864f
🔍 Latest deploy log https://app.netlify.com/projects/scrc-coding-guidelines/deploys/69ba95f2b33af500081bc116

@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
Copy Markdown
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
Copy Markdown
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.
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown

@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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

resolved

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

resolved (again)

Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

no problem, i was just looking for your opinion.

@felix91gr felix91gr added the coding guideline An issue related to a suggestion for a coding guideline label Feb 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

👋 Hey @iglesias! You've been assigned to review this coding guideline PR.

Your Role as Reviewer

As outlined in our contribution guide, please:

  1. Begin your review within 14 days
  2. Provide constructive feedback on the guideline content, examples, and formatting
  3. Iterate with @manhatsu - they may update the PR based on your feedback
  4. When the guideline is ready, approve and add to the merge queue

Review Checklist

  • Guideline title is clear and follows conventions
  • Amplification section expands on the title appropriately
  • Rationale explains the "why" effectively
  • Non-compliant example(s) clearly show the problem
  • Compliant example(s) clearly show the solution
  • Code examples compile (check the CI results)
  • FLS paragraph ID is correct

Bot Commands

If you need to pass this review:

  • @guidelines-bot /pass [reason] - Pass just this PR to the next reviewer
  • @guidelines-bot /away YYYY-MM-DD [reason] - Step away from the queue until a date
  • @guidelines-bot /release [@username] [reason] - Release assignment (yours or someone else's with triage+ permission)

To assign someone else:

  • @guidelines-bot /r? @username - Assign a specific reviewer
  • @guidelines-bot /r? producers - Request the next reviewer from the queue

Other commands:

  • @guidelines-bot /claim - Claim this review for yourself
  • @guidelines-bot /label +label-name - Add a label
  • @guidelines-bot /label -label-name - Remove a label
  • @guidelines-bot /queue - Show reviewer queue
  • @guidelines-bot /commands - Show all available commands

@felix91gr
Copy link
Copy Markdown
Collaborator

@iglesias one sec, we messed up and the thing has assigned you as reviewer to 4 PRs (it should only be able to assign you to 1)

@felix91gr
Copy link
Copy Markdown
Collaborator

felix91gr commented Feb 10, 2026

@iglesias okay, this one is the right one (according to the bot's queue). Sorry about the multiple pings! :)

@plaindocs
Copy link
Copy Markdown
Collaborator

Hey @iglesias would you like to claim this review, or let someone else grab it

@github-actions
Copy link
Copy Markdown
Contributor

⚠️ Review Reminder

Hey @iglesias, it's been more than 14 days since you were assigned to review this.

Please take one of the following actions:

  1. Begin your review - Post a comment with your feedback
  2. Pass the review - Use @guidelines-bot /pass [reason] to assign the next reviewer
  3. Step away temporarily - Use @guidelines-bot /away YYYY-MM-DD [reason] if you need time off

If no action is taken within 14 days, you may be transitioned from Producer to Observer status per our contribution guidelines.

Life happens! If you're dealing with something, just let us know.

@iglesias
Copy link
Copy Markdown
Contributor

@guidelines-bot /claim

@github-actions
Copy link
Copy Markdown
Contributor

@iglesias has claimed this review.

@iglesias is designated as reviewer by queue rotation, but GitHub could not add them to PR Reviewers automatically (API 422). A triage+ approver may still be required before merge queue.

@iglesias
Copy link
Copy Markdown
Contributor

Hey @felix91gr @plaindocs sorry the delay :-)

Co-authored-by: Fernando José <fernando.iglesiasg@gmail.com>
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ Review Reminder

Hey @iglesias, it's been more than 14 days since you were assigned to review this.

Please take one of the following actions:

  1. Begin your review - Post a comment with your feedback
  2. Pass the review - Use @guidelines-bot /pass [reason] to assign the next reviewer
  3. Step away temporarily - Use @guidelines-bot /away YYYY-MM-DD [reason] if you need time off

If no action is taken within 14 days, you may be transitioned from Producer to Observer status per our contribution guidelines.

Life happens! If you're dealing with something, just let us know.

@iglesias
Copy link
Copy Markdown
Contributor

@guidelines-bot

@iglesias
Copy link
Copy Markdown
Contributor

@guidelines-bot /commands

@iglesias
Copy link
Copy Markdown
Contributor

Hey @felix91gr @plaindocs
I approved the review 3 weeks ago, but still just got the review reminder 6 hours ago. Is there anything missing to approve it?
Thank you for any help :-)

Copy link
Copy Markdown
Contributor

@iglesias iglesias left a comment

Choose a reason for hiding this comment

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

LGTM

@felix91gr
Copy link
Copy Markdown
Collaborator

GAH we have to solve those conflicts, that's the issue. Damn, I forgot. I tried to do it on the web ui a couple times, but github wouldn't have it (something something large diff). And later I forgot to do it locally (I'm not even sure I know how to do that in a way github would accept).

@iglesias your review is perfect as far as I can tell. Lemme see if we can get this solved with @plaindocs before the bot pings you again 🙇🏻

@plaindocs
Copy link
Copy Markdown
Collaborator

@felix91gr know anything about the two errors shown?

@felix91gr
Copy link
Copy Markdown
Collaborator

@plaindocs I'm checking... one sec

@felix91gr
Copy link
Copy Markdown
Collaborator

Ah. Okay, I see what's up. Hmm. I'll be back in a bit. The code examples need some help. This didn't trigger before because there were some merge conflicts that stopped CI jobs from running.

@github-actions github-actions bot added the status: awaiting reviewer response Reviewer-bot is waiting on reviewer freshness or current-head review label Mar 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

⚠️ Review Reminder

Hey @iglesias, it's been more than 14 days since you were assigned to review this.

Please take one of the following actions:

  1. Begin your review - Post a comment with your feedback
  2. Pass the review - Use @guidelines-bot /pass [reason] to assign the next reviewer
  3. Step away temporarily - Use @guidelines-bot /away YYYY-MM-DD [reason] if you need time off

If no action is taken within 14 days, you may be transitioned from Producer to Observer status per our contribution guidelines.

Life happens! If you're dealing with something, just let us know.

3 similar comments
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

⚠️ Review Reminder

Hey @iglesias, it's been more than 14 days since you were assigned to review this.

Please take one of the following actions:

  1. Begin your review - Post a comment with your feedback
  2. Pass the review - Use @guidelines-bot /pass [reason] to assign the next reviewer
  3. Step away temporarily - Use @guidelines-bot /away YYYY-MM-DD [reason] if you need time off

If no action is taken within 14 days, you may be transitioned from Producer to Observer status per our contribution guidelines.

Life happens! If you're dealing with something, just let us know.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

⚠️ Review Reminder

Hey @iglesias, it's been more than 14 days since you were assigned to review this.

Please take one of the following actions:

  1. Begin your review - Post a comment with your feedback
  2. Pass the review - Use @guidelines-bot /pass [reason] to assign the next reviewer
  3. Step away temporarily - Use @guidelines-bot /away YYYY-MM-DD [reason] if you need time off

If no action is taken within 14 days, you may be transitioned from Producer to Observer status per our contribution guidelines.

Life happens! If you're dealing with something, just let us know.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

⚠️ Review Reminder

Hey @iglesias, it's been more than 14 days since you were assigned to review this.

Please take one of the following actions:

  1. Begin your review - Post a comment with your feedback
  2. Pass the review - Use @guidelines-bot /pass [reason] to assign the next reviewer
  3. Step away temporarily - Use @guidelines-bot /away YYYY-MM-DD [reason] if you need time off

If no action is taken within 14 days, you may be transitioned from Producer to Observer status per our contribution guidelines.

Life happens! If you're dealing with something, just let us know.

@plaindocs
Copy link
Copy Markdown
Collaborator

@PLeVasseur could you check the naggy review bot please

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

⚠️ Review Reminder

Hey @iglesias, it's been more than 14 days since you were assigned to review this.

Please take one of the following actions:

  1. Begin your review - Post a comment with your feedback
  2. Pass the review - Use @guidelines-bot /pass [reason] to assign the next reviewer
  3. Step away temporarily - Use @guidelines-bot /away YYYY-MM-DD [reason] if you need time off

If no action is taken within 14 days, you may be transitioned from Producer to Observer status per our contribution guidelines.

Life happens! If you're dealing with something, just let us know.

@PLeVasseur
Copy link
Copy Markdown
Collaborator

Sorry for the nagging; working on it

@iglesias
Copy link
Copy Markdown
Contributor

iglesias commented Apr 1, 2026

Thank you 🙇

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

Labels

chapter: unsafety coding guideline An issue related to a suggestion for a coding guideline status: awaiting reviewer response Reviewer-bot is waiting on reviewer freshness or current-head review

Development

Successfully merging this pull request may close these issues.

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

7 participants