Re: [PATCH v2] rust: macros: enable use of hyphens in module names

From: Anisse Astier
Date: Thu Jan 30 2025 - 01:08:38 EST




Jeu 30 janv 2025, à 05:58, Viresh Kumar a écrit :
> On 22-01-25, 14:39, Anisse Astier wrote:
>> + /* Rust does not allow hyphens in identifiers, use underscore instead */
>> + let name_identifier = info.name.replace("-", "_");
>
> With CLIPPY=1 W=1, this gives:
>
> warning: single-character string constant used as pattern
> --> /mnt/ssd/all/work/repos/kernel/linux/rust/macros/module.rs:186:45
> |
> 186 | let name_identifier = info.name.replace("-", "_");
> | ^^^ help: consider
> using a `char`: `'-'`
> |
> = help: for further information visit
> https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern
> = note: `-W clippy::single-char-pattern` implied by `-W clippy::all`
> = help: to override `-W clippy::all` add
> `#[allow(clippy::single_char_pattern)]`
>
> warning: 1 warning emitted
>
> This fixes it:
>
> diff --git a/rust/macros/module.rs b/rust/macros/module.rs
> index 1eff30d2ca6a..2e740bbdb598 100644
> --- a/rust/macros/module.rs
> +++ b/rust/macros/module.rs
> @@ -183,7 +183,7 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
> let info = ModuleInfo::parse(&mut it);
>
> /* Rust does not allow hyphens in identifiers, use underscore instead */
> - let name_identifier = info.name.replace("-", "_");
> + let name_identifier = info.name.replace('-', "_");
> let mut modinfo = ModInfoBuilder::new(name_identifier.as_ref());
> if let Some(author) = info.author {
> modinfo.emit("author", &author);
>
>
> Will include it in my V8 now, unless you have any objections to it.

No objections and nice catch!

Regards,

Anisse