Skip to content

Commit e0403bd

Browse files
committed
Add examples for unsafe reviews
1 parent 6a63736 commit e0403bd

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/unsafe-reviews.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,30 @@ keyword are kept small then reviews won't trigger too often. However, it may als
88
when unsafe code relies on properties outside files with the unsafe keyword (like robust
99
implementations).
1010

11+
## Sound triggering
12+
1113
If the robust keyword existed, unsafe reviews could trigger on files containing any of those 2
1214
keywords. By making sure during unsafe review that proofs only rely on documented robust properties
1315
(parameter of unsafe function or result of robust function), this would make sure that unsafe review
1416
will trigger each time it is needed.
1517

18+
Here are some examples of proofs that depended on undocumented or incorrect robustness:
19+
- <https://github.com/rust-lang/regex/pull/1154>
20+
- <https://github.com/rust-lang/rust/issues/80335>
21+
- <https://rustsec.org/advisories/RUSTSEC-2024-0019.html>
22+
23+
## Burden of proof
24+
1625
To avoid increasing the burden of unsafe reviews, it is important that items are not documented as
1726
robust unless it is known that a proof relies on them. To ensure this, robust items should also
1827
document in their robustness section which crates rely on their robustness. This could alternatively
1928
be tracked in a separate global tool like [`cargo-vet`][cargo-vet].
2029

21-
## Lints
30+
For example, one should not implement [`TrustedLen`][TrustedLen] unless it is relied upon somewhere.
31+
This is deliberately a borderline example to show that it is actually a trade-off between increasing
32+
the burden of proof and implementing possibly useful functionalities.
33+
34+
## Recommended lints
2235

2336
It is almost obligatory to enable [unsafe-op-in-unsafe-fn] which is allowed-by-default up to edition
2437
2021 and warn-by-default starting from edition 2024. Not using this lint will:
@@ -42,6 +55,7 @@ multiple-unsafe-ops-per-block. Both together ensure that there is a one-to-one c
4255
between the usage of unsafe superpower and the safety comment proving its soundness, thus
4356
simplifying unsafe reviews.
4457

58+
[TrustedLen]: https://doc.rust-lang.org/std/iter/trait.TrustedLen.html
4559
[cargo-vet]: https://github.com/mozilla/cargo-vet
4660
[multiple-unsafe-ops-per-block]: https://rust-lang.github.io/rust-clippy/master/index.html#/multiple_unsafe_ops_per_block
4761
[undocumented-unsafe-blocks]: https://rust-lang.github.io/rust-clippy/master/index.html#/undocumented_unsafe_blocks

0 commit comments

Comments
 (0)