Skip to content

Commit 7bc1867

Browse files
committed
rust: error: allow useless_conversion for 32-bit builds
For the new Rust support for 32-bit arm [1], Clippy warns: error: useless conversion to the same type: `i32` --> rust/kernel/error.rs:139:36 | 139 | unsafe { bindings::ERR_PTR(self.0.into()) as *mut _ } | ^^^^^^^^^^^^^ help: consider removing `.into()`: `self.0` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion = note: `-D clippy::useless-conversion` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::useless_conversion)]` The `self.0.into()` converts an `c_int` into `ERR_PTR`'s parameter which is a `c_long`. Thus, both types are `i32` in 32-bit. Therefore, allow it for those architectures. Link: https://lore.kernel.org/rust-for-linux/[email protected]/ [1] Reviewed-by: Alice Ryhl <[email protected]> Reviewed-by: Christian Schrefl <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Fixed typo in tag. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 7adcdd5 commit 7bc1867

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

rust/kernel/error.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,11 @@ impl Error {
135135
/// Returns the error encoded as a pointer.
136136
#[allow(dead_code)]
137137
pub(crate) fn to_ptr<T>(self) -> *mut T {
138+
#[cfg_attr(target_pointer_width = "32", allow(clippy::useless_conversion))]
138139
// SAFETY: `self.0` is a valid error due to its invariant.
139-
unsafe { bindings::ERR_PTR(self.0.into()) as *mut _ }
140+
unsafe {
141+
bindings::ERR_PTR(self.0.into()) as *mut _
142+
}
140143
}
141144

142145
/// Returns a string representing the error, if one exists.

0 commit comments

Comments
 (0)