Skip to content

Commit 93e48b9

Browse files
committed
tag styles: visually group tags; naming convention
1 parent e3d43ae commit 93e48b9

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

text/0000-safety-tags.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ unsafe fn delegation<T>(ptr: *const T) -> T {
245245
}
246246
```
247247

248+
The tags `ValidPtr` and `Initialized = "delegated to the caller"` are grouped together. We do not
249+
introduce new syntax for grouping tags but instead suggest visually grouping them for clarity. When
250+
`rustfmt` automatically formats `ValidPtr` to its own line, the only workaround is to set
251+
`attr_fn_like_width = 0` in the `rustfmt.toml` configuration file. For further discussion on this
252+
tag styling, see this [link](https://github.com/rust-lang/rfcs/pull/3842#discussion_r2296076785).
253+
248254
In this delegation case, you're able to declare a new meaningful tag for ValidPtr and Initialized
249255
invariants, and define the new tag on `delegation` function. This practice extends to partial unsafe
250256
delegation of multiple tag discharges:
@@ -602,6 +608,23 @@ following cases:
602608
But we believe safety requirements are almost mostly imposed by unsafe functions, so tagging a
603609
struct, enum, or union is neither needed nor permitted.
604610

611+
## Tag naming convention
612+
613+
There are two primary conventions for naming tags: `PascalCase` (also known as `UpperCamelCase`) and
614+
`snake_case`.
615+
616+
We might consider recommending just one convention for consistency, but it's challenging to
617+
determine whether a tag functions more like a type-level construct (semantically akin to an
618+
uninhabited enum) or a value-level construct (such as a function, especially if tags can take
619+
arguments).
620+
621+
To accommodate both styles, we could provide an option that allows users to unify their code style
622+
or lint against the alternative convention:
623+
624+
```rust
625+
#![safety::tag_naming_convention = "PascalCase"] // in root module
626+
```
627+
605628
# Future possibilities
606629
[future-possibilities]: #future-possibilities
607630

0 commit comments

Comments
 (0)