Skip to content

Commit c33df27

Browse files
authored
Rollup merge of #138980 - tmiasko:collect-var-debug-info, r=compiler-errors
Collect items referenced from var_debug_info The collection is limited to full debuginfo builds to match behavior of FunctionCx::compute_per_local_var_debug_info. Fixes #138942.
2 parents d26047d + b04e5b4 commit c33df27

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

compiler/rustc_monomorphize/src/collector.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ use rustc_middle::ty::{
231231
use rustc_middle::util::Providers;
232232
use rustc_middle::{bug, span_bug};
233233
use rustc_session::Limit;
234-
use rustc_session::config::EntryFnType;
234+
use rustc_session::config::{DebugInfo, EntryFnType};
235235
use rustc_span::source_map::{Spanned, dummy_spanned, respan};
236236
use rustc_span::{DUMMY_SP, Span};
237237
use tracing::{debug, instrument, trace};
@@ -1235,6 +1235,11 @@ fn collect_items_of_instance<'tcx>(
12351235
};
12361236

12371237
if mode == CollectionMode::UsedItems {
1238+
if tcx.sess.opts.debuginfo == DebugInfo::Full {
1239+
for var_debug_info in &body.var_debug_info {
1240+
collector.visit_var_debug_info(var_debug_info);
1241+
}
1242+
}
12381243
for (bb, data) in traversal::mono_reachable(body, tcx, instance) {
12391244
collector.visit_basic_block_data(bb, data)
12401245
}

tests/ui/mir/var_debug_ref.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Regression test for #138942, where a function was incorrectly internalized, despite the fact
2+
// that it was referenced by a var debug info from another code generation unit.
3+
//
4+
//@ build-pass
5+
//@ revisions: limited full
6+
//@ compile-flags: -Ccodegen-units=4
7+
//@[limited] compile-flags: -Cdebuginfo=limited
8+
//@[full] compile-flags: -Cdebuginfo=full
9+
trait Fun {
10+
const FUN: &'static fn();
11+
}
12+
impl Fun for () {
13+
const FUN: &'static fn() = &(detail::f as fn());
14+
}
15+
mod detail {
16+
// Place `f` in a distinct module to generate a separate code generation unit.
17+
#[inline(never)]
18+
pub(super) fn f() {}
19+
}
20+
fn main() {
21+
// SingleUseConsts represents "x" using VarDebugInfoContents::Const.
22+
// It is the only reference to `f` remaining.
23+
let x = <() as ::Fun>::FUN;
24+
}

0 commit comments

Comments
 (0)