@@ -151,24 +151,18 @@ unsafe fn foo(...) -> ... { unsafe {
151
151
# Rationale and alternatives
152
152
[ rationale-and-alternatives ] : #rationale-and-alternatives
153
153
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.
155
157
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.
159
160
160
161
We could avoid using ` unsafe ` for dual purpose, and instead have `unsafe_to_call
161
162
fn` for functions that are "unsafe to call" but do not implicitly have an
162
163
` unsafe {} ` block in their body. For consistency, we might want `unsafe_to_impl
163
164
trait` for traits, though the behavior would be the same as ` unsafe trait`.
164
165
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
-
172
166
We could introduce named proof obligations (proposed by @Centril ) such that the
173
167
compiler can be be told (to some extend) if the assumptions made by the `unsafe
174
168
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
177
171
those ` unsafe fn ` that contain at least one ` unsafe ` block, meaning short
178
172
` unsafe fn ` would keep compiling like they do now.
179
173
174
+ And of course, the lint name is subject to bikeshedding.
175
+
180
176
# Prior art
181
177
[ prior-art ] : #prior-art
182
178
@@ -208,3 +204,7 @@ care applied to them from the start. Potentially, `rustfmt` could be taught to
208
204
format ` unsafe ` blocks that wrap the entire function body in a way that avoids
209
205
double-indent. "function bodies as expressions" would enable a format like
210
206
` 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