File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
tests/fail/function_pointers Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ use std:: num:: * ;
2
+
3
+ #[ repr( C ) ]
4
+ struct S1 ( NonZeroI32 ) ;
5
+
6
+ #[ repr( C ) ]
7
+ struct S2 ( i32 ) ;
8
+
9
+ fn callee ( _s : S2 ) { }
10
+
11
+ fn main ( ) {
12
+ let fnptr: fn ( S2 ) = callee;
13
+ let fnptr: fn ( S1 ) = unsafe { std:: mem:: transmute ( fnptr) } ;
14
+ fnptr ( S1 ( NonZeroI32 :: new ( 1 ) . unwrap ( ) ) ) ;
15
+ //~^ ERROR: calling a function with argument of type S2 passing data of type S1
16
+ }
Original file line number Diff line number Diff line change
1
+ error: Undefined Behavior: calling a function with argument of type S2 passing data of type S1
2
+ --> $DIR/abi_mismatch_repr_C.rs:LL:CC
3
+ |
4
+ LL | fnptr(S1(NonZeroI32::new(1).unwrap()));
5
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling a function with argument of type S2 passing data of type S1
6
+ |
7
+ = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8
+ = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9
+ = help: this means these two types are not *guaranteed* to be ABI-compatible across all targets
10
+ = help: if you think this code should be accepted anyway, please report an issue
11
+ = note: BACKTRACE:
12
+ = note: inside `main` at $DIR/abi_mismatch_repr_C.rs:LL:CC
13
+
14
+ note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
15
+
16
+ error: aborting due to 1 previous error
17
+
You can’t perform that action at this time.
0 commit comments