Skip to content

Commit de4bf22

Browse files
bonziniBennoLossin
authored andcommitted
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 <benno.lossin@proton.me> Tested-by: Andreas Hindborg <a.hindborg@samsung.com> Link: https://lore.kernel.org/r/20240709160615.998336-3-ojeda@kernel.org Signed-off-by: Miguel Ojeda <ojeda@kernel.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> (cherry picked from commit dee1396a486cf2b6e7840322f6d104680649f2ff)
1 parent a7447f3 commit de4bf22

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

src/lib.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -824,11 +824,8 @@ where
824824
let val = unsafe { &mut *slot };
825825
// SAFETY: `slot` is considered pinned.
826826
let val = unsafe { Pin::new_unchecked(val) };
827-
(self.1)(val).map_err(|e| {
828-
// SAFETY: `slot` was initialized above.
829-
unsafe { core::ptr::drop_in_place(slot) };
830-
e
831-
})
827+
// SAFETY: `slot` was initialized above.
828+
(self.1)(val).inspect_err(|_| unsafe { core::ptr::drop_in_place(slot) })
832829
}
833830
}
834831

@@ -922,11 +919,9 @@ where
922919
// SAFETY: All requirements fulfilled since this function is `__init`.
923920
unsafe { self.0.__pinned_init(slot)? };
924921
// SAFETY: The above call initialized `slot` and we still have unique access.
925-
(self.1)(unsafe { &mut *slot }).map_err(|e| {
922+
(self.1)(unsafe { &mut *slot }).inspect_err(|_|
926923
// SAFETY: `slot` was initialized above.
927-
unsafe { core::ptr::drop_in_place(slot) };
928-
e
929-
})
924+
unsafe { core::ptr::drop_in_place(slot) })
930925
}
931926
}
932927

0 commit comments

Comments
 (0)