Skip to content

MIR inlining breaks Location::caller() #105538

@saethlin

Description

@saethlin
use core::panic::Location;

#[inline]
fn nested() -> &'static Location<'static> {
    Location::caller()
}

fn main() {
    println!("{:?}", nested());
}

In debug mode, this prints

Location { file: "src/main.rs", line: 5, col: 5 }

But with optimizations, this prints:

Location { file: "src/main.rs", line: 9, col: 22 }

With optimizations and -Zinline-mir=no, this prints:

Location { file: "src/main.rs", line: 5, col: 5 }

This check in the MIR inliner is hiding this problem from the track-caller UI tests:

// Only inline local functions if they would be eligible for cross-crate
// inlining. This is to ensure that the final crate doesn't have MIR that
// reference unexported symbols
if callsite.callee.def_id().is_local() {
let is_generic = callsite.callee.substs.non_erasable_generics().next().is_some();
if !is_generic && !callee_attrs.requests_inline() {
return Err("not exported");
}
}

@rustbot label +A-mir-opt +A-mir-opt-inlining


rustc --version --verbose:

rustc 1.68.0-nightly (dfe3fe710 2022-12-09)
binary: rustc
commit-hash: dfe3fe710181738a2cb3060c23ec5efb3c68ca09
commit-date: 2022-12-09
host: x86_64-unknown-linux-gnu
release: 1.68.0-nightly
LLVM version: 15.0.6

Metadata

Metadata

Assignees

Labels

A-mir-optArea: MIR optimizationsA-mir-opt-inliningArea: MIR inliningC-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions