* [PATCH v1] rust: bug: fix warn_on macro build error on UML
@ 2026-08-01 2:25 FUJITA Tomonori
2026-08-07 6:52 ` Miguel Ojeda
0 siblings, 1 reply; 4+ messages in thread
From: FUJITA Tomonori @ 2026-08-01 2:25 UTC (permalink / raw)
To: ojeda, richard, anton.ivanov, johannes
Cc: a.hindborg, acourbot, aliceryhl, bjorn3_gh, boqun, dakr,
daniel.almeida, gary, lossin, tamird, tmgross, work,
rust-for-linux, linux-um, FUJITA Tomonori
From: FUJITA Tomonori <fujita.tomonori@gmail.com>
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.
Fixes: dff64b072708 ("rust: Add warn_on macro")
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
---
rust/kernel/bug.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/rust/kernel/bug.rs b/rust/kernel/bug.rs
index ed943960f851..ca1ab69c977b 100644
--- a/rust/kernel/bug.rs
+++ b/rust/kernel/bug.rs
@@ -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,
$flags as $crate::ffi::c_uint,
::core::ptr::null(),
base-commit: 11028ab62899e4191e074ee364c712b77823a9c4
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v1] rust: bug: fix warn_on macro build error on UML
2026-08-01 2:25 [PATCH v1] rust: bug: fix warn_on macro build error on UML FUJITA Tomonori
@ 2026-08-07 6:52 ` Miguel Ojeda
2026-08-07 6:54 ` Miguel Ojeda
2026-08-07 11:19 ` FUJITA Tomonori
0 siblings, 2 replies; 4+ messages in thread
From: Miguel Ojeda @ 2026-08-07 6:52 UTC (permalink / raw)
To: FUJITA Tomonori
Cc: ojeda, richard, anton.ivanov, johannes, a.hindborg, acourbot,
aliceryhl, bjorn3_gh, boqun, dakr, daniel.almeida, gary, lossin,
tamird, tmgross, work, rust-for-linux, linux-um, FUJITA Tomonori,
David Gow
On Sat, Aug 1, 2026 at 5:41 AM FUJITA Tomonori <tomo@flapping.org> wrote:
>
> 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:
Cc: stable@vger.kernel.org
And Cc'ing David for UML in case he is interested.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] rust: bug: fix warn_on macro build error on UML
2026-08-07 6:52 ` Miguel Ojeda
@ 2026-08-07 6:54 ` Miguel Ojeda
2026-08-07 11:19 ` FUJITA Tomonori
1 sibling, 0 replies; 4+ messages in thread
From: Miguel Ojeda @ 2026-08-07 6:54 UTC (permalink / raw)
To: FUJITA Tomonori
Cc: ojeda, richard, anton.ivanov, johannes, a.hindborg, acourbot,
aliceryhl, bjorn3_gh, boqun, dakr, daniel.almeida, gary, lossin,
tamird, tmgross, work, rust-for-linux, linux-um, FUJITA Tomonori,
David Gow
On Fri, Aug 7, 2026 at 8:52 AM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> And Cc'ing David for UML in case he is interested.
Old email address from the contacts, sorry -- re-Cc'ing.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] rust: bug: fix warn_on macro build error on UML
2026-08-07 6:52 ` Miguel Ojeda
2026-08-07 6:54 ` Miguel Ojeda
@ 2026-08-07 11:19 ` FUJITA Tomonori
1 sibling, 0 replies; 4+ messages in thread
From: FUJITA Tomonori @ 2026-08-07 11:19 UTC (permalink / raw)
To: miguel.ojeda.sandonis
Cc: tomo, ojeda, richard, anton.ivanov, johannes, a.hindborg,
acourbot, aliceryhl, bjorn3_gh, boqun, dakr, daniel.almeida, gary,
lossin, tamird, tmgross, work, rust-for-linux, linux-um,
fujita.tomonori, david
On Fri, 7 Aug 2026 08:52:38 +0200
Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote:
> On Sat, Aug 1, 2026 at 5:41 AM FUJITA Tomonori <tomo@flapping.org> wrote:
>>
>> 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
>
> ?
Thanks, you are right. I'll send v2 shortly.
> Also:
>
> Cc: stable@vger.kernel.org
Ok.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-07 11:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-01 2:25 [PATCH v1] rust: bug: fix warn_on macro build error on UML FUJITA Tomonori
2026-08-07 6:52 ` Miguel Ojeda
2026-08-07 6:54 ` Miguel Ojeda
2026-08-07 11:19 ` FUJITA Tomonori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox