@@ -359,19 +359,16 @@ macro_rules! dbg {
359359 } ;
360360}
361361
362- /// Internal macro that processes a list of expressions and produces a chain of
363- /// nested `match`es, one for each expression, before finally calling `eprint!`
364- /// with the collected information and returning all the evaluated expressions
365- /// in a tuple.
362+ /// Internal macro that processes a list of expressions, binds their results
363+ /// with `match`, calls `eprint!` with the collected information, and returns
364+ /// all the evaluated expressions in a tuple.
366365///
367366/// E.g. `dbg_internal!(() () (1, 2))` expands into
368367/// ```rust, ignore
369- /// match 1 {
370- /// tmp_1 => match 2 {
371- /// tmp_2 => {
372- /// eprint!("...", &tmp_1, &tmp_2, /* some other arguments */);
373- /// (tmp_1, tmp_2)
374- /// }
368+ /// match (1, 2) {
369+ /// (tmp_1, tmp_2) => {
370+ /// eprint!("...", &tmp_1, &tmp_2, /* some other arguments */);
371+ /// (tmp_1, tmp_2)
375372/// }
376373/// }
377374/// ```
@@ -380,37 +377,41 @@ macro_rules! dbg {
380377#[ doc( hidden) ]
381378#[ rustc_macro_transparency = "semiopaque" ]
382379pub macro dbg_internal {
383- ( ( $( $piece: literal) , +) ( $( $processed: expr => $bound: expr) , +) ( ) ) => { {
384- $crate:: eprint!(
385- $crate :: concat!( $( $piece) , +) ,
386- $(
387- $crate :: stringify!( $processed) ,
388- // The `&T: Debug` check happens here (not in the format literal desugaring)
389- // to avoid format literal related messages and suggestions.
390- &&$bound as & dyn $crate :: fmt:: Debug
391- ) , +,
392- // The location returned here is that of the macro invocation, so
393- // it will be the same for all expressions. Thus, label these
394- // arguments so that they can be reused in every piece of the
395- // formatting template.
396- file=$crate :: file!( ) ,
397- line=$crate :: line!( ) ,
398- column=$crate :: column!( )
399- ) ;
400- // Comma separate the variables only when necessary so that this will
401- // not yield a tuple for a single expression, but rather just parenthesize
402- // the expression.
403- ( $( $bound) , +)
404- } } ,
405- ( ( $( $piece: literal) , * ) ( $( $processed: expr => $bound: expr) , * ) ( $val: expr $( , $rest: expr) * ) ) => {
380+ ( ( $( $piece: literal) , +) ( $( $processed: expr => $bound: ident) , +) ( ) ) => {
406381 // Use of `match` here is intentional because it affects the lifetimes
407382 // of temporaries - https://stackoverflow.com/a/48732525/1063961
408- match $val {
409- tmp => $crate:: macros:: dbg_internal!(
410- ( $( $piece, ) * "[{file}:{line}:{column}] {} = {:#?}\n " )
411- ( $( $processed => $bound, ) * $val => tmp)
412- ( $( $rest) , * )
413- ) ,
383+ // Always put the arguments in a tuple to avoid an unused parens lint on the pattern.
384+ match ( $( $processed, ) +) {
385+ ( $( $bound, ) +) => {
386+ $crate:: eprint!(
387+ $crate :: concat!( $( $piece) , +) ,
388+ $(
389+ $crate :: stringify!( $processed) ,
390+ // The `&T: Debug` check happens here (not in the format literal desugaring)
391+ // to avoid format literal related messages and suggestions.
392+ &&$bound as & dyn $crate :: fmt:: Debug
393+ ) , +,
394+ // The location returned here is that of the macro invocation, so
395+ // it will be the same for all expressions. Thus, label these
396+ // arguments so that they can be reused in every piece of the
397+ // formatting template.
398+ file=$crate :: file!( ) ,
399+ line=$crate :: line!( ) ,
400+ column=$crate :: column!( )
401+ ) ;
402+ // Comma separate the variables only when necessary so that this will
403+ // not yield a tuple for a single expression, but rather just parenthesize
404+ // the expression.
405+ ( $( $bound) , +)
406+
407+ }
414408 }
415409 } ,
410+ ( ( $( $piece: literal) , * ) ( $( $processed: expr => $bound: ident) , * ) ( $val: expr $( , $rest: expr) * ) ) => {
411+ $crate:: macros:: dbg_internal!(
412+ ( $( $piece, ) * "[{file}:{line}:{column}] {} = {:#?}\n " )
413+ ( $( $processed => $bound, ) * $val => tmp)
414+ ( $( $rest) , * )
415+ )
416+ } ,
416417}
0 commit comments