-
Notifications
You must be signed in to change notification settings - Fork 734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
macros: Remove 'r#' prefix from raw identifiers in field names #3130
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting... I'm ignorant to this so forgive me if I'm understanding this wrong.
Assuming that example!
is an external macro, is it possible that this behavior could be solved within the example macro? Entertain me for a minute, but it appears that the tracing macros (ie, info!
) are behaving as expected. Since the example macro renders what is ultimately fed into info!
, that is where I feel the behavior should be addressed.
Now, that is my 2c when viewing this as a bug, and I'm still not certain whether I would personally classify this as a bug or a UX enhancement.
Head branch was pushed to by a user without write access
Fixed clippy lint. warning: transmute from a `&[u8]` to a `&str`
--> tracing/src/lib.rs:1228:22
|
1228 | unsafe { mem::transmute(self.0.as_slice()) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8_unchecked(self.0.as_slice())`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#transmute_bytes_to_str
= note: `#[warn(clippy::transmute_bytes_to_str)]` on by default |
Thanks; looks like I had to go into a hidden UI to approve running actions. |
Motivation
Currently a call like
info!(..., r#type = "...")
ends up emitting a field named "r#type", which is never desirable. Previous work in #2925 made the desired behavior expressible asinfo!(..., type = "...")
, and even before that PR one could write it asinfo!(..., "type" = "...")
.However, when dealing with macro-generated use of tracing, we do still sometimes end up with raw identifiers. For example, if user-provided identifiers are used for both declaring (or instantiating, or accessing) a struct, and also for tracing. Something like this:
If we ask the user of
example!
to passtype
(unraw), there is no way for the macro to accessGLOBAL.r#type
from that. But if we ask the user ofexample!
to passr#type
(raw), there is no straightforward way for the macro to trace the field name as "type". The best option would have been something like:but this gets even more ridiculous when dealing with field names that are not just a single identifier. (
prefix.r#keyword.suffix
).Solution
r#keyword = $value
is made equivalent tokeyword = $value
. The field will be emitted with the name "keyword", not "r#keyword" as before.