|
1 |
| -use std::fmt::Display; |
| 1 | +use std::{ffi::c_void, fmt::Display}; |
2 | 2 |
|
3 | 3 | use mlir_sys::{
|
4 | 4 | mlirOperationDump, mlirOperationGetAttribute, mlirOperationGetAttributeByName,
|
@@ -274,21 +274,23 @@ pub trait OperationLike<'c: 'a, 'a>: Display + 'a {
|
274 | 274 | F: for<'x, 'y> FnMut(OperationRef<'x, 'y>) -> WalkResult,
|
275 | 275 | {
|
276 | 276 | // trampoline from C to Rust
|
277 |
| - unsafe extern "C" fn tramp<F>( |
278 |
| - raw: MlirOperation, |
279 |
| - user_data: *mut std::os::raw::c_void, |
280 |
| - ) -> MlirWalkResult |
281 |
| - where |
282 |
| - F: for<'x, 'y> FnMut(OperationRef<'x, 'y>) -> WalkResult, |
283 |
| - { |
284 |
| - let cb: &mut F = &mut *(user_data as *mut F); |
285 |
| - let op = OperationRef::from_raw(raw); |
286 |
| - (cb)(op) as MlirWalkResult |
| 277 | + unsafe extern "C" fn tramp<'c: 'a, 'a, F: FnMut(OperationRef<'c, 'a>) -> WalkResult>( |
| 278 | + operation: MlirOperation, |
| 279 | + data: *mut c_void, |
| 280 | + ) -> MlirWalkResult { |
| 281 | + let callback: &mut F = &mut *(data as *mut F); |
| 282 | + let operation = OperationRef::from_raw(operation); |
| 283 | + |
| 284 | + (callback)(operation) as _ |
287 | 285 | }
|
288 | 286 |
|
289 |
| - let data = &mut callback as *mut _ as *mut std::os::raw::c_void; |
290 | 287 | unsafe {
|
291 |
| - mlirOperationWalk(self.to_raw(), Some(tramp::<F>), data, order as _); |
| 288 | + mlirOperationWalk( |
| 289 | + self.to_raw(), |
| 290 | + Some(tramp::<'c, 'a, F>), |
| 291 | + &mut callback as *mut _ as *mut _, |
| 292 | + order as _, |
| 293 | + ); |
292 | 294 | }
|
293 | 295 | }
|
294 | 296 | }
|
|
0 commit comments