Skip to content

Commit e2376e5

Browse files
Add ui test for ADT
1 parent 1bbdfde commit e2376e5

3 files changed

+45
-3
lines changed

tests/ui/missing_transmute_annotations.fixed

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ unsafe fn foo7() -> i32 {
5353
bad_transmute!([1u16, 2u16])
5454
}
5555

56+
#[repr(i32)]
57+
enum Foo {
58+
A = 0,
59+
}
60+
61+
unsafe fn foo8() -> Foo {
62+
std::mem::transmute::<i32, Foo>(0i32)
63+
//~^ ERROR: transmute used without annotations
64+
}
65+
66+
unsafe fn foo9() -> i32 {
67+
std::mem::transmute::<Foo, i32>(Foo::A)
68+
//~^ ERROR: transmute used without annotations
69+
}
70+
5671
fn main() {
5772
let x: _ = unsafe { std::mem::transmute::<[u16; 2], i32>([1u16, 2u16]) };
5873
//~^ ERROR: transmute used without annotations

tests/ui/missing_transmute_annotations.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ unsafe fn foo7() -> i32 {
5353
bad_transmute!([1u16, 2u16])
5454
}
5555

56+
#[repr(i32)]
57+
enum Foo {
58+
A = 0,
59+
}
60+
61+
unsafe fn foo8() -> Foo {
62+
std::mem::transmute(0i32)
63+
//~^ ERROR: transmute used without annotations
64+
}
65+
66+
unsafe fn foo9() -> i32 {
67+
std::mem::transmute(Foo::A)
68+
//~^ ERROR: transmute used without annotations
69+
}
70+
5671
fn main() {
5772
let x: _ = unsafe { std::mem::transmute::<_, i32>([1u16, 2u16]) };
5873
//~^ ERROR: transmute used without annotations

tests/ui/missing_transmute_annotations.stderr

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,28 @@ LL | local_bad_transmute!([1u16, 2u16])
4949
= note: this error originates in the macro `local_bad_transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
5050

5151
error: transmute used without annotations
52-
--> tests/ui/missing_transmute_annotations.rs:57:35
52+
--> tests/ui/missing_transmute_annotations.rs:62:15
53+
|
54+
LL | std::mem::transmute(0i32)
55+
| ^^^^^^^^^ help: consider adding missing annotations: `transmute::<i32, Foo>`
56+
57+
error: transmute used without annotations
58+
--> tests/ui/missing_transmute_annotations.rs:67:15
59+
|
60+
LL | std::mem::transmute(Foo::A)
61+
| ^^^^^^^^^ help: consider adding missing annotations: `transmute::<Foo, i32>`
62+
63+
error: transmute used without annotations
64+
--> tests/ui/missing_transmute_annotations.rs:72:35
5365
|
5466
LL | let x: _ = unsafe { std::mem::transmute::<_, i32>([1u16, 2u16]) };
5567
| ^^^^^^^^^^^^^^^^^^^ help: consider adding missing annotations: `transmute::<[u16; 2], i32>`
5668

5769
error: transmute used without annotations
58-
--> tests/ui/missing_transmute_annotations.rs:60:30
70+
--> tests/ui/missing_transmute_annotations.rs:75:30
5971
|
6072
LL | let x: _ = std::mem::transmute::<_, i32>([1u16, 2u16]);
6173
| ^^^^^^^^^^^^^^^^^^^ help: consider adding missing annotations: `transmute::<[u16; 2], i32>`
6274

63-
error: aborting due to 9 previous errors
75+
error: aborting due to 11 previous errors
6476

0 commit comments

Comments
 (0)