1

rust: update dbg!() to format column number

In Rust 1.76.0, the `dbg!()` macro was updated to also format the column
number. The reason cited was usage of a few characters worth of
horizontal space while allowing direct jumps to the source location. [1]

Link: https://github.com/rust-lang/rust/pull/114962 [1]
Link: https://github.com/Rust-for-Linux/linux/issues/1065
Signed-off-by: Raghav Narang <dev@raxyte.com>
Reviewed-by: Trevor Gross <tmgross@umich.edu>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://lore.kernel.org/r/eba70259-9b10-4bf7-ac4f-d7accf6b8891@smtp-relay.sendinblue.com
[ Fixed commit author name and removed spurious newline in message. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This commit is contained in:
Raghav Narang 2024-04-14 18:49:28 +05:30 committed by Miguel Ojeda
parent 84373132b8
commit ea175b2d6f

View File

@ -146,15 +146,16 @@ macro_rules! dbg {
// `$val` expression could be a block (`{ .. }`), in which case the `pr_info!` // `$val` expression could be a block (`{ .. }`), in which case the `pr_info!`
// will be malformed. // will be malformed.
() => { () => {
$crate::pr_info!("[{}:{}]\n", ::core::file!(), ::core::line!()) $crate::pr_info!("[{}:{}:{}]\n", ::core::file!(), ::core::line!(), ::core::column!())
}; };
($val:expr $(,)?) => { ($val:expr $(,)?) => {
// Use of `match` here is intentional because it affects the lifetimes // Use of `match` here is intentional because it affects the lifetimes
// of temporaries - https://stackoverflow.com/a/48732525/1063961 // of temporaries - https://stackoverflow.com/a/48732525/1063961
match $val { match $val {
tmp => { tmp => {
$crate::pr_info!("[{}:{}] {} = {:#?}\n", $crate::pr_info!("[{}:{}:{}] {} = {:#?}\n",
::core::file!(), ::core::line!(), ::core::stringify!($val), &tmp); ::core::file!(), ::core::line!(), ::core::column!(),
::core::stringify!($val), &tmp);
tmp tmp
} }
} }