Skip to content

#[track_caller] functions don't track location when called from an inlined function #73709

Closed
@Vlad-Shcherbina

Description

@Vlad-Shcherbina

To reproduce

cargo new --bin main
cargo new --lib lib

cat <<END >lib/src/lib.rs
#[inline(always)]
pub fn f() {
    assert!(false)
}
END

echo "lib = { path = \"../lib\" }" >>main/Cargo.toml

cat <<END >main/src/main.rs
fn main() {
    lib::f();
}
END

cd main
cargo run

Expected result

     Running `target/debug/main`
thread 'main' panicked at 'assertion failed: false', /tmp/lib/src/lib.rs:3:5

Actual result

     Running `target/debug/main`
thread 'main' panicked at 'assertion failed: false', /rustc/ff5b446d2fdbd898bc97a751f2f72858de185cf1/src/libstd/macros.rs:13:23

Backtrace is also not helpful:

$ RUST_BACKTRACE=1 cargo run
...
  11: std::panicking::begin_panic
             at /rustc/ff5b446d2fdbd898bc97a751f2f72858de185cf1/src/libstd/panicking.rs:403
  12: lib::f
             at /rustc/ff5b446d2fdbd898bc97a751f2f72858de185cf1/src/libstd/macros.rs:13
  13: main::main
             at src/main.rs:2
...

Version info

This happens both on Windows and on Linux.

$ cargo version --verbose
cargo 1.46.0-nightly (089cbb80b 2020-06-15)
release: 1.46.0
commit-hash: 089cbb80b73ba242efdcf5430e89f63fa3b5328d
commit-date: 2020-06-15

$ rustc --version --verbose
rustc 1.46.0-nightly (ff5b446d2 2020-06-23)
binary: rustc
commit-hash: ff5b446d2fdbd898bc97a751f2f72858de185cf1
commit-date: 2020-06-23
host: x86_64-unknown-linux-gnu
release: 1.46.0-nightly
LLVM version: 10.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-track_caller`#![feature(track_caller)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions