Skip to content

Conversation

@manhatsu
Copy link
Contributor

Added new guideline on unions by @rcseacord.

This is the same content as #270 but moved to the feature branch.

@netlify
Copy link

netlify bot commented Dec 16, 2025

Deploy Preview for scrc-coding-guidelines ready!

Name Link
🔨 Latest commit 99551c2
🔍 Latest deploy log https://app.netlify.com/projects/scrc-coding-guidelines/deploys/694b19254346670008b3828a
😎 Deploy Preview https://deploy-preview-300--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.

@rcseacord
Copy link
Collaborator

@PLeVasseur @felix91gr I did a final cleanup and this rule LGTM. Please review & approve

@rcseacord rcseacord self-assigned this Dec 16, 2025
Copy link
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.

I left a couple of comments. Otherwise it was all clear. One is a question about a line I wasn't sure about and the other just a typo fix suggestion.

@felix91gr
Copy link
Collaborator

@PLeVasseur @felix91gr I did a final cleanup and this rule LGTM. Please review & approve

Alright, it goes into the queue.

@PLeVasseur
Copy link
Collaborator

PLeVasseur commented Dec 17, 2025

@PLeVasseur @felix91gr I did a final cleanup and this rule LGTM. Please review & approve

Alright, it goes into the queue.

Hey @felix91gr -- did you take a look at this one yet? I'd like it to be reviewed before we queue it up

(I'll try to make time to review some of @rcseacord's latest ones tomorrow, this included, if it's not been reviewed by you yet)

@felix91gr
Copy link
Collaborator

I'd like it to be reviewed before we queue it up

@PLeVasseur ah, sorry! I forgot we have a Merge Queue as well. I meant it as my own task queue, my bad. I haven't reviewed it yet

Copy link
Collaborator

@PLeVasseur PLeVasseur left a comment

Choose a reason for hiding this comment

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

Hey thanks for pulling this together @manhatsu and @rcseacord

Given that adding the bibliography bit touches quite a few other things, I'd suggest backing that out of this PR if you'd like the guideline to be reviewed on its merits and merged sooner than later.

I've opened issue #306 to track the work towards the work for a bibliography.

@manhatsu manhatsu force-pushed the doc/union-field-validation branch from 0431525 to 696e633 Compare December 19, 2025 02:27
@manhatsu
Copy link
Contributor Author

There is a duplication of URL in these two documents:
expressions/gui_Bib7x9KmPq2nL.rst.inc and types-and-traits/gui_0cuTYG8RVYjg.rst.inc.
bibliography.md says I should consider this, but how can I actually solve this?
I think it's fine if both have the source entry...

@manhatsu manhatsu requested a review from PLeVasseur December 19, 2025 02:41
@PLeVasseur
Copy link
Collaborator

There is a duplication of URL in these two documents: expressions/gui_Bib7x9KmPq2nL.rst.inc and types-and-traits/gui_0cuTYG8RVYjg.rst.inc. bibliography.md says I should consider this, but how can I actually solve this? I think it's fine if both have the source entry...

Yeah, you're right. I didn't have this implemented correctly. Duplicate URLs should be fine, what I wanted to have was for the same URL to force consistent referencing to be used.

I've pushed #335 which should fix this.

Please take a look at the following and rebase:
https://github.com/rustfoundation/safety-critical-rust-coding-guidelines/blob/main/docs/bibliography.md

@PLeVasseur PLeVasseur force-pushed the doc/union-field-validation branch from 696e633 to 99551c2 Compare December 23, 2025 22:35
@PLeVasseur
Copy link
Collaborator

I rebased this on main. It's building and working now.

Copy link
Collaborator

@PLeVasseur PLeVasseur left a comment

Choose a reason for hiding this comment

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

This is somewhat a procedural review to get this in-line with current best practices as outlined in CONTRIBUTING.md.

I haven't reviewed the contents of the guideline yet.

Please update and I can then take a look through content.

If the active field is uncertain, use explicit validity checks.

.. rationale::
:id: rat_UnionFieldValidityReason
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use IDs generated from ./generate_guideline_templates.py.

Reading an invalid value is undefined behavior.
.. non_compliant_example::
:id: non_compl_ex_UnionBool
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use IDs generated from ./generate_guideline_templates.py.

}
.. non_compliant_example::
:id: non_compl_ex_UnionChar
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use IDs generated from ./generate_guideline_templates.py.

}

.. non_compliant_example::
:id: non_compl_ex_UnionEnum
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use IDs generated from ./generate_guideline_templates.py.

}

.. non_compliant_example::
:id: non_compl_ex_UnionRef
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use IDs generated from ./generate_guideline_templates.py.

This noncompliant example reads a reference from a union containing a null pointer.
A similar problem occurs when reading a misaligned pointer.

.. code-block:: rust
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use the .. rust-example:: directive to ensure that these are extracted and tested correctly.
I think we have this a bit loose right now. Perhaps we should fail if there's an example without a .. rust-example:: directive to ensure that this is enforced.

This compliant example tracks the active field explicitly to ensure valid reads.
.. code-block:: rust
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use the .. rust-example:: directive to ensure that these are extracted and tested correctly.
I think we have this a bit loose right now. Perhaps we should fail if there's an example without a .. rust-example:: directive to ensure that this is enforced.

This compliant solution reads from the same field that was written.
.. code-block:: rust
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use the .. rust-example:: directive to ensure that these are extracted and tested correctly.
I think we have this a bit loose right now. Perhaps we should fail if there's an example without a .. rust-example:: directive to ensure that this is enforced.

This compliant example reinterprets the value as a different types where all bit patterns are valid.
.. code-block:: rust
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use the .. rust-example:: directive to ensure that these are extracted and tested correctly.
I think we have this a bit loose right now. Perhaps we should fail if there's an example without a .. rust-example:: directive to ensure that this is enforced.

This compliant example validates bytes before reading as a constrained type.
.. code-block:: rust
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use the .. rust-example:: directive to ensure that these are extracted and tested correctly.
I think we have this a bit loose right now. Perhaps we should fail if there's an example without a .. rust-example:: directive to ensure that this is enforced.

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.

5 participants