@@ -217,6 +217,16 @@ newtype for which the operator overloads are implemented using the
217
217
Note that this is only for potential convenience. The type-based approach has the
218
218
drawback that e.g. ` Vec<int> ` and ` Vec<Wrapping<int>> ` are incompatible types.
219
219
220
+ ## Lint
221
+
222
+ In general it seems inadvisable to use operations with error
223
+ conditions (like a naked ` + ` or ` - ` ) in unsafe code. It would be
224
+ better to use explicit ` checked ` or ` wrapped ` operations as
225
+ appropriate. The same holds for destructors, since unwinding in
226
+ destructors is inadvisable. Therefore, the RFC recommends a lint be
227
+ added against such operations, defaulting to warn, though the details
228
+ (such as the name of this lint) are not spelled out.
229
+
220
230
# Drawbacks
221
231
222
232
** Making choices is hard.** Having to think about whether wraparound
@@ -252,10 +262,10 @@ violated. However, this danger already exists, as there are numerous
252
262
ways to trigger a panic, and hence unsafe code must be written with
253
263
this in mind. It seems like the best advice is for unsafe code to
254
264
eschew the plain ` + ` and ` - ` operators, and instead prefer explicit
255
- checked or wrapping operations as appropriate (this would be a good
256
- opportunity for a lint). Furthermore, the danger of an unexpected
257
- panic occurring in unsafe code must be weighed against the danger of a
258
- (silent) overflow, which can also lead to unsafety.
265
+ checked or wrapping operations as appropriate (hence the proposed
266
+ lint). Furthermore, the danger of an unexpected panic occurring in
267
+ unsafe code must be weighed against the danger of a (silent) overflow,
268
+ which can also lead to unsafety.
259
269
260
270
** Divergence of debug and optimized code.** The proposal here causes
261
271
additional divergence of debug and optimized code, since optimized
0 commit comments