Skip to content

Commit 9838e5d

Browse files
committed
mention 'other opt-in switch' as unresolved question
1 parent 814301e commit 9838e5d

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -151,24 +151,18 @@ unsafe fn foo(...) -> ... { unsafe {
151151
# Rationale and alternatives
152152
[rationale-and-alternatives]: #rationale-and-alternatives
153153

154-
I explained the rationale in the motivation section.
154+
To achieve the goals laid out in the motivation section, the proposed approach
155+
is least invasive in the sense that it avoids introducing new keywords, and
156+
instead relies on the existing lint mechanism to perform the transition.
155157

156-
The alternative is to not do anything, and live with the current situation.
157-
158-
We could bikeshed the lint name.
158+
One alternative always is to not do anything, and live with the current
159+
situation.
159160

160161
We could avoid using `unsafe` for dual purpose, and instead have `unsafe_to_call
161162
fn` for functions that are "unsafe to call" but do not implicitly have an
162163
`unsafe {}` block in their body. For consistency, we might want `unsafe_to_impl
163164
trait` for traits, though the behavior would be the same as `unsafe trait`.
164165

165-
We could avoid having the "unnecessary unsafe" lint depend on
166-
`unsafe_op_in_unsafe_fn` and instead always behave like those blocks are
167-
necessary (if they contain an "unsafe to call" operation). That would avoid a
168-
dependency of one lint on another, but it could possibly be confusing when,
169-
inside an `unsafe fn`, some operations are guarded by an unsafe block and others
170-
are not.
171-
172166
We could introduce named proof obligations (proposed by @Centril) such that the
173167
compiler can be be told (to some extend) if the assumptions made by the `unsafe
174168
fn` are sufficient to discharge the requirements of the unsafe operations.
@@ -177,6 +171,8 @@ We could restrict this requirement to use `unsafe` blocks in `unsafe fn` to
177171
those `unsafe fn` that contain at least one `unsafe` block, meaning short
178172
`unsafe fn` would keep compiling like they do now.
179173

174+
And of course, the lint name is subject to bikeshedding.
175+
180176
# Prior art
181177
[prior-art]: #prior-art
182178

@@ -208,3 +204,7 @@ care applied to them from the start. Potentially, `rustfmt` could be taught to
208204
format `unsafe` blocks that wrap the entire function body in a way that avoids
209205
double-indent. "function bodies as expressions" would enable a format like
210206
`unsafe fn foo() = unsafe { body }`.
207+
208+
It is not entirely clear if having the behavior of one lint depend on another
209+
will work (though most likely, it will). If it does not, we should try to find
210+
some other mechanism to opt-in to the new treatment of `unsafe fn` bodies.

0 commit comments

Comments
 (0)