File: fn_ptr.rs

package info (click to toggle)
rustc 1.86.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 913,560 kB
  • sloc: xml: 158,127; python: 35,921; javascript: 19,689; sh: 19,600; cpp: 18,906; ansic: 13,124; asm: 4,376; makefile: 708; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (51 lines) | stat: -rw-r--r-- 1,852 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//@ only-cdb
//@ compile-flags:-g

// === CDB TESTS ==================================================================================

// cdb-command: g
// cdb-command: dx basic
// cdb-check: basic            : [...] : a!core::ops::function::FnOnce::call_once<fn_ptr::main::closure_env$0,tuple$<i32,i32> >+0x0 [Type: int (__cdecl*)(int,int)]
// cdb-check: a!core::ops::function::FnOnce::call_once<fn_ptr::main::closure_env$0,tuple$<i32,i32> >+0x0 [Type: int __cdecl(int,int)]

// cdb-command: dx paramless
// cdb-check: paramless        : [...] : a!core::ops::function::FnOnce::call_once<fn_ptr::main::closure_env$1,tuple$<> >+0x0 [Type: int (__cdecl*)()]
// cdb-check: a!core::ops::function::FnOnce::call_once<fn_ptr::main::closure_env$1,tuple$<> >+0x0 [Type: int __cdecl()]

// cdb-command: dx my_struct
// cdb-check: my_struct        [Type: fn_ptr::MyStruct]
// cdb-check:   [+0x000] my_field         : [...] : a!core::ops::function::FnOnce::call_once<fn_ptr::main::closure_env$2,tuple$<ref$<fn_ptr::MyStruct> > >+0x0 [Type: int (__cdecl*)(fn_ptr::MyStruct *)]

// cdb-command: dx non_rec_struct
// cdb-check: non_rec_struct   [Type: fn_ptr::NonRecStruct]
// cdb-check:  [+0x000] my_field         : [...] : a!core::ops::function::FnOnce::call_once<fn_ptr::main::closure_env$3,tuple$<i32> >+0x0 [Type: int (__cdecl*)(int)]

type BasicFnPtr = fn(i32, i32) -> i32;

pub type ParamlessFnPtr = fn() -> i32;

type MyFnPtr = fn(b: &MyStruct) -> i32;

type NonRecFnPtr = fn(i: i32) -> i32;

struct MyStruct {
    my_field: MyFnPtr,
}

struct NonRecStruct {
    my_field: NonRecFnPtr,
}

fn main() {
    let basic: BasicFnPtr = |a, b| a + b;
    let paramless: ParamlessFnPtr = || 1;
    let my_struct = MyStruct { my_field: |_| 1 };
    let non_rec_struct = NonRecStruct { my_field: |i| i };

    _zzz(); // #break
}

#[inline(never)]
fn _zzz() {
    ()
}