Macros not included in back-traces when used in a crate
When a macro causes a panic (directly or indirectly) between crates, the line of code from which the macro is used isn't included in the back-trace.
This makes it impossible to know which use of the macro caused the panic.
I ran into this problem because my tests are in a separate directory, and use the code they tests as a crate.
Possibly this is just unsupported feature / known limit in macro system, reporting because I wasn't sure.
Git repository for the example below.
tests/tests.rs
extern crate test_macro;
#[test]
fn main() {
let file: Vec<u8> = Vec::new();
test_macro::decode_main(&*file).unwrap();
}
src/lib.rs
use ::std::io;
macro_rules! read_exact {
($f:expr, $r:expr) => {
io::Read::read_exact($f, $r).unwrap()
}
}
fn decode_blocks<R: io::Read>(mut file: R) -> Result<(), io::Error> {
let mut bhead: [u8; 320] = [0; 320];
read_exact!(&mut file, &mut bhead); // <-- this line isn't in the backtrace
Ok(())
}
pub fn decode_main<R: io::Read>(mut file: R) -> Result<(), io::Error> {
decode_blocks(file)?;
Ok(())
}
Calling:
RUST_BACKTRACE=1 cargo test
Gives the backtrace:
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/result.rs:737
11: 0x562061ffd7da - test_macro::decode_blocks::h391253710f990761
at /src/test_macro/src/lib.rs:5
12: 0x562061ffd5ca - test_macro::decode_main::h43b3b33b47640ea4
at /src/test_macro/src/lib.rs:16
13: 0x562061fff1ad - tests::main::hc17f25ef21544d0b
at /src/test_macro/tests/tests.rs:5
14: 0x56206200d54e - <F as test::FnBox<T>>::call_box::h04563d623b7ebdf9
Notice line 11 isn't included.
Using Rust stable 1.15.
I'm not exactly sure when this was fixed (there's been a lot of backtrace work over the years), but using the latest stable (1.48.0), the backtrace does now include line 11:
3: core::result::Result<T,E>::unwrap at /home/achin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:973 4: test_macro::decode_blocks at ./src/lib.rs:11 5: test_macro::decode_main at ./src/lib.rs:16 6: tests::main at ./tests/tests.rs:5 7: tests::main::{{closure}} at ./tests/tests.rs:3This issue can be closed
Andrew Chin at 2020-11-27 19:34:57