MCPcopy Create free account
hub / github.com/IntegralPilot/rustc_codegen_jvm / main

Function main

tests/binary/fn_pointers/src/main.rs:115–188  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

113}
114
115type ErasedFormatter = unsafe fn(core::ptr::NonNull<()>, &mut i32) -> i32;
116
117#[derive(Copy, Clone)]
118struct FormatRecord {
119 value: i32,
120}
121
122fn format_i32(value: &i32, state: &mut i32) -> i32 {
123 *state += *value;
124 *state
125}
126
127fn format_i64(value: &i64, state: &mut i32) -> i32 {
128 *state += (*value / 10) as i32;
129 *state
130}
131
132fn format_u128(value: &u128, state: &mut i32) -> i32 {
133 *state += (*value / 100) as i32;
134 *state
135}
136
137fn format_record(value: &FormatRecord, state: &mut i32) -> i32 {
138 *state += value.value;
139 *state
140}
141
142fn format_str(value: &&str, state: &mut i32) -> i32 {
143 *state += value.len() as i32;
144 *state
145}
146
147fn call_erased<T>(value: &T, formatter: fn(&T, &mut i32) -> i32, initial: i32) -> i32 {
148 let erased: ErasedFormatter = unsafe { core::mem::transmute(formatter) };
149 let pointer: core::ptr::NonNull<()> = unsafe { core::mem::transmute(value) };
150 let mut state = initial;
151 unsafe { erased(pointer, &mut state) }
152}
153
154fn dummy() {}
155
156#[inline(never)]
157fn function_pointer_slot_is_null(pointer: *const fn()) -> bool {
158 pointer.is_null()
159}
160
161struct Ops {
162 unary: fn(i32) -> i32,
163 binary: fn(i32, i32) -> i32,
164}
165
166fn named_add_one(x: i32) -> i32 {
167 x + 1
168}
169
170// Const-eval path: closures inside a const initializer.
171const CLOSURE_OPS: Ops = Ops {
172 unary: |x| x * 3,

Callers

nothing calls this directly

Calls 4

derivativeFunction · 0.85
choose_curveFunction · 0.85
choose_int_opFunction · 0.85
ConstantEnum · 0.85

Tested by

no test coverage detected