Skip to content

Commit 4a28ab4

Browse files
Danilo Krummrichojeda
authored andcommitted
rust: error: check for config test in Error::name
Additional to `testlib` also check for `test` in `Error::name`. This is required by a subsequent patch that (indirectly) uses `Error` in test cases. Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Gary Guo <gary@garyguo.net> Signed-off-by: Danilo Krummrich <dakr@kernel.org> Link: https://lore.kernel.org/r/20241004154149.93856-24-dakr@kernel.org Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 29a48d2 commit 4a28ab4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

rust/kernel/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl Error {
161161
}
162162

163163
/// Returns a string representing the error, if one exists.
164-
#[cfg(not(testlib))]
164+
#[cfg(not(any(test, testlib)))]
165165
pub fn name(&self) -> Option<&'static CStr> {
166166
// SAFETY: Just an FFI call, there are no extra safety requirements.
167167
let ptr = unsafe { bindings::errname(-self.0.get()) };
@@ -178,7 +178,7 @@ impl Error {
178178
/// When `testlib` is configured, this always returns `None` to avoid the dependency on a
179179
/// kernel function so that tests that use this (e.g., by calling [`Result::unwrap`]) can still
180180
/// run in userspace.
181-
#[cfg(testlib)]
181+
#[cfg(any(test, testlib))]
182182
pub fn name(&self) -> Option<&'static CStr> {
183183
None
184184
}

0 commit comments

Comments
 (0)