-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
std: avoid tearing dbg! prints
#149869
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
base: main
Are you sure you want to change the base?
std: avoid tearing dbg! prints
#149869
Conversation
This comment has been minimized.
This comment has been minimized.
|
Neat solution :) I wasn't sure if we could use helper macros. |
|
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
| loop { | ||
| let [arm] = arms else { unreachable!("dbg! macro expansion only has single-arm matches") }; | ||
|
|
||
| match is_async_move_desugar(arm.body).unwrap_or(arm.body).peel_drop_temps().kind { |
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.
I'm not sure whether this is really necessary, I just copied this from above.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Is it allowed to change those error messages to leak those internal details? |
|
An alternative is to stuff the helper macro into the main macro with some kind of marker that would otherwise never be legal, e.g. starting with the tokens macro_rules! foo {
(=> __internal_recursion $x:expr) => {
// ...
};
($x:expr) => {
foo!(=> __internal_recursion $x);
};
} |
I don't think there's currently a way to tell the compiler to hide them unfortunately. But yes, this is fine, or at least there is precedent – the same happens for thread_local! {
#[rustc_align_static(42)]
static LOCAL: i32 = 42;
}(playground) on stable, the error message will reference
It would be legal to write these tokens in macro invocations in user code, so this would be an even worse leak of implementation details. I'm sure there is a way to abuse |
It would also be legal to directly write |
|
The Miri subtree was changed cc @rust-lang/miri |
No, since the macro is perma-unstable 😏 |
|
How does that work once the macro expands? Does it not expand in the user's context? Or is this just stdlib magic sprinkles? |
Edit: So yes, essentially just stdlib magic sprinkles 😄 |
Fixes #136703.
This is an alternative to #149859. Instead of formatting everything into a string, this PR makes multi-expression
dbg!expand into multiple nested matches, with the final match containing a singleeprint!. By using macro recursion and relying on hygiene, this allows naming every bound value in thateprint!.CC @orlp
r? libs