Skip to content

Commit 3d65c7f

Browse files
committed
Create proper debuginfo for closure variables
Variables for closures hold a tuple of captured variables, and not the function itself. Fixes #26484
1 parent 9175a16 commit 3d65c7f

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

src/librustc_trans/trans/debuginfo/metadata.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,14 @@ pub fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
813813
}
814814
ty::TyClosure(def_id, substs) => {
815815
let infcx = infer::normalizing_infer_ctxt(cx.tcx(), &cx.tcx().tables);
816-
let sig = infcx.closure_type(def_id, substs).sig;
817-
subroutine_type_metadata(cx, unique_type_id, &sig, usage_site_span)
816+
let upvars = infcx.closure_upvars(def_id, substs).unwrap();
817+
let upvar_types = upvars.iter().map(|u| u.ty).collect::<Vec<_>>();
818+
819+
prepare_tuple_metadata(cx,
820+
t,
821+
&upvar_types[..],
822+
unique_type_id,
823+
usage_site_span).finalize(cx)
818824
}
819825
ty::TyStruct(def_id, substs) => {
820826
prepare_struct_metadata(cx,

src/test/debuginfo/basic-types-metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
// gdb-command:whatis f64
4444
// gdb-check:type = f64
4545
// gdb-command:whatis fnptr
46-
// gdb-check:type = void (*)(void)
46+
// gdb-check:type = [...] (*)([...])
4747
// gdb-command:info functions _yyy
4848
// gdb-check:[...]![...]_yyy([...]);
4949
// gdb-command:continue

src/test/run-pass/issue-26484.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags:-g
12+
13+
fn helper<F: FnOnce(usize) -> bool>(_f: F) {
14+
print!("");
15+
}
16+
17+
fn main() {
18+
let cond = 0;
19+
helper(|v| v == cond)
20+
}

0 commit comments

Comments
 (0)