Skip to content

Commit

Permalink
Add ui test for ADT
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Feb 25, 2024
1 parent eadc7a9 commit 1ad95f1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
15 changes: 15 additions & 0 deletions tests/ui/missing_transmute_annotations.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ unsafe fn foo7() -> i32 {
bad_transmute!([1u16, 2u16])
}

#[repr(i32)]
enum Foo {
A = 0,
}

unsafe fn foo8() -> Foo {
std::mem::transmute::<i32, Foo>(0i32)
//~^ ERROR: transmute used without annotations
}

unsafe fn foo9() -> i32 {
std::mem::transmute::<Foo, i32>(Foo::A)
//~^ ERROR: transmute used without annotations
}

fn main() {
let x: _ = unsafe { std::mem::transmute::<[u16; 2], i32>([1u16, 2u16]) };
//~^ ERROR: transmute used without annotations
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/missing_transmute_annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ unsafe fn foo7() -> i32 {
bad_transmute!([1u16, 2u16])
}

#[repr(i32)]
enum Foo {
A = 0,
}

unsafe fn foo8() -> Foo {
std::mem::transmute(0i32)
//~^ ERROR: transmute used without annotations
}

unsafe fn foo9() -> i32 {
std::mem::transmute(Foo::A)
//~^ ERROR: transmute used without annotations
}

fn main() {
let x: _ = unsafe { std::mem::transmute::<_, i32>([1u16, 2u16]) };
//~^ ERROR: transmute used without annotations
Expand Down
18 changes: 15 additions & 3 deletions tests/ui/missing_transmute_annotations.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,28 @@ LL | local_bad_transmute!([1u16, 2u16])
= note: this error originates in the macro `local_bad_transmute` (in Nightly builds, run with -Z macro-backtrace for more info)

error: transmute used without annotations
--> tests/ui/missing_transmute_annotations.rs:57:35
--> tests/ui/missing_transmute_annotations.rs:62:15
|
LL | std::mem::transmute(0i32)
| ^^^^^^^^^ help: consider adding missing annotations: `transmute::<i32, Foo>`

error: transmute used without annotations
--> tests/ui/missing_transmute_annotations.rs:67:15
|
LL | std::mem::transmute(Foo::A)
| ^^^^^^^^^ help: consider adding missing annotations: `transmute::<Foo, i32>`

error: transmute used without annotations
--> tests/ui/missing_transmute_annotations.rs:72:35
|
LL | let x: _ = unsafe { std::mem::transmute::<_, i32>([1u16, 2u16]) };
| ^^^^^^^^^^^^^^^^^^^ help: consider adding missing annotations: `transmute::<[u16; 2], i32>`

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

error: aborting due to 9 previous errors
error: aborting due to 11 previous errors

0 comments on commit 1ad95f1

Please sign in to comment.