Skip to content

Commit bc8d32d

Browse files
committed
fix unary minus on usize and unused variable errors in .fixed file
1 parent 84db238 commit bc8d32d

3 files changed

+32
-32
lines changed

tests/ui/transmutes_expressible_as_ptr_casts.fixed

+15-15
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,54 @@ fn main() {
1515
// the casts, since the casts are the recommended fixes.
1616

1717
// e is an integer and U is *U_0, while U_0: Sized; addr-ptr-cast
18-
let ptr_i32_transmute = unsafe {
19-
-1 as *const i32
18+
let _ptr_i32_transmute = unsafe {
19+
usize::MAX as *const i32
2020
};
21-
let ptr_i32 = -1isize as *const i32;
21+
let ptr_i32 = usize::MAX as *const i32;
2222

2323
// e has type *T, U is *U_0, and either U_0: Sized ...
24-
let ptr_i8_transmute = unsafe {
24+
let _ptr_i8_transmute = unsafe {
2525
ptr_i32 as *const i8
2626
};
27-
let ptr_i8 = ptr_i32 as *const i8;
27+
let _ptr_i8 = ptr_i32 as *const i8;
2828

2929
let slice_ptr = &[0,1,2,3] as *const [i32];
3030

3131
// ... or pointer_kind(T) = pointer_kind(U_0); ptr-ptr-cast
32-
let ptr_to_unsized_transmute = unsafe {
32+
let _ptr_to_unsized_transmute = unsafe {
3333
slice_ptr as *const [u16]
3434
};
35-
let ptr_to_unsized = slice_ptr as *const [u16];
35+
let _ptr_to_unsized = slice_ptr as *const [u16];
3636
// TODO: We could try testing vtable casts here too, but maybe
3737
// we should wait until std::raw::TraitObject is stabilized?
3838

3939
// e has type *T and U is a numeric type, while T: Sized; ptr-addr-cast
40-
let usize_from_int_ptr_transmute = unsafe {
40+
let _usize_from_int_ptr_transmute = unsafe {
4141
ptr_i32 as usize
4242
};
43-
let usize_from_int_ptr = ptr_i32 as usize;
43+
let _usize_from_int_ptr = ptr_i32 as usize;
4444

4545
let array_ref: &[i32; 4] = &[1,2,3,4];
4646

4747
// e has type &[T; n] and U is *const T; array-ptr-cast
48-
let array_ptr_transmute = unsafe {
48+
let _array_ptr_transmute = unsafe {
4949
array_ref as *const [i32; 4]
5050
};
51-
let array_ptr = array_ref as *const [i32; 4];
51+
let _array_ptr = array_ref as *const [i32; 4];
5252

5353
fn foo(_: usize) -> u8 { 42 }
5454

5555
// e is a function pointer type and U has type *T, while T: Sized; fptr-ptr-cast
56-
let usize_ptr_transmute = unsafe {
56+
let _usize_ptr_transmute = unsafe {
5757
foo as *const usize
5858
};
59-
let usize_ptr_transmute = foo as *const usize;
59+
let _usize_ptr_transmute = foo as *const usize;
6060

6161
// e is a function pointer type and U is an integer; fptr-addr-cast
62-
let usize_from_fn_ptr_transmute = unsafe {
62+
let _usize_from_fn_ptr_transmute = unsafe {
6363
foo as usize
6464
};
65-
let usize_from_fn_ptr = foo as *const usize;
65+
let _usize_from_fn_ptr = foo as *const usize;
6666
}
6767

6868
// If a ref-to-ptr cast of this form where the pointer type points to a type other

tests/ui/transmutes_expressible_as_ptr_casts.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,54 @@ fn main() {
1515
// the casts, since the casts are the recommended fixes.
1616

1717
// e is an integer and U is *U_0, while U_0: Sized; addr-ptr-cast
18-
let ptr_i32_transmute = unsafe {
19-
transmute::<isize, *const i32>(-1)
18+
let _ptr_i32_transmute = unsafe {
19+
transmute::<usize, *const i32>(usize::MAX)
2020
};
21-
let ptr_i32 = -1isize as *const i32;
21+
let ptr_i32 = usize::MAX as *const i32;
2222

2323
// e has type *T, U is *U_0, and either U_0: Sized ...
24-
let ptr_i8_transmute = unsafe {
24+
let _ptr_i8_transmute = unsafe {
2525
transmute::<*const i32, *const i8>(ptr_i32)
2626
};
27-
let ptr_i8 = ptr_i32 as *const i8;
27+
let _ptr_i8 = ptr_i32 as *const i8;
2828

2929
let slice_ptr = &[0,1,2,3] as *const [i32];
3030

3131
// ... or pointer_kind(T) = pointer_kind(U_0); ptr-ptr-cast
32-
let ptr_to_unsized_transmute = unsafe {
32+
let _ptr_to_unsized_transmute = unsafe {
3333
transmute::<*const [i32], *const [u16]>(slice_ptr)
3434
};
35-
let ptr_to_unsized = slice_ptr as *const [u16];
35+
let _ptr_to_unsized = slice_ptr as *const [u16];
3636
// TODO: We could try testing vtable casts here too, but maybe
3737
// we should wait until std::raw::TraitObject is stabilized?
3838

3939
// e has type *T and U is a numeric type, while T: Sized; ptr-addr-cast
40-
let usize_from_int_ptr_transmute = unsafe {
40+
let _usize_from_int_ptr_transmute = unsafe {
4141
transmute::<*const i32, usize>(ptr_i32)
4242
};
43-
let usize_from_int_ptr = ptr_i32 as usize;
43+
let _usize_from_int_ptr = ptr_i32 as usize;
4444

4545
let array_ref: &[i32; 4] = &[1,2,3,4];
4646

4747
// e has type &[T; n] and U is *const T; array-ptr-cast
48-
let array_ptr_transmute = unsafe {
48+
let _array_ptr_transmute = unsafe {
4949
transmute::<&[i32; 4], *const [i32; 4]>(array_ref)
5050
};
51-
let array_ptr = array_ref as *const [i32; 4];
51+
let _array_ptr = array_ref as *const [i32; 4];
5252

5353
fn foo(_: usize) -> u8 { 42 }
5454

5555
// e is a function pointer type and U has type *T, while T: Sized; fptr-ptr-cast
56-
let usize_ptr_transmute = unsafe {
56+
let _usize_ptr_transmute = unsafe {
5757
transmute::<fn(usize) -> u8, *const usize>(foo)
5858
};
59-
let usize_ptr_transmute = foo as *const usize;
59+
let _usize_ptr_transmute = foo as *const usize;
6060

6161
// e is a function pointer type and U is an integer; fptr-addr-cast
62-
let usize_from_fn_ptr_transmute = unsafe {
62+
let _usize_from_fn_ptr_transmute = unsafe {
6363
transmute::<fn(usize) -> u8, usize>(foo)
6464
};
65-
let usize_from_fn_ptr = foo as *const usize;
65+
let _usize_from_fn_ptr = foo as *const usize;
6666
}
6767

6868
// If a ref-to-ptr cast of this form where the pointer type points to a type other

tests/ui/transmutes_expressible_as_ptr_casts.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: transmute from an integer to a pointer
22
--> $DIR/transmutes_expressible_as_ptr_casts.rs:19:9
33
|
4-
LL | transmute::<isize, *const i32>(-1)
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-1 as *const i32`
4+
LL | transmute::<usize, *const i32>(usize::MAX)
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `usize::MAX as *const i32`
66
|
77
= note: `-D clippy::useless-transmute` implied by `-D warnings`
88

0 commit comments

Comments
 (0)