Skip to content

Conversation

@orlp
Copy link
Contributor

@orlp orlp commented Dec 10, 2025

Fixes #136703.

I did attempt a solution which collects all expressions into a tuple tmp before iterating over that tuple using the unstable macro_metavar_expr tmp.${index()}, but that refused to compile even with #[allow_internal_unstable(macro_metavar_expr)] and/or #![feature(macro_metavar_expr)]:

error[E0658]: meta-variable expressions are unstable
   --> /Users/orlp/programming/rust/rust/library/std/src/macros.rs:394:34
    |
394 |                     &eager_eval.${index()} as &dyn $crate::fmt::Debug,
    |                                  ^^^^^^^^^
    |
    = note: see issue #83527 <https://github.com/rust-lang/rust/issues/83527> for more information
    = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable

As mentioned in the code comment, the original proposed solution in the issue of simply holding the stderr lock is undesirable because it can lead to deadlocks.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 10, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 10, 2025

r? @joboet

rustbot has assigned @joboet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@joboet
Copy link
Member

joboet commented Dec 10, 2025

You could also use concat! to create a single format template for all arguments (yeah, apparently this works).
Nevermind, you still wouldn't be able to name the variables...

@orlp
Copy link
Contributor Author

orlp commented Dec 10, 2025

@joboet The dbg! macro has a comment warning us precisely against doing that, even if we could name the variables:

// NOTE: We cannot use `concat!` to make a static string as a format argument
// of `eprintln!` because `file!` could contain a `{` or
// `$val` expression could be a block (`{ .. }`), in which case the `eprintln!`
// will be malformed.

@joboet
Copy link
Member

joboet commented Dec 10, 2025

That's different, that's warning against combining the output of file! into the format string – that's unnecessary nowadays anyway since the compiler will inline string literals into format_args! itself.

@orlp
Copy link
Contributor Author

orlp commented Dec 10, 2025

If you'd like to see the other approach I've tried you can see it here: abe2246

It should work in theory, it just refuses to compile because of the unstable macro feature despite enabling that feature, in a way I don't understand.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Dec 10, 2025

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Dec 10, 2025
@joboet
Copy link
Member

joboet commented Dec 10, 2025

I've found another solution: #149869.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dbg! prints can tear in multi-threading code

4 participants