diff options
author | Niklas Mohrin <dev@niklasmohrin.de> | 2022-11-10 17:41:35 +0100 |
---|---|---|
committer | Miguel Ojeda <ojeda@kernel.org> | 2022-12-04 01:59:16 +0100 |
commit | bee1688940b9264a9960e6afdac36a4af35f1f4b (patch) | |
tree | 3eeabe64b06a6159574abc753c9546fbee63cb4c /lib | |
parent | ef32054942ee8d78cbcc2c97212e55b6f5f668f7 (diff) | |
download | linux-stable-bee1688940b9264a9960e6afdac36a4af35f1f4b.tar.gz linux-stable-bee1688940b9264a9960e6afdac36a4af35f1f4b.tar.bz2 linux-stable-bee1688940b9264a9960e6afdac36a4af35f1f4b.zip |
rust: std_vendor: add `dbg!` macro based on `std`'s one
The Rust standard library has a really handy macro, `dbg!` [1,2].
It prints the source location (filename and line) along with the raw
source code that is invoked with and the `Debug` representation
of the given expression, e.g.:
let a = 2;
let b = dbg!(a * 2) + 1;
// ^-- prints: [src/main.rs:2] a * 2 = 4
assert_eq!(b, 5);
Port the macro over to the `kernel` crate inside a new module
called `std_vendor`, using `pr_info!` instead of `eprintln!` and
make the rules about committing uses of `dbg!` into version control
more concrete (i.e. tailored for the kernel).
Since the source code for the macro is taken from the standard
library source (with only minor adjustments), the new file is
licensed under `Apache 2.0 OR MIT`, just like the original [3,4].
Link: https://doc.rust-lang.org/std/macro.dbg.html [1]
Link: https://github.com/rust-lang/rust/blob/master/library/std/src/macros.rs#L212 [2]
Link: https://github.com/rust-lang/rust/blob/master/library/std/Cargo.toml [3]
Link: https://github.com/rust-lang/rust/blob/master/COPYRIGHT [4]
Signed-off-by: Niklas Mohrin <dev@niklasmohrin.de>
[Reworded, adapted for upstream and applied latest changes]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'lib')
0 files changed, 0 insertions, 0 deletions