rust: bug: fix warn_on macro build error on UML
Subsystems (3)
PATCH 1/1 rust: bug: fix warn_on macro build error on UML
From: FUJITA Tomonori <[email protected]>
Callers that go through kernel::prelude have CStrExt in scope, but code inside the kernel crate imports explicitly and may not. Using warn_on! from such a module fails to build on UML, which is the only configuration where warn_flags! needs a C string pointer rather than an inline asm bug entry:
error[E0599]: no method named as_char_ptr found for reference &ffi::CStr in the current scope
--> linux/rust/kernel/bug.rs:83:49
|
83 | $crate::c_str!(::core::file!()).as_char_ptr(),
| ^^^^^^^^^^^
|
::: linux/rust/kernel/time.rs:427:9
|
427 | warn_on!(self.nanos < 0);
| ------------------------ in this macro invocation
| = help: items from traits can only be used if the trait is in scope
= note: this error originates in the macro $crate::warn_flags which comes from the expansion of the macro warn_on (in Nightly builds, run with -Z mac)
help: trait CStrExt which provides as_char_ptr is implemented but not in scope; perhaps you want to import it
--> linux/rust/kernel/time.rs:27:1
|
27 + use crate::str::CStrExt;
Use the free function as_char_ptr_in_const_context() instead, as other exported macros already do.
--- rust/kernel/bug.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/bug.rs +1 -1
@@ -80,7 +80,7 @@ macro_rules! warn_flags {// with a valid null-terminated string. unsafe { $crate::bindings::warn_slowpath_fmt ( - $crate::c_str!(::core::file!()).as_char_ptr (), + $crate::str::as_char_ptr_in_const_context ($crate::c_str!(::core::file!())),line! ()as $crate::ffi::c_int , $flagsas $crate::ffi::c_uint , ::core::ptr::null(),
base-commit: 11028ab62899e4191e074ee364c712b77823a9c4
Signature · 1 line
2.43.0
Quoted 2 lines · FUJITA Tomonori
Use the free function
as_char_ptr_in_const_context()instead, as other exported macros already do.
I reproduced this and the fix works -- thanks Tomonori!
Do we need to use the free function? i.e. this is not a const context, so should we do e.g.
$crate::str::CStrExt::as_char_ptr
?
Also:
And Cc'ing David for UML in case he is interested.
Cheers,
Miguel
Quoted 2 lines · Miguel Ojeda
And Cc'ing David for UML in case he is interested.
Old email address from the contacts, sorry -- re-Cc'ing.
Cheers,
Miguel
Quoted 4 lines · On Fri, 7 Aug 2026 08:52:38 +0200 Miguel Ojeda…
Quoted 2 lines · FUJITA Tomonori
Use the free function
as_char_ptr_in_const_context()instead, as other exported macros already do.
Quoted 8 lines
I reproduced this and the fix works -- thanks Tomonori!
Do we need to use the free function? i.e. this is not a const context, so should we do e.g.
$crate::str::CStrExt::as_char_ptr?
Thanks, you are right. I'll send v2 shortly.
Quoted 3 lines
Also:
Ok.