mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-28 12:53:14 +01:00
rust: doctest: add LocalModule fallback for #[vtable] ThisModule
Add a `LocalModule` struct with a null-pointer `ModuleMetadata` impl in the doctest harness, so that `crate::LocalModule` (auto-inserted by `#[vtable]`) resolves correctly when there is no `module!` macro. Assisted-by: opencode:glm-5.2 Reviewed-by: Andreas Hindborg <[email protected]> Reviewed-by: Gary Guo <[email protected]> Acked-by: Danilo Krummrich <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Signed-off-by: Alvin Sun <[email protected]> Link: https://patch.msgid.link/[email protected] [ Fixed `clippy::undocumented_unsafe_blocks` lint by wrapping with a block. Added interim `#[allow(dead_code)]`. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
This commit is contained in:
1 parent
54f846db7b
commit
98f256e272
1 file changed
+19
@@ -239,6 +239,25 @@ pub extern "C" fn {kunit_name}(__kunit_test: *mut ::kernel::bindings::kunit) {{
|
||||
|
||||
const __LOG_PREFIX: &[u8] = b"rust_doctests_kernel\0";
|
||||
|
||||
/// Dummy module type for doctest context.
|
||||
#[allow(dead_code)]
|
||||
struct LocalModule;
|
||||
|
||||
use kernel::{{
|
||||
str::CStr,
|
||||
ModuleMetadata,
|
||||
ThisModule, //
|
||||
}};
|
||||
use core::ptr::null_mut;
|
||||
|
||||
impl ModuleMetadata for LocalModule {{
|
||||
const NAME: &'static CStr = c"rust_doctests_kernel";
|
||||
const THIS_MODULE: ThisModule = {{
|
||||
// SAFETY: `try_module_get`/`module_put` handle null module pointers gracefully.
|
||||
unsafe {{ ThisModule::from_ptr(null_mut()) }}
|
||||
}};
|
||||
}}
|
||||
|
||||
{rust_tests}
|
||||
"#
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user