Skip to content

Commit d0e6104

Browse files
committed
Avoid UB in clippy transmute_ptr_to_ptr UI test
1 parent 003676e commit d0e6104

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

Diff for: src/tools/clippy/tests/ui/transmute_ptr_to_ptr.fixed

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ fn transmute_ptr_to_ptr() {
3535
// ref-ref transmutes; bad
3636
let _: &f32 = &*(&1u32 as *const u32 as *const f32);
3737
//~^ ERROR: transmute from a reference to a reference
38-
let _: &f64 = &*(&1f32 as *const f32 as *const f64);
38+
let _: &f32 = &*(&1f64 as *const f64 as *const f32);
3939
//~^ ERROR: transmute from a reference to a reference
4040
//:^ this test is here because both f32 and f64 are the same TypeVariant, but they are not
4141
// the same type
4242
let _: &mut f32 = &mut *(&mut 1u32 as *mut u32 as *mut f32);
4343
//~^ ERROR: transmute from a reference to a reference
4444
let _: &GenericParam<f32> = &*(&GenericParam { t: 1u32 } as *const GenericParam<u32> as *const GenericParam<f32>);
4545
//~^ ERROR: transmute from a reference to a reference
46-
let u8_ref: &u8 = &0u8;
47-
let u64_ref: &u64 = unsafe { &*(u8_ref as *const u8 as *const u64) };
46+
let u64_ref: &u64 = &0u64;
47+
let u8_ref: &u8 = unsafe { &*(u64_ref as *const u64 as *const u8) };
4848
//~^ ERROR: transmute from a reference to a reference
4949
}
5050

Diff for: src/tools/clippy/tests/ui/transmute_ptr_to_ptr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ fn transmute_ptr_to_ptr() {
3535
// ref-ref transmutes; bad
3636
let _: &f32 = std::mem::transmute(&1u32);
3737
//~^ ERROR: transmute from a reference to a reference
38-
let _: &f64 = std::mem::transmute(&1f32);
38+
let _: &f32 = std::mem::transmute(&1f64);
3939
//~^ ERROR: transmute from a reference to a reference
4040
//:^ this test is here because both f32 and f64 are the same TypeVariant, but they are not
4141
// the same type
4242
let _: &mut f32 = std::mem::transmute(&mut 1u32);
4343
//~^ ERROR: transmute from a reference to a reference
4444
let _: &GenericParam<f32> = std::mem::transmute(&GenericParam { t: 1u32 });
4545
//~^ ERROR: transmute from a reference to a reference
46-
let u8_ref: &u8 = &0u8;
47-
let u64_ref: &u64 = unsafe { std::mem::transmute(u8_ref) };
46+
let u64_ref: &u64 = &0u64;
47+
let u8_ref: &u8 = unsafe { std::mem::transmute(u64_ref) };
4848
//~^ ERROR: transmute from a reference to a reference
4949
}
5050

Diff for: src/tools/clippy/tests/ui/transmute_ptr_to_ptr.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ LL | let _: &f32 = std::mem::transmute(&1u32);
2222
error: transmute from a reference to a reference
2323
--> $DIR/transmute_ptr_to_ptr.rs:38:23
2424
|
25-
LL | let _: &f64 = std::mem::transmute(&1f32);
26-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&1f32 as *const f32 as *const f64)`
25+
LL | let _: &f32 = std::mem::transmute(&1f64);
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&1f64 as *const f64 as *const f32)`
2727

2828
error: transmute from a reference to a reference
2929
--> $DIR/transmute_ptr_to_ptr.rs:42:27
@@ -38,10 +38,10 @@ LL | let _: &GenericParam<f32> = std::mem::transmute(&GenericParam { t:
3838
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&GenericParam { t: 1u32 } as *const GenericParam<u32> as *const GenericParam<f32>)`
3939

4040
error: transmute from a reference to a reference
41-
--> $DIR/transmute_ptr_to_ptr.rs:47:38
41+
--> $DIR/transmute_ptr_to_ptr.rs:47:36
4242
|
43-
LL | let u64_ref: &u64 = unsafe { std::mem::transmute(u8_ref) };
44-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(u8_ref as *const u8 as *const u64)`
43+
LL | let u8_ref: &u8 = unsafe { std::mem::transmute(u64_ref) };
44+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(u64_ref as *const u64 as *const u8)`
4545

4646
error: aborting due to 7 previous errors
4747

0 commit comments

Comments
 (0)