Skip to content

Commit 817ad57

Browse files
Danilo Krummrichfbq
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 <[email protected]> Reviewed-by: Benno Lossin <[email protected]> Reviewed-by: Gary Guo <[email protected]> Signed-off-by: Danilo Krummrich <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 026a3eb commit 817ad57

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
@@ -142,7 +142,7 @@ impl Error {
142142
}
143143

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

0 commit comments

Comments
 (0)