1
1
mod crosspointer_transmute;
2
2
mod eager_transmute;
3
3
mod missing_transmute_annotations;
4
- mod transmute_float_to_int;
5
4
mod transmute_int_to_bool;
6
- mod transmute_int_to_char;
7
- mod transmute_int_to_float;
8
5
mod transmute_int_to_non_zero;
9
6
mod transmute_null_to_fn;
10
- mod transmute_num_to_bytes;
11
7
mod transmute_ptr_to_ptr;
12
8
mod transmute_ptr_to_ref;
13
9
mod transmute_ref_to_ref;
@@ -141,40 +137,6 @@ declare_clippy_lint! {
141
137
"transmutes from a pointer to a reference type"
142
138
}
143
139
144
- declare_clippy_lint ! {
145
- /// ### What it does
146
- /// Checks for transmutes from an integer to a `char`.
147
- ///
148
- /// ### Why is this bad?
149
- /// Not every integer is a Unicode scalar value.
150
- ///
151
- /// ### Known problems
152
- /// - [`from_u32`] which this lint suggests using is slower than `transmute`
153
- /// as it needs to validate the input.
154
- /// If you are certain that the input is always a valid Unicode scalar value,
155
- /// use [`from_u32_unchecked`] which is as fast as `transmute`
156
- /// but has a semantically meaningful name.
157
- /// - You might want to handle `None` returned from [`from_u32`] instead of calling `unwrap`.
158
- ///
159
- /// [`from_u32`]: https://doc.rust-lang.org/std/char/fn.from_u32.html
160
- /// [`from_u32_unchecked`]: https://doc.rust-lang.org/std/char/fn.from_u32_unchecked.html
161
- ///
162
- /// ### Example
163
- /// ```no_run
164
- /// let x = 1_u32;
165
- /// unsafe {
166
- /// let _: char = std::mem::transmute(x); // where x: u32
167
- /// }
168
- ///
169
- /// // should be:
170
- /// let _ = std::char::from_u32(x).unwrap();
171
- /// ```
172
- #[ clippy:: version = "pre 1.29.0" ]
173
- pub TRANSMUTE_INT_TO_CHAR ,
174
- complexity,
175
- "transmutes from an integer to a `char`"
176
- }
177
-
178
140
declare_clippy_lint ! {
179
141
/// ### What it does
180
142
/// Checks for transmutes from a `&[u8]` to a `&str`.
@@ -232,29 +194,6 @@ declare_clippy_lint! {
232
194
"transmutes from an integer to a `bool`"
233
195
}
234
196
235
- declare_clippy_lint ! {
236
- /// ### What it does
237
- /// Checks for transmutes from an integer to a float.
238
- ///
239
- /// ### Why is this bad?
240
- /// Transmutes are dangerous and error-prone, whereas `from_bits` is intuitive
241
- /// and safe.
242
- ///
243
- /// ### Example
244
- /// ```no_run
245
- /// unsafe {
246
- /// let _: f32 = std::mem::transmute(1_u32); // where x: u32
247
- /// }
248
- ///
249
- /// // should be:
250
- /// let _: f32 = f32::from_bits(1_u32);
251
- /// ```
252
- #[ clippy:: version = "pre 1.29.0" ]
253
- pub TRANSMUTE_INT_TO_FLOAT ,
254
- complexity,
255
- "transmutes from an integer to a float"
256
- }
257
-
258
197
declare_clippy_lint ! {
259
198
/// ### What it does
260
199
/// Checks for transmutes from `T` to `NonZero<T>`, and suggests the `new_unchecked`
@@ -280,29 +219,6 @@ declare_clippy_lint! {
280
219
"transmutes from an integer to a non-zero wrapper"
281
220
}
282
221
283
- declare_clippy_lint ! {
284
- /// ### What it does
285
- /// Checks for transmutes from a float to an integer.
286
- ///
287
- /// ### Why is this bad?
288
- /// Transmutes are dangerous and error-prone, whereas `to_bits` is intuitive
289
- /// and safe.
290
- ///
291
- /// ### Example
292
- /// ```no_run
293
- /// unsafe {
294
- /// let _: u32 = std::mem::transmute(1f32);
295
- /// }
296
- ///
297
- /// // should be:
298
- /// let _: u32 = 1f32.to_bits();
299
- /// ```
300
- #[ clippy:: version = "1.41.0" ]
301
- pub TRANSMUTE_FLOAT_TO_INT ,
302
- complexity,
303
- "transmutes from a float to an integer"
304
- }
305
-
306
222
declare_clippy_lint ! {
307
223
/// ### What it does
308
224
/// Checks for transmutes from a number to an array of `u8`
@@ -581,12 +497,9 @@ impl_lint_pass!(Transmute => [
581
497
TRANSMUTE_PTR_TO_PTR ,
582
498
USELESS_TRANSMUTE ,
583
499
WRONG_TRANSMUTE ,
584
- TRANSMUTE_INT_TO_CHAR ,
585
500
TRANSMUTE_BYTES_TO_STR ,
586
501
TRANSMUTE_INT_TO_BOOL ,
587
- TRANSMUTE_INT_TO_FLOAT ,
588
502
TRANSMUTE_INT_TO_NON_ZERO ,
589
- TRANSMUTE_FLOAT_TO_INT ,
590
503
TRANSMUTE_NUM_TO_BYTES ,
591
504
UNSOUND_COLLECTION_TRANSMUTE ,
592
505
TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS ,
@@ -632,14 +545,10 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
632
545
| transmute_null_to_fn:: check ( cx, e, arg, to_ty)
633
546
| transmute_ptr_to_ref:: check ( cx, e, from_ty, to_ty, arg, path, self . msrv )
634
547
| missing_transmute_annotations:: check ( cx, path, from_ty, to_ty, e. hir_id )
635
- | transmute_int_to_char:: check ( cx, e, from_ty, to_ty, arg, const_context)
636
548
| transmute_ref_to_ref:: check ( cx, e, from_ty, to_ty, arg, const_context)
637
549
| transmute_ptr_to_ptr:: check ( cx, e, from_ty, to_ty, arg, self . msrv )
638
550
| transmute_int_to_bool:: check ( cx, e, from_ty, to_ty, arg)
639
- | transmute_int_to_float:: check ( cx, e, from_ty, to_ty, arg, const_context, self . msrv )
640
551
| transmute_int_to_non_zero:: check ( cx, e, from_ty, to_ty, arg)
641
- | transmute_float_to_int:: check ( cx, e, from_ty, to_ty, arg, const_context, self . msrv )
642
- | transmute_num_to_bytes:: check ( cx, e, from_ty, to_ty, arg, const_context, self . msrv )
643
552
| ( unsound_collection_transmute:: check ( cx, e, from_ty, to_ty)
644
553
|| transmute_undefined_repr:: check ( cx, e, from_ty, to_ty) )
645
554
| ( eager_transmute:: check ( cx, e, arg, from_ty, to_ty) ) ;
0 commit comments