Skip to content

Commit 2004fd4

Browse files
committed
safety-tags: add tag discharge of unsafe encapsulation
1 parent c0495e3 commit 2004fd4

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

text/0000-safety-tags.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ LLL | unsafe { ptr::read(ptr) }
140140

141141
The process of verifying whether a tag is absent is referred to as tag discharge.
142142

143+
Note that it's allowed to discharge tags of unsafe callees onto the unsafe caller for unsafe
144+
encapsulation:
145+
146+
```rust
147+
#[clippy::safety { ValidPtr, Aligned, Initialized }] //
148+
unsafe fn constructor<T>() -> T {
149+
unsafe { read(...) }
150+
}
151+
```
152+
143153
## Safety Tags as Ordinary Items
144154

145155
Before tagging a function, we must declare them as ordinary items with `#[clippy::safety::tag]` such
@@ -209,7 +219,7 @@ Currently, safety tags requires the following unstable features
209219
Since the safety-tag mechanism is implemented primarily in Clippy and rust-analyzer, no additional
210220
support is required from rustc.
211221

212-
But We ask the libs team to adopt safety tags for all public `unsafe` APIs in libstd, along with
222+
But we ask the libs team to adopt safety tags for all public `unsafe` APIs in libstd, along with
213223
their call sites. To enable experimentation, a nightly-only library feature
214224
`#![feature(safety_tags)]` should be introduced and remain unstable until the design is finalized.
215225

0 commit comments

Comments
 (0)