Skip to content

Commit 81a60b7

Browse files
authored
Rollup merge of #81233 - lzutao:dbg, r=KodrAus
Document why not use concat! in dbg! macro Original title: Reduce code generated by `dbg!` macro The expanded code before/after: <https://rust.godbolt.org/z/hE3j95>. --- We cannot use `concat!` since `file!` could contains `{` or the expression is a block (`{ .. }`). Using it will generated malformed format strings. So let's document this reason why we don't use `concat!` macro at all.
2 parents 2ceee72 + d0c1405 commit 81a60b7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

library/std/src/macros.rs

+4
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ macro_rules! eprintln {
282282
#[macro_export]
283283
#[stable(feature = "dbg_macro", since = "1.32.0")]
284284
macro_rules! dbg {
285+
// NOTE: We cannot use `concat!` to make a static string as a format argument
286+
// of `eprintln!` because `file!` could contain a `{` or
287+
// `$val` expression could be a block (`{ .. }`), in which case the `eprintln!`
288+
// will be malformed.
285289
() => {
286290
$crate::eprintln!("[{}:{}]", $crate::file!(), $crate::line!());
287291
};

0 commit comments

Comments
 (0)