Skip to content

Commit 8cb1b3f

Browse files
committed
more alternatives
1 parent 153d286 commit 8cb1b3f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

text/0000-unsafe-block-in-unsafe-fn.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ This new warning will likely fire for the vast majority of `unsafe fn` out there
124124

125125
Many `unsafe fn` are actually rather short (no more than 3 lines) and will
126126
likely end up just being one large `unsafe` block. This change would make such
127-
functions less ergonomic to write.
127+
functions less ergonomic to write, they would likely become
128+
129+
```rust
130+
unsafe fn foo(...) -> ... { unsafe {
131+
// Code goes here
132+
} }
133+
```
128134

129135
# Rationale and alternatives
130136
[rationale-and-alternatives]: #rationale-and-alternatives
@@ -137,6 +143,14 @@ We could introduce named proof obligations (proposed by @Centril) such that the
137143
compiler can be be told (to some extend) if the assumptions made by the `unsafe
138144
fn` are sufficient to discharge the requirements of the unsafe operations.
139145

146+
We could restrict this requirement to use `unsafe` blocks in `unsafe fn` to
147+
those `unsafe fn` that contain at least one `unsafe` block, meaning short
148+
`unsafe fn` would keep compiling like they do now.
149+
150+
We could have separate marker for `unsafe fn` with and without an implicitly
151+
unsafe body, e.g. `unsafe unsafe fn` has an unsafe body, or `unsafe fn foo(...)
152+
-> ... unsafe { }` has an unsafe body, or `unsafe_to_call fn` has a safe body.
153+
140154
# Prior art
141155
[prior-art]: #prior-art
142156

0 commit comments

Comments
 (0)