Skip to content

Commit

Permalink
rust: update dbg!() to format column number
Browse files Browse the repository at this point in the history
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: rust-lang/rust#114962 [1]
Link: Rust-for-Linux#1065

Signed-off-by: Raghav Narang <dev@raxyte.com>
  • Loading branch information
raxyte committed Apr 14, 2024
1 parent 8db31d3 commit c1ec212
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions rust/kernel/std_vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,16 @@ macro_rules! dbg {
// `$val` expression could be a block (`{ .. }`), in which case the `pr_info!`
// will be malformed.
() => {
$crate::pr_info!("[{}:{}]\n", ::core::file!(), ::core::line!())
$crate::pr_info!("[{}:{}:{}]\n", ::core::file!(), ::core::line!(), ::core::column!())
};
($val:expr $(,)?) => {
// Use of `match` here is intentional because it affects the lifetimes
// of temporaries - https://stackoverflow.com/a/48732525/1063961
match $val {
tmp => {
$crate::pr_info!("[{}:{}] {} = {:#?}\n",
::core::file!(), ::core::line!(), ::core::stringify!($val), &tmp);
$crate::pr_info!("[{}:{}:{}] {} = {:#?}\n",
::core::file!(), ::core::line!(), ::core::column!(),
::core::stringify!($val), &tmp);
tmp
}
}
Expand Down

0 comments on commit c1ec212

Please sign in to comment.