You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
module!: take strings instead of byte strings #252
Given it is a proc macro, we could take normal strings for the fields and ensure they are ASCII if/where needed.
This would make the interface a bit leaner.
For author, it would be particularly fitting anyway, because we would like to allow names requiring UTF-8, such as non-romanized names. There are kernel modules with MODULE_AUTHORs with non-ASCII characters already (and encoded as UTF-8) e.g.
This is actually non-trivial, because binary string constants cannot contain non-ASCII characters, so module proc_macro needs to properly parse the string literal and convert it to a binary string.
However there is no way to get a String or Vec<u8> from a Literal other than parsing it yourself. It's easy once once it's parsed. If you look at #258 you'll see that's exactly what I do.
I do not know, but even if we happen to need it, I do not think we should worry about that for the time being, in particular if it makes things more complex.
Activity
nbdd0121 commentedon May 9, 2021
This is actually non-trivial, because binary string constants cannot contain non-ASCII characters, so module proc_macro needs to properly parse the string literal and convert it to a binary string.
bjorn3 commentedon May 9, 2021
str::as_bytesgives the raw UTF-8 bytes of a string. You can directly pass this toLiteral::byte_stringI believe. Rustc automatically escapes the individual bytes: https://github.com/rust-lang/rust/blob/bba8710616e5e4722215c0d6b27abaedca03ebad/compiler/rustc_expand/src/proc_macro_server.rs#L566-L572nbdd0121 commentedon May 9, 2021
However there is no way to get a
StringorVec<u8>from aLiteralother than parsing it yourself. It's easy once once it's parsed. If you look at #258 you'll see that's exactly what I do.bjorn3 commentedon May 9, 2021
Ah, I see what you mean. If licensing would allow it copying syn or rustc_ast would be the easiest solutions.
nbdd0121 commentedon May 12, 2021
Are there scenarios that we need to take non-UTF-8 strings?
ojeda commentedon May 12, 2021
I do not know, but even if we happen to need it, I do not think we should worry about that for the time being, in particular if it makes things more complex.
rust: take str literal instead bstr literal in `module!` macro
rust: take str literal instead bstr literal in `module!` macro
rust_out_of_tree: use string literals in `module!` macro
rust: macros: take string literals in `module!`
rust: macros: take string literals in `module!`
rust: macros: take string literals in `module!`
rust: macros: take string literals in `module!`
rust: macros: take string literals in `module!`
rust: macros: take string literals in `module!`
BennoLossin commentedon Jul 25, 2024
Stale issue: this is already the case.
btrfs: zoned: skip reporting zone for new block group
btrfs: zoned: skip reporting zone for new block group