-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
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.
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 don't think this is needed here. You can probably use match arm.body.kind { and add this extra test line to src/tools/clippy/tests/ui/dbg_macro/dbg_macro.rs (and bless the results with ./x test clippy --bless):
takes_async_fn(async move |val| { dbg!(val, val + 1); val });
//~^ dbg_macro
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 😄 |
|
☔ The latest upstream changes (presumably #150068) made this pull request unmergeable. Please resolve the merge conflicts. |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@bors r+ |
std: avoid tearing `dbg!` prints Fixes rust-lang#136703. This is an alternative to rust-lang#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 single `eprint!`. By using macro recursion and relying on hygiene, this allows naming every bound value in that `eprint!`. CC @orlp r? libs
std: avoid tearing `dbg!` prints Fixes rust-lang#136703. This is an alternative to rust-lang#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 single `eprint!`. By using macro recursion and relying on hygiene, this allows naming every bound value in that `eprint!`. CC @orlp r? libs
std: avoid tearing `dbg!` prints Fixes rust-lang#136703. This is an alternative to rust-lang#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 single `eprint!`. By using macro recursion and relying on hygiene, this allows naming every bound value in that `eprint!`. CC @orlp r? libs
Rollup of 8 pull requests Successful merges: - #145393 (Add codegen test for removing trailing zeroes from `NonZero`) - #149869 (std: avoid tearing `dbg!` prints) - #150065 (add CSE optimization tests for iterating over slice) - #150842 (Fix(lib/win/thread): Ensure `Sleep`'s usage passes over the requested duration under Win7) - #151244 (Refine dummy_span.rs test) - #151505 (Various refactors to the proc_macro bridge) - #151560 (relnotes: fix 1.93's `as_mut_array` methods) - #151577 (Rename `DepKindStruct` to `DepKindVTable`)
std: avoid tearing `dbg!` prints Fixes rust-lang#136703. This is an alternative to rust-lang#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 single `eprint!`. By using macro recursion and relying on hygiene, this allows naming every bound value in that `eprint!`. CC @orlp r? libs
…uwer Rollup of 11 pull requests Successful merges: - #145393 (Add codegen test for removing trailing zeroes from `NonZero`) - #148764 (ptr_aligment_type: add more APIs) - #149869 (std: avoid tearing `dbg!` prints) - #150065 (add CSE optimization tests for iterating over slice) - #150842 (Fix(lib/win/thread): Ensure `Sleep`'s usage passes over the requested duration under Win7) - #151505 (Various refactors to the proc_macro bridge) - #151560 (relnotes: fix 1.93's `as_mut_array` methods) - #151611 (Improve is_ascii performance on x86_64 with explicit SSE2 intrinsics) - #151317 (x86 soft-float feature: mark it as forbidden rather than unstable) - #151577 (Rename `DepKindStruct` to `DepKindVTable`) - #151620 (Fix 'the the' typo in library/core/src/array/iter.rs)
Rollup of 10 pull requests Successful merges: - #145393 (Add codegen test for removing trailing zeroes from `NonZero`) - #148764 (ptr_aligment_type: add more APIs) - #149869 (std: avoid tearing `dbg!` prints) - #150065 (add CSE optimization tests for iterating over slice) - #150842 (Fix(lib/win/thread): Ensure `Sleep`'s usage passes over the requested duration under Win7) - #151505 (Various refactors to the proc_macro bridge) - #151560 (relnotes: fix 1.93's `as_mut_array` methods) - #151317 (x86 soft-float feature: mark it as forbidden rather than unstable) - #151577 (Rename `DepKindStruct` to `DepKindVTable`) - #151620 (Fix 'the the' typo in library/core/src/array/iter.rs)
Rollup merge of #149869 - joboet:torn-dbg, r=Mark-Simulacrum std: avoid tearing `dbg!` prints 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 single `eprint!`. By using macro recursion and relying on hygiene, this allows naming every bound value in that `eprint!`. CC @orlp r? libs
Rollup of 10 pull requests Successful merges: - rust-lang/rust#145393 (Add codegen test for removing trailing zeroes from `NonZero`) - rust-lang/rust#148764 (ptr_aligment_type: add more APIs) - rust-lang/rust#149869 (std: avoid tearing `dbg!` prints) - rust-lang/rust#150065 (add CSE optimization tests for iterating over slice) - rust-lang/rust#150842 (Fix(lib/win/thread): Ensure `Sleep`'s usage passes over the requested duration under Win7) - rust-lang/rust#151505 (Various refactors to the proc_macro bridge) - rust-lang/rust#151560 (relnotes: fix 1.93's `as_mut_array` methods) - rust-lang/rust#151317 (x86 soft-float feature: mark it as forbidden rather than unstable) - rust-lang/rust#151577 (Rename `DepKindStruct` to `DepKindVTable`) - rust-lang/rust#151620 (Fix 'the the' typo in library/core/src/array/iter.rs)
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