Re: [PATCH v4 1/2] rust: Introduce file_from_location()

From: Miguel Ojeda
Date: Thu Jun 19 2025 - 16:43:11 EST


On Thu, Jun 19, 2025 at 5:10 PM Boqun Feng <boqun.feng@xxxxxxxxx> wrote:
>
> +/// // - A path like "rust/kernel/example.rs" if file_with_nul() available.

"is available."

> +pub fn file_from_location<'a>(_loc: &'a core::panic::Location<'a>) -> &'a core::ffi::CStr {
> + #[cfg(CONFIG_RUSTC_HAS_FILE_WITH_NUL)]
> + { _loc.file_with_nul() }
> +
> + #[cfg(not(CONFIG_RUSTC_HAS_FILE_WITH_NUL))]
> + { c"<Location::file_with_nul() not supported>" }
> +}

If a `let _` works, then it may be better -- please see a similar case at:

https://lore.kernel.org/rust-for-linux/CANiq72=ph_XG0TtkdsNJCUZMiAMYBo11eJaCTLCTpTAFXtcNMA@xxxxxxxxxxxxxx/

The new version looks great, thanks!

Cheers,
Miguel