Skip to content

Commit d5fe00f

Browse files
committed
rust: init: simplify from map_err to inspect_err
A new complexity lint, `manual_inspect` [1], has been introduced in the upcoming Rust 1.81 (currently in nightly), which checks for uses of `map*` which return the original item: error: --> rust/kernel/init.rs:846:23 | 846 | (self.1)(val).map_err(|e| { | ^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_inspect = note: `-D clippy::manual-inspect` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::manual_inspect)]` help: try | 846 ~ (self.1)(val).inspect_err(|e| { 847 | // SAFETY: `slot` was initialized above. 848 ~ unsafe { core::ptr::drop_in_place(slot) }; | Thus clean them up. Link: https://rust-lang.github.io/rust-clippy/master/index.html#/manual_inspect [1] Tested-by: Benno Lossin <[email protected]> Tested-by: Andreas Hindborg <[email protected]> Signed-off-by: Miguel Ojeda <[email protected]>
1 parent bc7f84b commit d5fe00f

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

rust/kernel/init.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -843,11 +843,8 @@ where
843843
let val = unsafe { &mut *slot };
844844
// SAFETY: `slot` is considered pinned.
845845
let val = unsafe { Pin::new_unchecked(val) };
846-
(self.1)(val).map_err(|e| {
847-
// SAFETY: `slot` was initialized above.
848-
unsafe { core::ptr::drop_in_place(slot) };
849-
e
850-
})
846+
// SAFETY: `slot` was initialized above.
847+
(self.1)(val).inspect_err(|_| unsafe { core::ptr::drop_in_place(slot) })
851848
}
852849
}
853850

@@ -941,11 +938,9 @@ where
941938
// SAFETY: All requirements fulfilled since this function is `__init`.
942939
unsafe { self.0.__pinned_init(slot)? };
943940
// SAFETY: The above call initialized `slot` and we still have unique access.
944-
(self.1)(unsafe { &mut *slot }).map_err(|e| {
941+
(self.1)(unsafe { &mut *slot }).inspect_err(|_|
945942
// SAFETY: `slot` was initialized above.
946-
unsafe { core::ptr::drop_in_place(slot) };
947-
e
948-
})
943+
unsafe { core::ptr::drop_in_place(slot) })
949944
}
950945
}
951946

0 commit comments

Comments
 (0)